Skip to content

Commit

Permalink
Ensure app bootstrap AppContext is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 8, 2024
1 parent 32f529a commit 310d39a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/1988.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The typings for ``AppContext`` passed to GUI Toolkit bootstraps for creating new projects is now correct.
5 changes: 2 additions & 3 deletions src/briefcase/bootstraps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ class AppContext(TypedDict):
app_name: str
class_name: str
module_name: str
source_dir: str
test_source_dir: str
project_name: str
description: str
author: str
author_email: str
bundle: str
url: str
license: str
briefcase_version: str
template_source: str
template_branch: str


class BaseGuiBootstrap(ABC):
Expand Down
63 changes: 63 additions & 0 deletions tests/commands/new/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PySide6GuiBootstrap,
TogaGuiBootstrap,
)
from briefcase.bootstraps.base import AppContext


@pytest.fixture
Expand All @@ -21,6 +22,68 @@ def mock_builtin_bootstraps():
}


def test_question_sequence_bootstrap_context(
new_command,
mock_builtin_bootstraps,
monkeypatch,
):
"""The context passed to GUI Toolkits is correct."""

passed_context = {}

class GuiBootstrap:
fields = []

def __init__(self, context):
nonlocal passed_context
passed_context = context.copy()

monkeypatch.setattr(
briefcase.commands.new,
"get_gui_bootstraps",
MagicMock(
return_value=dict(
**mock_builtin_bootstraps,
**{"Custom GUI": GuiBootstrap},
),
),
)

new_command.input.enabled = False

new_command.build_context(
project_overrides=dict(
formal_name="My Override App",
app_name="myoverrideapp",
bundle="net.example",
project_name="My Override Project",
description="My override description",
author="override, author",
author_email="author@override.tld",
url="https://override.example.com",
license="MIT license",
bootstrap="Custom GUI",
),
)

assert passed_context == {
"app_name": "myoverrideapp",
"author": "override, author",
"author_email": "author@override.tld",
"bundle": "net.example",
"class_name": "MyOverrideApp",
"description": "My override description",
"formal_name": "My Override App",
"license": "MIT license",
"module_name": "myoverrideapp",
"project_name": "My Override Project",
"source_dir": "src/myoverrideapp",
"test_source_dir": "tests",
"url": "https://override.example.com",
}
assert sorted(passed_context.keys()) == sorted(AppContext.__annotations__.keys())


def test_question_sequence_toga(new_command):
"""Questions are asked, a context is constructed."""

Expand Down

0 comments on commit 310d39a

Please sign in to comment.