Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pylink/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ def dll_version(self):
if match:
num_part = match.group(1)
return float(f"{num_part[0]}.{num_part[1:]}")

match = re.search(r"libjlinkarm(?:_x86)?\.so\.(\d+)\.(\d+)", os.path.realpath(self._path))
if match:
return float(f"{match.group(1)}.{match.group(2)}")
return None


Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def join(*args):
return s

mock_os.path.join.side_effect = join
mock_os.path.realpath.side_effect = lambda f: f

def listdir(f):
"""List the files and directories within the directory."""
Expand Down Expand Up @@ -1137,6 +1138,30 @@ def test_dll_version_mac(self, _mock_load_library):
lib = library.Library(path)
self.assertEqual(lib.dll_version(), 7.96)

@mock.patch('os.path.realpath', new=lambda f: f)
@mock.patch('ctypes.cdll.LoadLibrary')
def test_dll_version_linux_versioned_file_name(self, _mock_load_library):
path = "/opt/SEGGER/JLink/libjlinkarm.so.9.50.0"
lib = library.Library(path)
self.assertEqual(lib.dll_version(), 9.50)

@mock.patch('sys.platform', new='linux')
@mock.patch('os.path.realpath')
@mock.patch('pylink.library.open')
@mock.patch('tempfile.NamedTemporaryFile')
@mock.patch('ctypes.cdll.LoadLibrary')
def test_dll_version_linux_versioned_file_name_symlink(self, mock_load_library, mock_temp_file,
_mock_open, mock_realpath):
path = "/opt/SEGGER/JLink/libjlinkarm.so.9"
real = "/opt/SEGGER/JLink/libjlinkarm.so.9.50.0"
mock_realpath.side_effect = lambda f: real if f == path else f

lib = library.Library(path)

self.assertEqual(lib.dll_version(), 9.50)
mock_temp_file.assert_not_called()
mock_load_library.assert_called_once_with(path)


if __name__ == '__main__':
unittest.main()