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.base import BaseCommand
from briefcase.config import AppConfig
from ...utils import DummyConsole
class DummyCommand(BaseCommand):
"""A dummy command to test the BaseCommand interface."""
command = ("dummy",)
# Platform and format contain upper case to test case normalization
platform = "Tester"
output_format = "Dummy"
description = "Dummy base command"
def __init__(self, *args, **kwargs):
kwargs.setdefault("console", DummyConsole())
super().__init__(*args, **kwargs)
self.actions = []
def add_options(self, parser):
# Provide some extra arguments:
# * some optional arguments
parser.add_argument("-x", "--extra")
parser.add_argument("-m", "--mystery")
# * a required argument
parser.add_argument("-r", "--required", required=True)
def binary_path(self, app):
raise NotImplementedError()
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))
@pytest.fixture
def base_command(tmp_path):
command = DummyCommand(
base_path=tmp_path / "base_path",
data_path=tmp_path / "data_path",
)
command.parse_options(["-r", "default"])
return command
# Define some stub command classes
# These will be used to test the command accessor
class DummyCreateCommand(DummyCommand):
description = "Test Create"
class DummyUpdateCommand(DummyCommand):
description = "Test Update"
class DummyBuildCommand(DummyCommand):
description = "Test Build"
class DummyRunCommand(DummyCommand):
description = "Test Run"
class DummyPackageCommand(DummyCommand):
description = "Test Package"
class DummyPublishCommand(DummyCommand):
description = "Test Publish"
# Register the commands with the module
create = DummyCreateCommand
update = DummyUpdateCommand
build = DummyBuildCommand
run = DummyRunCommand
package = DummyPackageCommand
publish = DummyPublishCommand
class OtherDummyCommand(BaseCommand):
command = ("other",)
platform = "tester"
output_format = "dumdum"
description = "Another dummy command"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def binary_path(self, app):
raise NotImplementedError()
@pytest.fixture
def other_command(tmp_path):
return OtherDummyCommand(base_path=tmp_path, console=DummyConsole())
@pytest.fixture
def my_app():
return AppConfig(
app_name="my-app",
formal_name="My App",
bundle="com.example",
version="1.2.3",
description="This is a simple app",
sources=["src/my_app"],
license={"file": "LICENSE"},
)
|