def setUp(self): super().setUp() temp_cwd_fixture = fixture_setup.TempCWD() self.useFixture(temp_cwd_fixture) self.path = temp_cwd_fixture.path self.useFixture(fixture_setup.TempXDG(self.path)) # Some tests will directly or indirectly change the plugindir, which # is a module variable. Make sure that it is returned to the original # value when a test ends. self.addCleanup(common.set_plugindir, common.get_plugindir()) self.addCleanup(common.set_schemadir, common.get_schemadir()) self.addCleanup(common.set_librariesdir, common.get_librariesdir()) self.addCleanup(common.set_tourdir, common.get_tourdir()) self.addCleanup(common.reset_env) common.set_schemadir(os.path.join(__file__, '..', '..', '..', 'schema')) self.useFixture(fixtures.FakeLogger(level=logging.ERROR)) self.useFixture(fixture_setup.FakeParts()) patcher = mock.patch('multiprocessing.cpu_count') self.cpu_count = patcher.start() self.cpu_count.return_value = 2 self.addCleanup(patcher.stop) patcher = mock.patch('snapcraft.internal.indicators.ProgressBar', new=SilentProgressBar) patcher.start() self.addCleanup(patcher.stop) # These are what we expect by default self.snap_dir = os.path.join(os.getcwd(), 'prime') self.stage_dir = os.path.join(os.getcwd(), 'stage') self.parts_dir = os.path.join(os.getcwd(), 'parts') self.local_plugins_dir = os.path.join(self.parts_dir, 'plugins')
def test_config_composes_with_remote_parts(self, mock_loadPlugin): self.useFixture(fixture_setup.FakeParts()) self.make_snapcraft_yaml("""name: test version: "1" summary: test description: test confinement: strict parts: part1: stage-packages: [fswebcam] """) parts.update() project_loader.Config() mock_loadPlugin.assert_called_with('part1', 'go', { 'source': 'http://source.tar.gz', 'stage-packages': ['fswebcam'], 'stage': [], 'snap': []})
def test_config_uses_remote_part_from_after(self, mock_load): self.useFixture(fixture_setup.FakeParts()) self.make_snapcraft_yaml("""name: test version: "1" summary: test description: test confinement: strict parts: part1: after: - curl plugin: go stage-packages: [fswebcam] """) def load_effect(*args, **kwargs): mock_part = unittest.mock.Mock() mock_part.code.build_packages = [] mock_part.deps = [] mock_part.name = args[0] return mock_part mock_load.side_effect = load_effect project_options = snapcraft.ProjectOptions() parts.update() project_loader.Config(project_options) call1 = unittest.mock.call('part1', 'go', { 'stage': [], 'snap': [], 'stage-packages': ['fswebcam']}, project_options, self.part_schema) call2 = unittest.mock.call('curl', 'autotools', { 'source': 'http://curl.org'}, project_options, self.part_schema) mock_load.assert_has_calls([call1, call2])
def test_config_composes_with_a_non_existent_remote_part(self): self.useFixture(fixture_setup.FakeParts()) self.make_snapcraft_yaml("""name: test version: "1" summary: test description: test confinement: strict parts: non-existing-part: stage-packages: [fswebcam] """) parts.update() with self.assertRaises(parts.SnapcraftLogicError) as raised: project_loader.Config() self.assertEqual( str(raised.exception), '{!r} is missing the `plugin` entry and is not defined in the ' 'current remote parts cache, try to run `snapcraft update` ' 'to refresh'.format('non-existing-part'))
def test_changed_parts_uri(self): result = self.run_command(['update']) self.assertThat(result.exit_code, Equals(0)) self.useFixture(fixture_setup.FakeParts()) self.useFixture(fixtures.EnvironmentVariable('CUSTOM_PARTS', '1')) self.parts_dir = self._parts_dir() self.parts_yaml = os.path.join(self.parts_dir, 'parts.yaml') result = self.run_command(['update']) self.assertThat(result.exit_code, Equals(0)) expected_parts = OrderedDict() expected_parts['curl-custom'] = p = OrderedDict() p['plugin'] = 'autotools' p['source'] = 'http://curl.org' p['description'] = 'custom curl part' p['maintainer'] = 'none' with open(self.parts_yaml) as parts_file: parts = yaml.load(parts_file) self.assertThat(parts, Equals(expected_parts))
def test_config_after_is_an_undefined_part(self): self.useFixture(fixture_setup.FakeParts()) self.make_snapcraft_yaml("""name: test version: "1" summary: test description: test confinement: strict parts: part1: plugin: nil after: [non-existing-part] """) parts.update() with self.assertRaises(parts.SnapcraftLogicError) as raised: project_loader.Config() self.assertEqual( str(raised.exception), 'Cannot find definition for part {!r}. It may be a ' 'remote part, run `snapcraft update` to ' 'refresh the remote parts cache'.format('non-existing-part'))
def setUp(self): super().setUp() self.useFixture(fixture_setup.FakeParts())