From afd071c24e33e1e059dc7c798f2e02b55c9abfe0 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sat, 21 Dec 2024 14:17:41 -0700 Subject: [PATCH] Fix windows-11 detection for non-float platform.release() values (fixes #639) --- meshtastic/tests/test_util.py | 7 +++++++ meshtastic/util.py | 14 +++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index ab457217..94b49332 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -442,6 +442,13 @@ def test_is_windows11_false_win8_1(patched_platform, patched_release): patched_platform.assert_called() patched_release.assert_called() +@patch("platform.release", return_value="2022Server") +@patch("platform.system", return_value="Windows") +def test_is_windows11_false_winserver(patched_platform, patched_release): + """Test is_windows11()""" + assert is_windows11() is False + patched_platform.assert_called() + patched_release.assert_called() @pytest.mark.unit @patch("platform.system", return_value="Linux") diff --git a/meshtastic/util.py b/meshtastic/util.py index f36655e6..f1589af0 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -521,15 +521,15 @@ def is_windows11() -> bool: """Detect if Windows 11""" is_win11: bool = False if platform.system() == "Windows": - if float(platform.release()) >= 10.0: - patch = platform.version().split(".")[2] - # in case they add some number suffix later, just get first 5 chars of patch - patch = patch[:5] - try: + try: + if float(platform.release()) >= 10.0: + patch = platform.version().split(".")[2] + # in case they add some number suffix later, just get first 5 chars of patch + patch = patch[:5] if int(patch) >= 22000: is_win11 = True - except Exception as e: - print(f"problem detecting win11 e:{e}") + except Exception as e: + print(f"problem detecting win11 e:{e}") return is_win11