Skip to content

Commit

Permalink
[PR-204] Python 3.12 test updates (#204)
Browse files Browse the repository at this point in the history
Renamed test function calls that are removed in Python 3. Fixed some test
cases that likely were broken but failure was masked by calling an invalid
function. Fixes #197.
  • Loading branch information
frogamic authored Jul 12, 2024
1 parent 8f12d5c commit 09898e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions tests/unit/test_jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2971,12 +2971,12 @@ def test_jlink_restarted(self):
self.jlink.halted.return_value = True

self.assertEqual(True, self.jlink.restart())
self.dll.JLINKARM_GoEx.called_once_with(0, 0)
self.dll.JLINKARM_GoEx.assert_called_once_with(0, 0)

self.dll.JLINKARM_GoEx = mock.Mock()

self.assertEqual(True, self.jlink.restart(10, skip_breakpoints=True))
self.dll.JLINKARM_GoEx.called_once_with(10, enums.JLinkFlags.GO_OVERSTEP_BP)
self.dll.JLINKARM_GoEx.assert_called_once_with(10, enums.JLinkFlags.GO_OVERSTEP_BP)

@mock.patch('time.sleep')
def test_jlink_halt_failure(self, mock_sleep):
Expand Down Expand Up @@ -6215,10 +6215,11 @@ def test_cp15_register_write_success(self):
``None``
"""
args = [1, 2, 3, 4, 5]
expected = [1, 3, 2, 4, 5]

self.dll.JLINKARM_CP15_WriteEx.return_value = 0
actual = self.jlink.cp15_register_write(*args)
assert self.dll.JLINKARM_CP15_WriteEx.called_once_with(*args)
self.dll.JLINKARM_CP15_WriteEx.assert_called_once_with(*expected)

def test_cp15_register_write_raises_exception_if_CP15_WriteEx_fails(self):
"""Tests that cp15_register_write raises a JLinkException on failure.
Expand All @@ -6242,9 +6243,10 @@ def test_set_log_file_success(self):
``None``
"""
args = ['my/file/path']
expected = [b'my/file/path']
self.dll.JLINKARM_SetLogFile.return_value = 0
self.jlink.set_log_file(*args)
assert self.dll.JLINKARM_SetLogFile.called_once_with(*args)
self.dll.JLINKARM_SetLogFile.assert_called_once_with(*expected)

def test_set_log_file_raises_exception_if_SetLogFile_fails(self):
"""Tests that set_log_file raises a JLinkException on failure.
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,9 @@ def test_linux_glibc_unavailable(self, mock_load_library, mock_cdll, mock_dlinfo

mock_find_library.assert_called_once_with(library.Library.JLINK_SDK_OBJECT)
# JLinkarmDlInfo has not been instantiated.
self.assertEquals(0, mock_dlinfo_ctr.call_count)
self.assertEqual(0, mock_dlinfo_ctr.call_count)
# Fallback to "search by file name" has succeeded.
self.assertEquals(1, mock_load_library.call_count)
self.assertEqual(1, mock_load_library.call_count)
self.assertEqual(directories[0], lib._path)

@mock.patch('os.name', new='posix')
Expand Down Expand Up @@ -1080,9 +1080,9 @@ def test_linux_dl_unavailable(self, mock_load_library, mock_cdll, mock_find_libr

mock_find_library.assert_any_call(library.Library.JLINK_SDK_OBJECT)
mock_find_library.assert_any_call('dl')
self.assertEquals(2, mock_find_library.call_count)
self.assertEqual(2, mock_find_library.call_count)
# Called once in JLinkarmDlInfo and once in Library.
self.assertEquals(2, mock_load_library.call_count)
self.assertEqual(2, mock_load_library.call_count)
# The dlinfo() dance silently failed, but will answer None resolved path.
self.assertIsNone(library.Library._dlinfo.path)
# Fallback to "search by file name" has succeeded.
Expand Down Expand Up @@ -1121,8 +1121,8 @@ def test_linux_dl_oserror(self, mock_load_library, mock_find_library, mock_libc_

mock_find_library.assert_any_call(library.Library.JLINK_SDK_OBJECT)
mock_find_library.assert_any_call('dl')
self.assertEquals(2, mock_find_library.call_count)
self.assertEquals(2, mock_load_library.call_count)
self.assertEqual(2, mock_find_library.call_count)
self.assertEqual(2, mock_load_library.call_count)


if __name__ == '__main__':
Expand Down

0 comments on commit 09898e7

Please sign in to comment.