From 1a7aca31f546ede0f9b698074f0427ca63b3969e Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 29 Jun 2022 08:02:56 -0400 Subject: [PATCH 1/3] test: print info --- src/app_model/_types.py | 4 ++-- tests/test_id.py | 10 ++++++++++ tox.ini | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/test_id.py diff --git a/src/app_model/_types.py b/src/app_model/_types.py index 97b293d..817c8de 100644 --- a/src/app_model/_types.py +++ b/src/app_model/_types.py @@ -1,6 +1,6 @@ from __future__ import annotations -import os +import platform import sys from typing import ( TYPE_CHECKING, @@ -19,7 +19,7 @@ from . import context -WINDOWS = os.name == "nt" +WINDOWS = platform.system() == "Windows" MACOS = sys.platform == "darwin" LINUX = sys.platform.startswith("linux") diff --git a/tests/test_id.py b/tests/test_id.py new file mode 100644 index 0000000..4e8cb70 --- /dev/null +++ b/tests/test_id.py @@ -0,0 +1,10 @@ +import os +import platform +import sys + + +def test_plat(): + print(f"{os.name=}") + print(f"{sys.platform=}") + print(f"{platform.system()=}") + print(f"{platform.release()=}") diff --git a/tox.ini b/tox.ini index 482d968..449e6ef 100644 --- a/tox.ini +++ b/tox.ini @@ -26,4 +26,4 @@ setenv = extras = test commands = - pytest -v --cov=app_model --cov-report=xml --color=yes --basetemp={envtmpdir} {posargs} + pytest -v -s --cov=app_model --cov-report=xml --color=yes --basetemp={envtmpdir} {posargs} From fb85496a2e61690cabb726702346240e89b91d58 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 29 Jun 2022 08:06:48 -0400 Subject: [PATCH 2/3] fix: fix windows keybinding --- src/app_model/_types.py | 4 ++-- tests/test_actions.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app_model/_types.py b/src/app_model/_types.py index 817c8de..97b293d 100644 --- a/src/app_model/_types.py +++ b/src/app_model/_types.py @@ -1,6 +1,6 @@ from __future__ import annotations -import platform +import os import sys from typing import ( TYPE_CHECKING, @@ -19,7 +19,7 @@ from . import context -WINDOWS = platform.system() == "Windows" +WINDOWS = os.name == "nt" MACOS = sys.platform == "darwin" LINUX = sys.platform.startswith("linux") diff --git a/tests/test_actions.py b/tests/test_actions.py index 6682572..459f065 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -23,7 +23,7 @@ dict(keybindings=[{"primary": PRIMARY_KEY}]), dict( keybindings=[ - {"primary": PRIMARY_KEY, "mac": OS_KEY, "windows": OS_KEY, "linux": OS_KEY} + {"primary": PRIMARY_KEY, "mac": OS_KEY, "win": OS_KEY, "linux": OS_KEY} ] ), dict(keybindings=[{"primary": "ctrl+a"}], menus=[{"id": MENUID}]), From 73908f1f875d2b25d0a8ab36dbd0f249dfd607a1 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 29 Jun 2022 08:08:27 -0400 Subject: [PATCH 3/3] feat: add strict model --- src/app_model/_types.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app_model/_types.py b/src/app_model/_types.py index 97b293d..aede66d 100644 --- a/src/app_model/_types.py +++ b/src/app_model/_types.py @@ -57,7 +57,12 @@ class KeybindingRuleDict(TypedDict, total=False): # ------------------ commands-related types -------------------- -class Icon(BaseModel): +class _StrictModel(BaseModel): + class Config: + extra = "forbid" + + +class Icon(_StrictModel): """Icons used to represent commands, or submenus. May provide both a light and dark variant. If only one is provided, it is used @@ -87,7 +92,7 @@ def validate(cls, v: Any) -> Icon: return cls(**v) -class CommandRule(BaseModel): +class CommandRule(_StrictModel): """Data representing a command and its presentation. Presentation of contributed commands depends on the containing menu. The Command @@ -132,7 +137,7 @@ class CommandRule(BaseModel): # ------------------ keybinding-related types -------------------- -class KeybindingRule(BaseModel): +class KeybindingRule(_StrictModel): """Data representing a keybinding and when it should be active. This model lacks a corresponding command. That gets linked up elsewhere, @@ -174,7 +179,7 @@ def _bind_to_current_platform(self) -> Optional[KeyCodeStr]: # ------------------ menus-related types -------------------- -class _MenuItemBase(BaseModel): +class _MenuItemBase(_StrictModel): """Data representing where and when a menu item should be shown.""" when: Optional[context.Expr] = Field(