diff --git a/src/app_model/types/_constants.py b/src/app_model/types/_constants.py index d592967b..137b5d6d 100644 --- a/src/app_model/types/_constants.py +++ b/src/app_model/types/_constants.py @@ -26,18 +26,18 @@ def current() -> "OperatingSystem": @property def is_windows(self) -> bool: - """Returns True if the current operating system is Windows.""" - return _CURRENT == OperatingSystem.WINDOWS + """Returns True if this operating system is Windows.""" + return self == OperatingSystem.WINDOWS @property def is_linux(self) -> bool: - """Returns True if the current operating system is Linux.""" - return _CURRENT == OperatingSystem.LINUX + """Returns True if this operating system is Linux.""" + return self == OperatingSystem.LINUX @property def is_mac(self) -> bool: - """Returns True if the current operating system is MacOS.""" - return _CURRENT == OperatingSystem.MACOS + """Returns True if this operating system is MacOS.""" + return self == OperatingSystem.MACOS _CURRENT = OperatingSystem.UNKNOWN diff --git a/tests/test_keybindings.py b/tests/test_keybindings.py index 503f8187..64a61c39 100644 --- a/tests/test_keybindings.py +++ b/tests/test_keybindings.py @@ -188,3 +188,18 @@ class M(BaseModel): m = M(key=StandardKeyBinding.Copy) assert m.key.primary == KeyMod.CtrlCmd | KeyCode.KeyC + + +@pytest.mark.parametrize( + ("enc", "os", "expect"), + [ + (KeyMod.CtrlCmd | KeyCode.KeyX, OperatingSystem.MACOS, "Cmd+X"), + (KeyMod.CtrlCmd | KeyCode.KeyX, OperatingSystem.WINDOWS, "Ctrl+X"), + (KeyMod.WinCtrl | KeyCode.KeyX, OperatingSystem.MACOS, "Control+X"), + (KeyMod.WinCtrl | KeyCode.KeyX, OperatingSystem.WINDOWS, "Win+X"), + ], +) +def test_int_conversion_respects_os(enc: int, os: OperatingSystem, expect: str) -> None: + kb = KeyBinding.from_int(enc, os=os) + assert kb.to_text(os=os) == expect + assert kb.to_int(os=os) == enc