Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_source(base_command, my_app):
"If an app provides no source locations, an error is raised"
my_app.sources = []
with pytest.raises(BriefcaseCommandError):
base_command.app_module_path(my_app)
def test_run_app_failed(first_app_config, tmp_path):
"If there's a problem started the app, an exception is raised"
command = macOSAppRunCommand(base_path=tmp_path)
command.subprocess = mock.MagicMock()
command.subprocess.run.side_effect = BriefcaseCommandError('problem')
with pytest.raises(BriefcaseCommandError):
command.run_app(first_app_config)
# The run command was still invoked, though
command.subprocess.run.assert_called_with(
['open', tmp_path / 'macOS' / 'First App' / 'First App.app'],
check=True
)
def test_run_app_failed(first_app_config, tmp_path):
"If there's a problem started the app, an exception is raised"
command = WindowsMSIRunCommand(base_path=tmp_path)
command.subprocess = mock.MagicMock()
command.subprocess.run.side_effect = BriefcaseCommandError('problem')
with pytest.raises(BriefcaseCommandError):
command.run_app(first_app_config)
# The run command was still invoked, though
command.subprocess.run.assert_called_with(
[
str(tmp_path / 'windows' / 'First App' / 'src' / 'python' / 'pythonw.exe'),
"-m", "first_app"
],
check=True
)
def test_run_app_failed(first_app_config, tmp_path):
"If there's a problem started the app, an exception is raised"
command = WindowsMSIRunCommand(base_path=tmp_path)
command.subprocess = mock.MagicMock()
command.subprocess.run.side_effect = BriefcaseCommandError('problem')
with pytest.raises(BriefcaseCommandError):
command.run_app(first_app_config)
# The run command was still invoked, though
command.subprocess.run.assert_called_with(
[
str(tmp_path / 'windows' / 'First App' / 'src' / 'python' / 'pythonw.exe'),
"-m", "first_app"
],
check=True
)
def test_no_args_two_apps(dev_command, first_app, second_app):
"If there are one app, dev starts that app by default"
# 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)
# No apps will be launched
assert dev_command.actions == []
def test_unknown_device():
"If you ask for an invalid device UDID, an exception is raised."
sub = mock.MagicMock()
sub.check_output.return_value = simctl_result('no-devices')
with pytest.raises(BriefcaseCommandError):
get_device_state('dead-beef-dead-beef', sub=sub)
from cookiecutter.repository import is_repo_url
from git import exc as git_exceptions
from briefcase import __version__
from briefcase.config import AppConfig, GlobalConfig, parse_config
from briefcase.exceptions import (
BadNetworkResourceError,
BriefcaseCommandError,
BriefcaseConfigError,
MissingNetworkResourceError
)
try:
import git
except ImportError:
raise BriefcaseCommandError("""
Briefcase requires git, but it is not installed (or is not on your PATH). Visit:
https://git-scm.com/
to download and install git. If you have installed git recently and are still
getting this error, you may need to restart your terminal session.""")
class TemplateUnsupportedVersion(BriefcaseCommandError):
def __init__(self, version_tag):
self.version_tag = version_tag
super().__init__(
msg='Template does not support {version_tag}'.format(
version_tag=version_tag
)
)
confirm that it is a valid codesigning identity.
:returns: The final identity to use
"""
# Obtain the valid codesigning identities.
identities = self.get_identities('codesigning')
if identity:
try:
# Try to look up the identity as a hex checksum
return identities[identity]
except KeyError:
# It's not a valid checksum; try to use it as a value.
if identity in identities.values():
return identity
raise BriefcaseCommandError(
"Invalid code signing identity {identity!r}".format(
identity=identity
)
)
if len(identities) == 0:
raise BriefcaseCommandError(
"No code signing identities are available."
)
elif len(identities) == 1:
identity = list(identities.items())[0][1]
else:
print()
print("Select code signing identity to use:")
print()
selection = select_option(identities, input=self.input)
)
elif len(simulators) == 1:
iOS_version = list(simulators.keys())[0]
else:
print()
print("Select iOS version:")
print()
iOS_version = select_option({
version: version
for version in simulators.keys()
}, input=self.input)
devices = simulators[iOS_version]
if len(devices) == 0:
raise BriefcaseCommandError(
"No simulators available for iOS {iOS_version}.".format(
iOS_version=iOS_version
)
)
elif len(devices) == 1:
udid = list(devices.keys())[0]
else:
print()
print("Select simulator device:")
print()
udid = select_option(devices, input=self.input)
device = devices[udid]
return udid, iOS_version, device
try:
print("Signing", path)
self.subprocess.run(
[
'codesign',
'--sign', identity,
'--entitlements', str(entitlements),
'--deep', str(path),
'--force',
'--options', 'runtime',
],
check=True,
)
except subprocess.CalledProcessError:
print()
raise BriefcaseCommandError(
"Unable to code sign {path}.".format(path=path)
)