def test_cleaning_with_strip_does_prime_and_warns(self, mock_clean): fake_logger = fixtures.FakeLogger(level=logging.WARNING) self.useFixture(fake_logger) self.make_snapcraft_yaml(n=3) main(['clean', '--step=strip']) expected_staged_state = { 'clean0': states.StageState({'clean0'}, set()), 'clean1': states.StageState({'clean1'}, set()), 'clean2': states.StageState({'clean2'}, set()), } expected_primed_state = { 'clean0': states.PrimeState({'clean0'}, set()), 'clean1': states.PrimeState({'clean1'}, set()), 'clean2': states.PrimeState({'clean2'}, set()), } self.assertEqual( 'DEPRECATED: Use `prime` instead of `strip` as ' 'the step to clean\n', fake_logger.output) mock_clean.assert_called_with(expected_staged_state, expected_primed_state, 'prime')
def stage(self, force=False): self.makedirs() self.notify_part_progress('Staging') self._organize() snap_files, snap_dirs = self.migratable_fileset_for('stage') def fixup_func(file_path): if os.path.islink(file_path): return if not file_path.endswith('.pc'): return repo.fix_pkg_config(self.stagedir, file_path, self.code.installdir) _migrate_files(snap_files, snap_dirs, self.code.installdir, self.stagedir, fixup_func=fixup_func) # TODO once `snappy try` is in place we will need to copy # dependencies here too self.mark_done( 'stage', states.StageState(snap_files, snap_dirs, self.code.options, self._project_options))
def test_per_step_cleaning(self, mock_clean): self.make_snapcraft_yaml(n=3) main(['clean', '--step=foo']) expected_staged_state = { 'clean0': states.StageState({'clean0'}, set()), 'clean1': states.StageState({'clean1'}, set()), 'clean2': states.StageState({'clean2'}, set()), } expected_primed_state = { 'clean0': states.PrimeState({'clean0'}, set()), 'clean1': states.PrimeState({'clean1'}, set()), 'clean2': states.PrimeState({'clean2'}, set()), } mock_clean.assert_called_with(expected_staged_state, expected_primed_state, 'foo')
def mark_stage_done(self, snap_files, snap_dirs): self.mark_done( steps.STAGE, states.StageState( snap_files, snap_dirs, self._part_properties, self._project_options, self._scriptlet_metadata[steps.STAGE], ), )
def stage(self, force=False): self.makedirs() self.notify_part_progress('Staging') self._organize() snap_files, snap_dirs = self.migratable_fileset_for('stage') _migrate_files(snap_files, snap_dirs, self.code.installdir, self.stagedir) # TODO once `snappy try` is in place we will need to copy # dependencies here too self.mark_done('stage', states.StageState( snap_files, snap_dirs, self.code.options, self._project_options))
def test_clean_stage_state_common_files(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) bindir = os.path.join(self.stage_dir, "bin") os.makedirs(bindir) open(os.path.join(bindir, "1"), "w").close() open(os.path.join(bindir, "2"), "w").close() self.handler.mark_done(steps.BUILD) self.handler.mark_done(steps.STAGE, states.StageState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_stage( {"other_part": states.StageState({"bin/2"}, {"bin"})}) self.assertThat(self.handler.latest_step(), Equals(steps.BUILD)) self.assertThat(self.handler.next_step(), Equals(steps.STAGE)) self.assertFalse(os.path.exists(os.path.join(bindir, "1"))) self.assertTrue( os.path.exists(os.path.join(bindir, "2")), "Expected 'bin/2' to remain as it's required by other parts", )
def test_clean_stage_state(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) self.assertThat(self.handler.next_step(), Equals(steps.PULL)) bindir = os.path.join(self.stage_dir, "bin") os.makedirs(bindir) open(os.path.join(bindir, "1"), "w").close() open(os.path.join(bindir, "2"), "w").close() self.handler.mark_done(steps.BUILD) self.handler.mark_done(steps.STAGE, states.StageState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_stage({}) self.assertThat(self.handler.latest_step(), Equals(steps.BUILD)) self.assertThat(self.handler.next_step(), Equals(steps.STAGE)) self.assertFalse(os.path.exists(bindir))
def test_clean_stage_state_multiple_parts(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) bindir = os.path.join(self.stage_dir, "bin") os.makedirs(bindir) open(os.path.join(bindir, "1"), "w").close() open(os.path.join(bindir, "2"), "w").close() open(os.path.join(bindir, "3"), "w").close() self.handler.mark_done(steps.BUILD) self.handler.mark_done(steps.STAGE, states.StageState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_stage({}) self.assertThat(self.handler.latest_step(), Equals(steps.BUILD)) self.assertThat(self.handler.next_step(), Equals(steps.STAGE)) self.assertFalse(os.path.exists(os.path.join(bindir, "1"))) self.assertFalse(os.path.exists(os.path.join(bindir, "2"))) self.assertTrue( os.path.exists(os.path.join(bindir, "3")), "Expected 'bin/3' to remain as it wasn't staged by this part", )
def mark_stage_done(self, snap_files, snap_dirs): self.mark_done( 'stage', states.StageState(snap_files, snap_dirs, self._part_properties, self._project_options))
def mark_stage_done(self, snap_files, snap_dirs): self.mark_done( 'stage', states.StageState(snap_files, snap_dirs, self._part_properties, self._project_options, self._scriptlet_metadata['stage']))
def stage_state(): """Return a StageState.""" project, files, directories, part_properties = _STAGE_DEFAULT return states.StageState(files, directories, part_properties, project)
def stage_state_variant(request): """Return variants of stage_state.""" project, files, directories, part_properties = request.param return states.StageState(files, directories, part_properties, project)