1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
import pytest
from briefcase.commands import BuildCommand
from briefcase.commands.base import full_options
from briefcase.config import AppConfig
from ...utils import create_file, DummyConsole
class DummyBuildCommand(BuildCommand):
"""A dummy build command that doesn't actually do anything.
It only serves to track which actions would be performed.
"""
# Platform and format contain upper case to test case normalization
platform = "Tester"
output_format = "Dummy"
description = "Dummy build command"
def __init__(self, *args, **kwargs):
kwargs.setdefault("console", DummyConsole())
super().__init__(*args, apps={}, **kwargs)
self.actions = []
def briefcase_toml(self, app):
# default any app to an empty `briefcase.toml`
return self._briefcase_toml.get(app, {})
def binary_path(self, app):
return self.bundle_path(app) / f"{app.app_name}.dummy.bin"
def verify_host(self):
super().verify_host()
self.actions.append(("verify-host",))
def verify_tools(self):
super().verify_tools()
self.actions.append(("verify-tools",))
def finalize_app_config(self, app):
super().finalize_app_config(app=app)
self.actions.append(("finalize-app-config", app.app_name))
def verify_app_template(self, app):
super().verify_app_template(app=app)
self.actions.append(("verify-app-template", app.app_name))
def verify_app_tools(self, app):
super().verify_app_tools(app=app)
self.actions.append(("verify-app-tools", app.app_name))
def build_app(self, app, **kwargs):
self.actions.append(("build", app.app_name, kwargs.copy()))
# Remove arguments consumed by the underlying call to build_app()
kwargs.pop("update", None)
kwargs.pop("update_requirements", None)
kwargs.pop("update_resources", None)
kwargs.pop("update_support", None)
kwargs.pop("update_stub", None)
kwargs.pop("no_update", None)
kwargs.pop("test_mode", None)
return full_options({"build_state": app.app_name}, kwargs)
# These commands override the default behavior, simply tracking that
# they were invoked, rather than instantiating a Create/Update command.
# This is for testing purposes.
def create_command(self, app, **kwargs):
self.actions.append(("create", app.app_name, kwargs.copy()))
# Remove arguments consumed by the underlying call to create_app()
kwargs.pop("test_mode", None)
return full_options({"create_state": app.app_name}, kwargs)
def update_command(self, app, **kwargs):
self.actions.append(("update", app.app_name, kwargs.copy()))
# Remove arguments consumed by the underlying call to update_app()
kwargs.pop("update_requirements", None)
kwargs.pop("update_resources", None)
kwargs.pop("update_support", None)
kwargs.pop("update_stub", None)
kwargs.pop("test_mode", None)
return full_options({"update_state": app.app_name}, kwargs)
@pytest.fixture
def build_command(tmp_path):
return DummyBuildCommand(base_path=tmp_path / "base_path")
@pytest.fixture
def second_app_config():
return AppConfig(
app_name="second",
bundle="com.example",
version="0.0.2",
description="The second simple app",
sources=["src/second"],
license={"file": "LICENSE"},
)
@pytest.fixture
def second_app(second_app_config, tmp_path):
# The same fixture as second_app_config,
# but ensures that the binary for the app exists
create_file(
tmp_path
/ "base_path"
/ "build"
/ "second"
/ "tester"
/ "dummy"
/ "second.bundle",
"second.bundle",
)
create_file(
tmp_path / "base_path/build/second/tester/dummy/second.bin",
"second.bin",
)
return second_app_config
|