def test_partial_clean(self): parts = self.make_snapcraft_yaml(n=3) clean.main(['clean0', 'clean2']) for i in [0, 2]: self.assertFalse( os.path.exists(parts[i]['part_dir']), 'Expected for {!r} to be wiped'.format(parts[i]['part_dir'])) self.assertTrue(os.path.exists(parts[1]['part_dir']), 'Expected a part directory for the clean1 part') self.assertTrue(os.path.exists(common.get_partsdir())) self.assertTrue(os.path.exists(common.get_stagedir())) self.assertTrue(os.path.exists(common.get_snapdir())) # Now clean it the rest of the way clean.main(['clean1']) for i in range(0, 3): self.assertFalse( os.path.exists(parts[i]['part_dir']), 'Expected for {!r} to be wiped'.format(parts[i]['part_dir'])) self.assertFalse(os.path.exists(common.get_partsdir())) self.assertFalse(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir()))
def test_clean_all_when_all_parts_specified(self): self.make_snapcraft_yaml(n=3) clean.main(['clean0', 'clean1', 'clean2']) self.assertFalse(os.path.exists(common.get_partsdir())) self.assertFalse(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir()))
def test_clean_all(self): self.make_snapcraft_yaml(n=3) clean.main() self.assertFalse(os.path.exists(common.get_partsdir())) self.assertFalse(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir()))
def test_part_to_remove_not_defined_exits_with_error(self): self.make_snapcraft_yaml(n=3) with self.assertRaises(EnvironmentError) as raised: clean.main(['no-clean', ]) self.assertEqual( raised.exception.__str__(), "The part named 'no-clean' is not defined in 'snapcraft.yaml'")
def test_clean_nested_dependent_parts(self): yaml = """name: clean-test version: 1.0 summary: test clean description: test clean parts: main: plugin: nil source: . dependent: plugin: nil source: . after: [main] dependent-dependent: plugin: nil source: . after: [dependent]""" super().make_snapcraft_yaml(yaml) part_dirs = {} for part in ['main', 'dependent', 'dependent-dependent']: part_dirs[part] = os.path.join(common.get_partsdir(), part) os.makedirs(part_dirs[part]) os.makedirs(common.get_stagedir()) os.makedirs(common.get_snapdir()) # Cleaning only `main`. Since `dependent` depends upon main, we expect # that it will be cleaned as well. Otherwise it won't be using the new # `main` when it is built. clean.main(['main']) self.assertFalse(os.path.exists(part_dirs['main']), 'Expected part directory for main to be cleaned') self.assertFalse( os.path.exists(part_dirs['dependent']), 'Expected part directory for dependent to be cleaned as it ' 'depends upon main') self.assertFalse( os.path.exists(part_dirs['dependent-dependent']), 'Expected part directory for dependent-dependent to be cleaned as ' 'it depends upon dependent, which depends upon main') self.assertFalse(os.path.exists(common.get_partsdir())) self.assertFalse(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir()))
def test_per_step_cleaning(self, mock_clean): self.make_snapcraft_yaml(n=3) clean.main(['--step=foo']) expected_staged_state = { 'clean0': pluginhandler.StageState({'clean0'}, set()), 'clean1': pluginhandler.StageState({'clean1'}, set()), 'clean2': pluginhandler.StageState({'clean2'}, set()), } expected_stripped_state = { 'clean0': pluginhandler.StripState({'clean0'}, set()), 'clean1': pluginhandler.StripState({'clean1'}, set()), 'clean2': pluginhandler.StripState({'clean2'}, set()), } mock_clean.assert_called_with( expected_staged_state, expected_stripped_state, 'foo')
def test_partial_clean(self): parts = self.make_snapcraft_yaml(n=3) clean.main(['clean0', 'clean2', ]) for i in [0, 2]: self.assertFalse( os.path.exists(parts[i]['part_dir']), 'Expected for {!r} to be wiped'.format(parts[i]['part_dir'])) self.assertFalse( os.path.exists(parts[i]['state_file']), 'Expected for {!r} to be wiped'.format(parts[i]['state_file'])) self.assertTrue(os.path.exists(parts[1]['part_dir']), 'Expected a part directory for the clean1 part') self.assertTrue(os.path.exists(parts[1]['state_file']), 'Expected a state file for the clean1 part') self.assertTrue(os.path.exists(common.get_partsdir())) self.assertTrue(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir()))
def test_everything_is_clean(self): """Don't crash if everything is already clean.""" self.make_snapcraft_yaml(n=3, create=False) clean.main()