Skip to content

Commit

Permalink
Merge pull request #5008 from jenshnielsen/fix_5007
Browse files Browse the repository at this point in the history
Fix #5007 Handle version str with extra info
  • Loading branch information
jenshnielsen authored Feb 14, 2023
2 parents 238bbee + a878fef commit 2720dce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/5007.improved_driver
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug in version parsing for Keysight 344XXA and Keysight E4980A which
would result in incompatibility with packaging>21 under certain circumstances.
32 changes: 25 additions & 7 deletions qcodes/tests/test_installation_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from packaging import version

import qcodes as qc
import qcodes.utils.installation_info as ii
Expand All @@ -13,20 +14,20 @@
# but we can at least test that they execute without errors


def test_get_qcodes_version():
def test_get_qcodes_version() -> None:
with pytest.warns(QCoDeSDeprecationWarning):
version = ii.get_qcodes_version()

assert version == qc.__version__


def test_is_qcodes_installed_editably():
def test_is_qcodes_installed_editably() -> None:
answer = is_qcodes_installed_editably()

assert isinstance(answer, bool)


def test_get_all_installed_package_versions():
def test_get_all_installed_package_versions() -> None:
ipvs = get_all_installed_package_versions()

assert isinstance(ipvs, dict)
Expand All @@ -37,12 +38,29 @@ def test_get_all_installed_package_versions():
assert isinstance(v, str)


def test_convert_legacy_version_to_supported_version():
def test_convert_legacy_version_to_supported_version() -> None:
def assert_version_str(legacy_verstr: str, expected_converted_ver_str: str) -> None:
converted_version_str = convert_legacy_version_to_supported_version(
legacy_verstr
)
assert converted_version_str == expected_converted_ver_str
assert version.parse(converted_version_str) == version.parse(
expected_converted_ver_str
)

legacy_verstr = "a.1.4"
assert convert_legacy_version_to_supported_version(legacy_verstr) == "65.1.4"
expected_converted_ver_str = "65.1.4"
assert_version_str(legacy_verstr, expected_converted_ver_str)


legacy_verstr = "10.4.7"
assert convert_legacy_version_to_supported_version(legacy_verstr) == "10.4.7"
expected_converted_ver_str = "10.4.7"
assert_version_str(legacy_verstr, expected_converted_ver_str)

legacy_verstr = "C.2.1"
assert convert_legacy_version_to_supported_version(legacy_verstr) == "67.2.1"
expected_converted_ver_str = "67.2.1"
assert_version_str(legacy_verstr, expected_converted_ver_str)

legacy_verstr = "A.02.17-02.40-02.17-00.52-04-01"
expected_converted_ver_str = "65.02.17"
assert_version_str(legacy_verstr, expected_converted_ver_str)
8 changes: 7 additions & 1 deletion qcodes/utils/installation_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def convert_legacy_version_to_supported_version(ver: str) -> str:
numbers to a regular version string. This is done by replacing a char
by its ASCII code (using ``ord``). This assumes that the version number
only uses at most a single char per level and only ASCII chars.
It also splits off anything that comes after the first ``-`` in the version str.
This is meant to pass versions like ``'A.02.17-02.40-02.17-00.52-04-01'``
primarily used by Keysight instruments.
"""

temp_list = []
Expand All @@ -75,4 +80,5 @@ def convert_legacy_version_to_supported_version(ver: str) -> str:
temp_list.append(str(ord(v.upper())))
else:
temp_list.append(v)
return "".join(temp_list)
temp_str = "".join(temp_list)
return temp_str.split("-")[0]

0 comments on commit 2720dce

Please sign in to comment.