def setUp(self): super().setUp() # Use "clean" step for testing provider handling. self.step = "clean" # Don't actually run clean - we only want to test the command # line interface flag parsing. self.useFixture( fixtures.MockPatch("snapcraft_legacy.internal.lifecycle.clean")) # tests.legacy.unit.TestCase sets SNAPCRAFT_BUILD_ENVIRONMENT to host. # These build provider tests will want to set this explicitly. self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT", None)) self.mock_get_provider_for = self.useFixture( fixtures.MockPatch( "snapcraft_legacy.internal.build_providers.get_provider_for", return_value=ProviderImpl, )).mock # Tests need to dictate this (or not). self.useFixture( fixtures.MockPatch( "snapcraft_legacy.internal.common.is_process_container", return_value=False, )) self.useFixture(fixture_setup.FakeMultipass()) snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, base="core20") snapcraft_yaml.update_part("part1", dict(plugin="nil")) self.useFixture(snapcraft_yaml)
def test_validation_passes(self): snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, base="core20") snapcraft_yaml.update_part("part1", dict(plugin="nil")) self.useFixture(snapcraft_yaml) result = self.run_command(["pull"]) self.assertThat(result.exit_code, Equals(0))
def make_snapcraft_project(self, parts): snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path) snapcraft_yaml.update_part("part1", dict(plugin="nil")) for part_name, part in parts: snapcraft_yaml.update_part(part_name, part) self.useFixture(snapcraft_yaml) project = Project( snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) return project_loader.load_config(project)
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_snap_packaging(self, **yaml_args): if "parts" not in yaml_args: yaml_args["parts"] = dict(part1=dict(plugin="nil")) snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, **yaml_args) self.useFixture(snapcraft_yaml) project = Project( snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) config = load_config(project) return _SnapPackaging(project_config=config, extracted_metadata=None)
def test_validation_fails(self): snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, name="name with spaces", base="core20") snapcraft_yaml.update_part("part1", dict(plugin="nil")) self.useFixture(snapcraft_yaml) self.assertRaises( snapcraft_legacy.yaml_utils.errors.YamlValidationError, self.run_command, ["pull"], )
def test_non_prime_and_no_version(self): snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, version=None) snapcraft_yaml.data["adopt-info"] = "test-part" snapcraft_yaml.update_part( "test-part", { "plugin": "nil", "override-build": "snapcraftctl set-version 1.0" }, ) self.useFixture(snapcraft_yaml) project = Project( snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) project_config = project_loader.load_config(project) # This should not fail lifecycle.execute(steps.PULL, project_config)
def setUp(self): super().setUp() self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT")) self.fake_lifecycle_clean = fixtures.MockPatch( "snapcraft_legacy.internal.lifecycle.clean") self.useFixture(self.fake_lifecycle_clean) self.fake_lifecycle_execute = fixtures.MockPatch( "snapcraft_legacy.internal.lifecycle.execute") self.useFixture(self.fake_lifecycle_execute) self.fake_pack = fixtures.MockPatch( "snapcraft_legacy.cli.lifecycle._pack") self.useFixture(self.fake_pack) self.snapcraft_yaml = fixture_setup.SnapcraftYaml( self.path, parts={ "part0": { "plugin": "nil" }, "part1": { "plugin": "nil" }, "part2": { "plugin": "nil" }, }, ) self.useFixture(self.snapcraft_yaml) self.provider_class_mock = mock.MagicMock() self.provider_mock = mock.MagicMock() self.provider_class_mock.return_value.__enter__.return_value = ( self.provider_mock) self.fake_get_provider_for = fixtures.MockPatch( "snapcraft_legacy.internal.build_providers.get_provider_for", return_value=self.provider_class_mock, ) self.useFixture(self.fake_get_provider_for)
def setUp(self): super().setUp() self._source = self.useFixture(TestDir()) self._source.create_file("foo") self._source.create_file("bar") self._source.create_dir("dir") self._source.create_file("dir", "baz") self._source.create_dir("empty_dir") self._dest = self.useFixture(TestDir()) self._snapcraft_yaml = fixture_setup.SnapcraftYaml(self._source.path) self._snapcraft_yaml.update_part("my-part", { "plugin": "nil", "source": self._source.path }) self.useFixture(self._snapcraft_yaml) self.load_project_and_worktree()
def test_print_module_help_for_valid_plugin_snapcraft_yaml(self): self.useFixture( fixture_setup.SnapcraftYaml( self.path, base="core18", parts={"part1": { "source": ".", "plugin": "nil" }}, )) result = self.run_command(["help", "python", "--base", "core18"]) expected = ("Displaying help for the 'python' plugin for 'core18'.\n\n" "The python plugin can be used for") output = result.output[:len(expected)] self.assertThat( output, Equals(expected), "The help message does not start with {!r} but with " "{!r} instead".format(expected, output), )
def setUp(self): super().setUp() self.snapcraft_yaml = fixture_setup.SnapcraftYaml( self.path, parts={"part0": { "plugin": "nil" }}, ) self.useFixture(self.snapcraft_yaml) self.mock_lc_init = self.useFixture( fixtures.MockPatch("snapcraft_legacy.cli.remote.LaunchpadClient", autospec=True)).mock self.mock_lc = self.mock_lc_init.return_value self.mock_lc_architectures = mock.PropertyMock(return_value=["i386"]) type(self.mock_lc).architectures = self.mock_lc_architectures self.mock_lc.has_outstanding_build.return_value = False self.mock_project = self.useFixture( fixtures.MockPatchObject( snapcraft_legacy.project.Project, "_get_project_directory_hash", return_value="fakehash123", ))
def setUp(self): super().setUp() self.useFixture(fixtures.FakeLogger(level=logging.ERROR)) temp_cwd = fixture_setup.TempCWD() self.useFixture(temp_cwd) snapcraft_yaml = fixture_setup.SnapcraftYaml( temp_cwd.path, base="core18", parts={"test-part": { "plugin": "nil" }}) self.useFixture(snapcraft_yaml) project = Project( snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) self.global_state_filepath = project._get_global_state_file_path() self.project_config = project_loader.load_config(project) self.useFixture( fixtures.MockPatchObject(self.project_config, "get_build_snaps", return_value={"core18"})) self.useFixture( fixtures.MockPatch( "snapcraft_legacy.internal.lifecycle._runner._Executor.run")) self.useFixture( fixtures.MockPatch( "snapcraft_legacy.internal.repo.snaps.install_snaps")) # Avoid unnecessary calls to info. channel_map = [] for arch in ("amd64", "i386", "s390x", "arm64", "armhf", "ppc64el"): channel_map.append({ "channel": { "architecture": arch, "name": "stable", "released-at": "2019-10-15T13:54:06.800280+00:00", "risk": "stable", "track": "latest", }, "confinement": "strict", "download": { "deltas": [], "sha3-384": "64d232d6bfa65be14d7f8d84e952d4e372e12021e2c3dbaf70cf2af5e78bf51c4baf9c9107dd6db815064636b781bda6", "size": 57151488, "url": "https://api.snapcraft.io/api/v1/snaps/download/CSO04Jhav2yK0uz97cr0ipQRyqg0qQL6_1223.snap", }, "revision": 1223, }) info = { "channel-map": channel_map, "default-track": None, "name": "core18", "snap": { "name": "core18", "publisher": { "display-name": "Canonical", "id": "canonical", "username": "******", "validation": "verified", }, "snap-id": "CSO04Jhav2yK0uz97cr0ipQRyqg0qQL6", }, "snap-id": "CSO04Jhav2yK0uz97cr0ipQRyqg0qQL6", } self.fake_storeapi_get_info = fixtures.MockPatch( "snapcraft_legacy.storeapi._snap_api.SnapAPI.get_info", return_value=SnapInfo(info), ) self.useFixture(self.fake_storeapi_get_info)