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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
import pytest
from briefcase.config import AppConfig
from briefcase.exceptions import BriefcaseConfigError
from .conftest import DummyCommand
@pytest.fixture
def first_app():
return AppConfig(
app_name="first",
bundle="com.example",
version="0.0.1",
description="The first simple app",
sources=["src/first"],
license={"file": "LICENSE"},
)
@pytest.fixture
def second_app():
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 base_command(dummy_console, tmp_path, first_app, second_app):
return DummyCommand(
console=dummy_console,
base_path=tmp_path,
apps={
"first": first_app,
"second": second_app,
},
)
def test_finalize_all(base_command, first_app, second_app):
"A call to finalize verifies host, tools, and finalized all app configs"
base_command.finalize()
# The right sequence of things will be done
assert base_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
# App config has been finalized
("finalize-app-config", "second"),
]
# Apps are no longer in draft mode
assert not hasattr(first_app, "__draft__")
assert not hasattr(second_app, "__draft__")
def test_finalize_single(base_command, first_app, second_app):
"A call to finalize verifies host, tools, and finalized all app configs"
base_command.finalize(first_app)
# The right sequence of things will be done
assert base_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
]
# First app is no longer in draft mode; second is
assert not hasattr(first_app, "__draft__")
assert hasattr(second_app, "__draft__")
def test_finalize_all_repeat(base_command, first_app, second_app):
"Multiple calls to finalize verifies host & tools multiple times, but only once on config"
# Finalize apps twice. This is an approximation of what happens
# when a command chain is executed; create, update, build and run will
# all finalize; create will finalize the app configs, each command will
# have it's own tools verified.
base_command.finalize()
base_command.finalize()
# The right sequence of things will be done
assert base_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
# App config has been finalized
("finalize-app-config", "second"),
# Host OS is verified again
("verify-host",),
# Tools are verified again
("verify-tools",),
]
# Apps are no longer in draft mode
assert not hasattr(first_app, "__draft__")
assert not hasattr(second_app, "__draft__")
def test_finalize_single_repeat(base_command, first_app, second_app):
"Multiple calls to finalize verifies host & tools multiple times, but finalizes app config once"
# Finalize app twice. This is an approximation of what happens
# when a command chain is executed; create, update, build and run will
# all finalize; create will finalize the app config, each command will
# have it's own tools verified.
base_command.finalize(first_app)
base_command.finalize(first_app)
# The right sequence of things will be done
assert base_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App config has been finalized
("finalize-app-config", "first"),
# Host OS is verified again
("verify-host",),
# Tools are verified again
("verify-tools",),
]
# First app is no longer in draft mode; second is
assert not hasattr(first_app, "__draft__")
assert hasattr(second_app, "__draft__")
def test_external_and_internal(base_command, first_app):
"""If an app provides both sources and external_package_path, an error is raised."""
first_app.external_package_path = "path/to/package"
with pytest.raises(
BriefcaseConfigError,
match=r"'first' is declared as an external app, but also defines 'sources'",
):
base_command.finalize(first_app)
def test_not_external_or_internal(base_command, first_app):
"""If an app provides neither sources or external_package_path, an error is
raised."""
first_app.sources = None
with pytest.raises(
BriefcaseConfigError,
match=r"'first' does not define either 'sources' or 'external_package_path'.",
):
base_command.finalize(first_app)
def test_binary_path_internal_app(base_command, first_app):
"""If an internal app defines external_package_executable_path, an error is
raised."""
first_app.external_package_executable_path = "internal/app.exe"
with pytest.raises(
BriefcaseConfigError,
match=r"'first' defines 'external_package_executable_path', but not 'external_package_path'",
):
base_command.finalize(first_app)
|