def test_packages_plugin_no_attr( self, monkeypatch, host_arch, target_arch, packages, expected_amd64, expected_i386, expected_armhf, ): monkeypatch.setattr(platform, "machine", lambda: host_arch) monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF")) repo = mock.Mock() class Plugin: pass plugin = Plugin() processor = PartGrammarProcessor( plugin=plugin, properties={"build-packages": packages}, project=project.Project(target_deb_arch=target_arch), repo=repo, ) expected_arch = dict( expected_amd64=expected_amd64, expected_i386=expected_i386, expected_armhf=expected_armhf, ) assert (processor.get_build_packages() == expected_arch[f"expected_{target_arch}"])
def test( self, monkeypatch, host_arch, target_arch, properties, expected_amd64, expected_i386, expected_armhf, ): monkeypatch.setattr(platform, "machine", lambda: host_arch) monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF")) repo = mock.Mock() plugin = mock.Mock() plugin.properties = properties.copy() expected_arch = dict( expected_amd64=expected_amd64, expected_i386=expected_i386, expected_armhf=expected_armhf, ) assert (PartGrammarProcessor( plugin=plugin, properties=plugin.properties, project=project.Project(target_deb_arch=target_arch), repo=repo, ).get_source() == expected_arch[f"expected_{target_arch}"]) # Verify that the original properties haven't changed assert plugin.properties == properties
def test_build_snaps(self, platform_machine_mock, platform_architecture_mock): platform_machine_mock.return_value = self.host_arch platform_architecture_mock.return_value = ("64bit", "ELF") repo = mock.Mock() class Plugin: build_snaps = self.snaps stage_snaps = self.snaps plugin = Plugin() expected = getattr(self, "expected_{}".format(self.target_arch)) processor = PartGrammarProcessor( plugin=plugin, properties={ "build-snaps": {"plugin-preferred"}, "stage-snaps": "plugin-preferred", }, project=project.Project(target_deb_arch=self.target_arch), repo=repo, ) self.assertThat(processor.get_build_snaps(), Equals(expected)) self.assertThat(processor.get_stage_snaps(), Equals(expected))
def make_snapcraft_project(self, apps): snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path) snapcraft_yaml.update_part("part1", dict(plugin="nil")) for app_name, app in apps: snapcraft_yaml.update_app(app_name, app) self.useFixture(snapcraft_yaml) p = project.Project( snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) return load_config(p)
def get_user_agent(platform: str = sys.platform) -> str: arch = project.Project().deb_arch testing = "(testing) " if _is_ci_env() else "" if platform == "linux": os_platform = _get_linux_release(os_release.OsRelease()) else: os_platform = platform.title() return f"snapcraft/{snapcraft.__version__} {testing}{os_platform} ({arch})"
def setUp(self): super().setUp() self.part1 = self.load_part("part1") self.part2 = self.load_part("part2") self.parts = [self.part1, self.part2] self.project = project.Project() self.part1.makedirs() self.part2.makedirs()
def get_project_config(snapcraft_yaml_content, target_deb_arch=None): snapcraft_yaml_path = pathlib.Path("Snapcraft.yaml") with snapcraft_yaml_path.open("w") as snapcraft_yaml_file: print(snapcraft_yaml_content, file=snapcraft_yaml_file) snapcraft_project = project.Project( snapcraft_yaml_file_path=snapcraft_yaml_path.as_posix(), target_deb_arch=target_deb_arch, ) return load_config(snapcraft_project)
def test_build_snaps(self, platform_machine_mock, platform_architecture_mock): platform_machine_mock.return_value = self.host_arch platform_architecture_mock.return_value = ('64bit', 'ELF') repo = mock.Mock() plugin = mock.Mock() plugin.build_snaps = self.build_snaps expected = getattr(self, 'expected_{}'.format(self.target_arch)) self.assertThat( PartGrammarProcessor( plugin=plugin, properties={}, project=project.Project(target_deb_arch=self.target_arch), repo=repo).get_build_snaps(), Equals(expected))
def test_source(self, platform_machine_mock, platform_architecture_mock): platform_machine_mock.return_value = self.host_arch platform_architecture_mock.return_value = ('64bit', 'ELF') repo = mock.Mock() plugin = mock.Mock() plugin.properties = self.properties.copy() expected = getattr(self, 'expected_{}'.format(self.target_arch)) self.assertThat( PartGrammarProcessor( plugin=plugin, properties=plugin.properties, project=project.Project(target_deb_arch=self.target_arch), repo=repo).get_source(), Equals(expected)) # Verify that the original properties haven't changed self.assertThat(plugin.properties, Equals(self.properties))
def test_packages(self, platform_machine_mock, platform_architecture_mock): platform_machine_mock.return_value = self.host_arch platform_architecture_mock.return_value = ("64bit", "ELF") repo = mock.Mock() plugin = mock.Mock() plugin.build_packages = self.packages plugin.stage_packages = self.packages expected = getattr(self, "expected_{}".format(self.target_arch)) processor = PartGrammarProcessor( plugin=plugin, properties={}, project=project.Project(target_deb_arch=self.target_arch), repo=repo, ) self.assertThat(processor.get_build_packages(), Equals(expected)) self.assertThat(processor.get_stage_packages(), Equals(expected))
def test_snaps( self, monkeypatch, host_arch, target_arch, snaps, expected_amd64, expected_i386, expected_armhf, ): monkeypatch.setattr(platform, "machine", lambda: host_arch) monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF")) monkeypatch.setattr( snapcraft_repo.snaps.SnapPackage, "is_valid_snap", lambda x: "invalid" not in x, ) repo = mock.Mock() class Plugin: build_snaps = snaps stage_snaps = snaps plugin = Plugin() processor = PartGrammarProcessor( plugin=plugin, properties={ "build-snaps": {"plugin-preferred"}, "stage-snaps": "plugin-preferred", }, project=project.Project(target_deb_arch=target_arch), repo=repo, ) expected_arch = dict( expected_amd64=expected_amd64, expected_i386=expected_i386, expected_armhf=expected_armhf, ) assert processor.get_build_snaps( ) == expected_arch[f"expected_{target_arch}"] assert processor.get_stage_snaps( ) == expected_arch[f"expected_{target_arch}"]
def __init__(self, project_options: project.Project = None) -> None: if project_options is None: project_options = project.Project() self.build_snaps = set() # type: Set[str] self._project_options = project_options self.snapcraft_yaml_path = get_snapcraft_yaml() snapcraft_yaml = _snapcraft_yaml_load(self.snapcraft_yaml_path) self._validator = Validator(snapcraft_yaml) self._validator.validate() snapcraft_yaml = self._process_remote_parts(snapcraft_yaml) snapcraft_yaml = self._expand_filesets(snapcraft_yaml) # both confinement type and build quality are optionals _ensure_confinement_default(snapcraft_yaml, self._validator.schema) _ensure_grade_default(snapcraft_yaml, self._validator.schema) self.data = self._expand_env(snapcraft_yaml) # We need to set the ProjectInfo here because ProjectOptions is # created in the CLI. self._project_options.info = ProjectInfo(self.data) self._ensure_no_duplicate_app_aliases() grammar_processor = grammar_processing.GlobalGrammarProcessor( properties=self.data, project_options=project_options) self.build_tools = grammar_processor.get_build_packages() self.build_tools |= set(project_options.additional_build_packages) self.parts = PartsConfig(parts=self.data, project_options=self._project_options, validator=self._validator, build_snaps=self.build_snaps, build_tools=self.build_tools, snapcraft_yaml=self.snapcraft_yaml_path) if 'architectures' not in self.data: self.data['architectures'] = [self._project_options.deb_arch]
def __init__(self, project_options: project.Project = None) -> None: if project_options is None: project_options = project.Project() self.build_snaps = set() # type: Set[str] self._project_options = project_options self.snapcraft_yaml_path = get_snapcraft_yaml() snapcraft_yaml = _snapcraft_yaml_load(self.snapcraft_yaml_path) self.original_snapcraft_yaml = snapcraft_yaml.copy() self.validator = Validator(snapcraft_yaml) self.validator.validate() snapcraft_yaml = self._process_remote_parts(snapcraft_yaml) snapcraft_yaml = self._expand_filesets(snapcraft_yaml) # We need to set the ProjectInfo here because ProjectOptions is # created in the CLI. self._project_options.info = ProjectInfo(snapcraft_yaml) self.data = self._expand_env(snapcraft_yaml) self._ensure_no_duplicate_app_aliases() grammar_processor = grammar_processing.GlobalGrammarProcessor( properties=self.data, project=project_options) self.build_tools = grammar_processor.get_build_packages() self.build_tools |= set(project_options.additional_build_packages) self.parts = PartsConfig(parts=self.data, project_options=self._project_options, validator=self.validator, build_snaps=self.build_snaps, build_tools=self.build_tools, snapcraft_yaml=self.snapcraft_yaml_path) self.data['architectures'] = _process_architectures( self.data.get('architectures'), self._project_options.deb_arch)
def load_tests(loader, tests, ignore): if project.Project().deb_arch == "amd64": tests.addTests(doctest.DocTestSuite(processor)) return tests