def test_minimal_AppConfig(): "A simple config can be defined" config = AppConfig( name="myapp", version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/myapp'], ) # The basic properties have been set. assert config.name == "myapp" assert config.version == '1.2.3' assert config.bundle == 'org.beeware' assert config.description == 'A simple app' assert config.requires is None # Derived properties have been set. assert config.formal_name == 'myapp' assert config.document_types == {} # There is no icon or splash of any kind assert config.icon is None assert config.splash is None assert repr(config) == "<org.beeware.myapp v1.2.3 AppConfig>"
def test_doctype_icon_target(create_command, tmp_path): "If the template defines document types, their icons will be installed" myapp = 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'], document_type={ 'mydoc': { 'icon': 'images/mydoc-icon' }, 'other': { 'icon': 'images/other-icon', } }) # Prime the path index with 2 document types; # * mydoc, which has a single static image; and # * other, which has multiple size targets. create_command._path_index = { myapp: { 'document_type_icon': { 'mydoc': 'path/to/mydoc-icon.png', 'other': { '10': 'path/to/other-icon-10.png', '20': 'path/to/other-icon-20.png', } } } } install_image = mock.MagicMock() create_command.install_image = install_image # Install app resources create_command.install_app_resources(myapp) # 2 calls to install doctype icon images will be made install_image.assert_has_calls([ mock.call( 'icon for .mydoc documents', source='images/mydoc-icon', variant=None, size=None, target=tmp_path / 'tester/my-app.bundle/path/to/mydoc-icon.png'), mock.call('icon for .other documents', source='images/other-icon', variant=None, size='10', target=tmp_path / 'tester/my-app.bundle/path/to/other-icon-10.png'), mock.call('icon for .other documents', source='images/other-icon', variant=None, size='20', target=tmp_path / 'tester/my-app.bundle/path/to/other-icon-20.png'), ], any_order=True)
def test_minimal_AppConfig(): """A simple config can be defined.""" config = AppConfig( app_name="myapp", version="1.2.3", bundle="org.beeware", description="A simple app", sources=["src/myapp", "somewhere/else/interesting"], ) # The basic properties have been set. assert config.app_name == "myapp" assert config.version == "1.2.3" assert config.bundle == "org.beeware" assert config.description == "A simple app" assert config.requires is None # Derived properties have been set. assert config.formal_name == "myapp" assert config.document_types == {} # There is no icon or splash of any kind assert config.icon is None assert config.splash is None # The PYTHONPATH is derived correctly assert config.PYTHONPATH == ["src", "somewhere/else"] # The object has a meaningful REPL assert repr(config) == "<org.beeware.myapp v1.2.3 AppConfig>"
def second_app_config(): return AppConfig( app_name='second', bundle='com.example', version='0.0.2', description='The second simple app', sources=['src/second'], )
def test_package_name(bundle, package_name): config = AppConfig(app_name="myapp", version="1.2.3", bundle=bundle, description="A simple app", sources=['src/myapp']) assert config.package_name == package_name
def first_app_config(): return AppConfig( app_name='first', bundle='com.example', version='0.0.1', description='The first simple app', sources=['src/first'], )
def test_invalid_app_name(name): with pytest.raises(BriefcaseConfigError, match=r"is not a valid app name\."): AppConfig(app_name=name, version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/invalid'])
def second_app_config(): return AppConfig( app_name="second", bundle="com.example", version="0.0.2", description="The second simple app", sources=["src/second"], )
def test_duplicated_source(sources): with pytest.raises(BriefcaseConfigError, match=r"contains duplicated package names\."): AppConfig(app_name='dupe', version="1.2.3", bundle="org.beeware", description="A simple app", sources=sources)
def test_no_source_for_app(): with pytest.raises(BriefcaseConfigError, match=r" does not include a package named 'my_app'\."): AppConfig(app_name='my-app', version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/something', 'src/other'])
def test_module_name(name, module_name): config = AppConfig(app_name=name, version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/' + module_name]) assert config.module_name == module_name
def test_invalid_app_version(): with pytest.raises(BriefcaseConfigError, match=r"Version number for myapp.*is not valid\."): AppConfig(app_name="myapp", version="foobar", bundle="org.beeware", description="A simple app", sources=['src/invalid'])
def first_app_config(): return AppConfig( app_name="first", bundle="com.example", version="0.0.1", description="The first simple app", sources=["src/first"], )
def test_valid_app_name(name): try: AppConfig(app_name=name, version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/' + name.replace('-', '_')]) except BriefcaseConfigError: pytest.fail('{name} should be valid'.format(name=name))
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'], )
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"], )
def test_valid_app_version(): try: AppConfig(app_name="myapp", version="1.2.3", bundle="org.beeware", description="A simple app", sources=['src/myapp']) except BriefcaseConfigError: pytest.fail('1.2.3 should be a valid version number')
def pytest_cmdline_main(config): "Parse the command line, adding the sys.path entries needed to support the app" app_name = config.getoption("app") platform = config.getoption("platform") # Load the platform module and determine the default output format. platforms = get_platforms() platform_module = platforms[platform] # Determine the output format to target try: output_format = config.getoption("output_format") except ValueError: output_format = platform_module.DEFAULT_OUTPUT_FORMAT # Load the application config from the pyproject.toml # in the pytest rootdir _, app_configs = parse_config(config.rootdir / 'pyproject.toml', platform=platform, output_format=output_format) # If no app name has been provided, check to see if there is # a single app in the project. If there is, use it. Otherwise, # raise an error. # If an app name has been provided, load that app config. if app_name == '*': if len(app_configs) == 1: app = AppConfig(**list(app_configs.values())[0]) else: raise BriefcasePytestConfigError( 'More than one app in the porject. Specify an app name with --app' ) else: try: app = AppConfig(**app_configs[app_name]) except KeyError: raise BriefcasePytestConfigError( "'{app_name}' is not an app name in this project".format( app_name=app_name)) # Process the `sources` list for the app, adding to the pythonpath. # This matches the PYTHONPATH configuration done by `briefcase dev` for path in app.PYTHONPATH: sys.path.insert(0, str(config.rootdir / path))
def first_app_config(): return AppConfig( app_name="first-app", project_name="First Project", formal_name="First App", bundle="com.example", version="0.0.1", description="The first simple app", sources=["src/first_app"], )
def first_app_config(): return AppConfig( app_name='first-app', project_name='First Project', formal_name='First App', bundle='com.example', version='0.0.1', description='The first simple app', sources=['src/first_app'], )
def test_invalid_bundle_identifier(bundle): with pytest.raises(BriefcaseConfigError, match=r"is not a valid bundle identifier\."): AppConfig( app_name="myapp", version="1.2.3", bundle=bundle, description="A simple app", sources=["src/invalid"], )
def test_valid_app_name(name): try: AppConfig( app_name=name, version="1.2.3", bundle="org.beeware", description="A simple app", sources=["src/" + name.replace("-", "_")], ) except BriefcaseConfigError: pytest.fail(f"{name} should be valid")
def test_valid_bundle(bundle): try: AppConfig( app_name="myapp", version="1.2.3", bundle=bundle, description="A simple app", sources=["src/myapp"], ) except BriefcaseConfigError: pytest.fail(f"{bundle} should be valid")
def update_command(tmp_path): return DummyUpdateCommand(base_path=tmp_path, apps={ 'first': AppConfig( app_name='first', bundle='com.example', version='0.0.1', description='The first simple app', sources=['src/first'], ), 'second': AppConfig( app_name='second', bundle='com.example', version='0.0.2', description='The second simple app', sources=['src/second'], ), })
def tracking_create_command(tmp_path, mock_git): return TrackingCreateCommand(git=mock_git, base_path=tmp_path, apps={ 'first': AppConfig( app_name='first', bundle='com.example', version='0.0.1', description='The first simple app', sources=['src/first'], ), 'second': AppConfig( app_name='second', bundle='com.example', version='0.0.2', description='The second simple app', sources=['src/second'], ), })
def myapp(): 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"], url="https://example.com", author="First Last", author_email="*****@*****.**", )
def update_command(tmp_path): return DummyUpdateCommand( base_path=tmp_path, apps={ "first": AppConfig( app_name="first", bundle="com.example", version="0.0.1", description="The first simple app", sources=["src/first"], ), "second": AppConfig( app_name="second", bundle="com.example", version="0.0.2", description="The second simple app", sources=["src/second"], ), }, )
def first_app_uninstalled(tmp_path): # Make sure the source code exists (tmp_path / "src" / "first").mkdir(parents=True, exist_ok=True) with (tmp_path / "src" / "first" / "__init__.py").open("w") as f: f.write('print("Hello world")') return AppConfig( app_name="first", bundle="com.example", version="0.0.1", description="The first simple app", sources=["src/first"], )
def first_app_uninstalled(tmp_path): # Make sure the source code exists (tmp_path / 'src' / 'first').mkdir(parents=True, exist_ok=True) with (tmp_path / 'src' / 'first' / '__init__.py').open('w') as f: f.write('print("Hello world")') return AppConfig( name='first', bundle='com.example', version='0.0.1', description='The first simple app', sources=['src/first'], )
def tracking_create_command(tmp_path, mock_git): return TrackingCreateCommand( git=mock_git, base_path=tmp_path, apps={ "first": AppConfig( app_name="first", bundle="com.example", version="0.0.1", description="The first simple app", sources=["src/first"], ), "second": AppConfig( app_name="second", bundle="com.example", version="0.0.2", description="The second simple app", sources=["src/second"], ), }, )