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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
import pytest
from briefcase.commands import DevCommand
from briefcase.commands.base import full_options
from briefcase.console import Console
from briefcase.exceptions import BriefcaseCommandError
class DummyDevCommand(DevCommand):
"""A dummy Dev 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 dev command"
def __init__(self, *args, **kwargs):
kwargs.setdefault("console", Console())
super().__init__(*args, apps={}, **kwargs)
self.actions = []
self.env = dict(a=1, b=2, c=3)
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 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 install_dev_requirements(self, app, **kwargs):
self.actions.append(("dev_requirements", app.app_name, kwargs))
def get_environment(self, app, test_mode):
return self.env
def run_dev_app(self, app, env, **kwargs):
self.actions.append(("run_dev", app.app_name, kwargs, env))
return full_options({"run_dev_state": app.app_name, "env": env}, kwargs)
@pytest.fixture
def dev_command(tmp_path):
return DummyDevCommand(base_path=tmp_path)
def test_no_args_one_app(dev_command, first_app):
"""If there is one app, dev starts that app by default."""
# Add a single app
dev_command.apps = {
"first": first_app,
}
# Configure no command line options
options, _ = dev_command.parse_options([])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# Run the first app devly
("run_dev", "first", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_no_args_two_apps(dev_command, first_app, second_app):
"""If there are two apps and no explicit app provided, an error is raised."""
# Add two apps
dev_command.apps = {
"first": first_app,
"second": second_app,
}
# Configure no command line options
options, _ = dev_command.parse_options([])
# Invoking the run command raises an error
with pytest.raises(BriefcaseCommandError):
dev_command(**options)
# Finalization will not occur.
assert dev_command.actions == []
def test_with_arg_one_app(dev_command, first_app):
"""If there is one app, and a -a argument, dev starts that app."""
# Add a single app
dev_command.apps = {
"first": first_app,
}
# Configure a -a command line option
options, _ = dev_command.parse_options(["-a", "first"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# Run the first app devly
("run_dev", "first", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_with_arg_two_apps(dev_command, first_app, second_app):
"""If there are multiple apps, the --app argument starts app nominated."""
# Add two apps
dev_command.apps = {
"first": first_app,
"second": second_app,
}
# Configure a --app command line option
options, _ = dev_command.parse_options(["--app", "second"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "second"),
# App tools are verified for app
("verify-app-tools", "second"),
# Run the second app devly
("run_dev", "second", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_bad_app_reference(dev_command, first_app, second_app):
"""If the command line argument refers to an app that doesn't exist, raise an
error."""
# Add two apps
dev_command.apps = {
"first": first_app,
"second": second_app,
}
# Configure a --app command line option
options, _ = dev_command.parse_options(["--app", "does-not-exist"])
# Invoking the run command raises an error
with pytest.raises(BriefcaseCommandError):
dev_command(**options)
# Finalization will not occur.
assert dev_command.actions == []
def test_update_requirements(dev_command, first_app):
"""The dev command can request that the app is updated first."""
# Add a single app
dev_command.apps = {
"first": first_app,
}
# Configure a requirements update
options, _ = dev_command.parse_options(["-r"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# An update was requested
("dev_requirements", "first", {}),
# Then, it will be started
("run_dev", "first", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_run_uninstalled(dev_command, first_app_uninstalled):
"""The dev command will install first if the app hasn't been installed."""
# Add a single app
dev_command.apps = {
"first": first_app_uninstalled,
}
# Configure no command line options
options, _ = dev_command.parse_options([])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# The app will be installed
("dev_requirements", "first", {}),
# Then, it will be started
("run_dev", "first", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_update_uninstalled(dev_command, first_app_uninstalled):
"""A request to update requirements is redundant if the app hasn't been
installed."""
# Add a single app
dev_command.apps = {
"first": first_app_uninstalled,
}
# Configure a requirements update
options, _ = dev_command.parse_options(["-r"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# An update was requested
("dev_requirements", "first", {}),
# Then, it will be started
("run_dev", "first", {"test_mode": False, "passthrough": []}, dev_command.env),
]
def test_no_run(dev_command, first_app_uninstalled):
"""Install requirements without running the app."""
# Add a single app
dev_command.apps = {
"first": first_app_uninstalled,
}
# Configure an update without run
options, _ = dev_command.parse_options(["--no-run"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# Only update requirements without running the app
("dev_requirements", "first", {}),
]
def test_run_test(dev_command, first_app):
"""The test suite can be run in development mode."""
# Add a single app
dev_command.apps = {
"first": first_app,
}
# Configure the test option
options, _ = dev_command.parse_options(["--test"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# Then, it will be started
("run_dev", "first", {"test_mode": True, "passthrough": []}, dev_command.env),
]
def test_run_test_uninstalled(dev_command, first_app_uninstalled):
"""The test suite can be run in development mode."""
# Add a single app
dev_command.apps = {
"first": first_app_uninstalled,
}
# Configure the test option
options, _ = dev_command.parse_options(["--test"])
# Run the run command
dev_command(**options)
# The right sequence of things will be done
assert dev_command.actions == [
# Host OS is verified
("verify-host",),
# Tools are verified
("verify-tools",),
# App template is verified
("verify-app-template", "first"),
# App tools are verified for app
("verify-app-tools", "first"),
# Development requirements will be installed
("dev_requirements", "first", {}),
# Then, it will be started
("run_dev", "first", {"test_mode": True, "passthrough": []}, dev_command.env),
]
|