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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
import pytest
from briefcase.exceptions import BriefcaseConfigError
from ...utils import create_file
def test_missing_config(base_command):
"""If the configuration file doesn't exit, raise an error."""
filename = base_command.base_path / "does_not_exist.toml"
with pytest.raises(BriefcaseConfigError, match="Configuration file not found"):
base_command.parse_config(filename, {})
def test_incomplete_global_config(base_command):
"""If the global configuration is missing a required argument, an error is
raised."""
# Provide a configuration that is missing `bundle`, a required attribute
filename = base_command.base_path / "pyproject.toml"
create_file(
filename,
"""
[tool.briefcase]
version = "1.2.3"
description = "A sample app"
license.file = "LICENSE"
[tool.briefcase.app.my-app]
""",
)
with pytest.raises(
BriefcaseConfigError,
match=r"Global configuration is incomplete \(missing 'bundle', 'project_name'\)",
):
base_command.parse_config(filename, {})
def test_incomplete_config(base_command):
"""If the configuration is missing a required argument, an error is raised."""
# Provide a configuration that is missing `bundle`, a required attribute
filename = base_command.base_path / "pyproject.toml"
create_file(
filename,
"""
[tool.briefcase]
project_name = "Sample project"
version = "1.2.3"
bundle = "com.example"
description = "A sample app"
license.file = "LICENSE"
[tool.briefcase.app.my-app]
""",
)
with pytest.raises(
BriefcaseConfigError,
match=r"Configuration for 'my-app' is incomplete \(missing 'sources'\)",
):
base_command.parse_config(filename, {})
def test_parse_config(base_command):
"""A well-formed configuration file can turned into a set of configurations."""
filename = base_command.base_path / "pyproject.toml"
create_file(
filename,
"""
[tool.briefcase]
project_name = "Sample project"
version = "1.2.3"
description = "A sample app"
bundle = "org.beeware"
mystery = 'default'
license.file = "LICENSE"
[tool.briefcase.app.firstapp]
sources = ['src/firstapp']
[tool.briefcase.app.secondapp]
sources = ['src/secondapp']
extra = 'something'
mystery = 'sekrits'
""",
)
# Parse the configuration, no overrides
base_command.parse_config(filename, {})
# There is a global configuration object
assert repr(base_command.global_config) == "<Sample project v1.2.3 GlobalConfig>"
assert base_command.global_config.project_name == "Sample project"
assert base_command.global_config.bundle == "org.beeware"
assert base_command.global_config.version == "1.2.3"
# The first app will have all the base attributes required by an app,
# defined in the config file.
assert (
repr(base_command.apps["firstapp"]) == "<org.beeware.firstapp v1.2.3 AppConfig>"
)
assert base_command.apps["firstapp"].project_name == "Sample project"
assert base_command.apps["firstapp"].app_name == "firstapp"
assert base_command.apps["firstapp"].bundle == "org.beeware"
assert base_command.apps["firstapp"].mystery == "default"
assert not hasattr(base_command.apps["firstapp"], "extra")
# The second app is much the same, except that it has an override
# value for `mystery`, and an `extra` value.
assert (
repr(base_command.apps["secondapp"])
== "<org.beeware.secondapp v1.2.3 AppConfig>"
)
assert base_command.apps["secondapp"].project_name == "Sample project"
assert base_command.apps["secondapp"].app_name == "secondapp"
assert base_command.apps["secondapp"].bundle == "org.beeware"
assert base_command.apps["secondapp"].mystery == "sekrits"
assert base_command.apps["secondapp"].extra == "something"
def test_parse_config_with_overrides(base_command):
"""A well-formed configuration file can be augmented by the command line."""
filename = base_command.base_path / "pyproject.toml"
create_file(
filename,
"""
[tool.briefcase]
project_name = "Sample project"
version = "1.2.3"
description = "A sample app"
bundle = "org.beeware"
mystery = 'default'
license.file = "LICENSE"
[tool.briefcase.app.firstapp]
sources = ['src/firstapp']
[tool.briefcase.app.secondapp]
sources = ['src/secondapp']
extra = 'something'
mystery = 'sekrits'
""",
)
# Parse the configuration, with overrides
base_command.parse_config(
filename,
{
"version": "2.3.4",
"custom": "something special",
"mystery": "overridden",
},
)
# There is a global configuration object. It picks up the override values.
assert repr(base_command.global_config) == "<Sample project v2.3.4 GlobalConfig>"
assert base_command.global_config.project_name == "Sample project"
assert base_command.global_config.bundle == "org.beeware"
assert base_command.global_config.version == "2.3.4"
assert base_command.global_config.custom == "something special"
assert base_command.global_config.mystery == "overridden"
# The first app will have all the base attributes required by an app,
# defined in the config file, with the values from the overrides taking precedence.
assert (
repr(base_command.apps["firstapp"]) == "<org.beeware.firstapp v2.3.4 AppConfig>"
)
assert base_command.apps["firstapp"].project_name == "Sample project"
assert base_command.apps["firstapp"].app_name == "firstapp"
assert base_command.apps["firstapp"].bundle == "org.beeware"
assert base_command.apps["firstapp"].version == "2.3.4"
assert base_command.apps["firstapp"].custom == "something special"
assert base_command.apps["firstapp"].mystery == "overridden"
assert not hasattr(base_command.apps["firstapp"], "extra")
# The second app is much the same. The value for `mystery`` is overridden by the
# command line (superseding the app override); but the `extra` app-specific value
# is preserved.
assert (
repr(base_command.apps["secondapp"])
== "<org.beeware.secondapp v2.3.4 AppConfig>"
)
assert base_command.apps["secondapp"].project_name == "Sample project"
assert base_command.apps["secondapp"].app_name == "secondapp"
assert base_command.apps["secondapp"].bundle == "org.beeware"
assert base_command.apps["secondapp"].version == "2.3.4"
assert base_command.apps["secondapp"].custom == "something special"
assert base_command.apps["secondapp"].mystery == "overridden"
assert base_command.apps["secondapp"].extra == "something"
def test_parse_config_with_invalid_override(base_command):
"""If an override value doesn't pass validation, an exception is raised."""
filename = base_command.base_path / "pyproject.toml"
create_file(
filename,
"""
[tool.briefcase]
project_name = "Sample project"
version = "1.2.3"
description = "A sample app"
bundle = "org.beeware"
mystery = 'default'
license.file = "LICENSE"
[tool.briefcase.app.firstapp]
sources = ['src/firstapp']
""",
)
# Parse the configuration, with overrides
with pytest.raises(
BriefcaseConfigError,
match=r"Version numbers must be PEP440 compliant",
):
base_command.parse_config(
filename,
{
"version": "not-a-version-number",
},
)
|