def test_clean_prime_state_common_files(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) self.assertThat(self.handler.next_step(), Equals(steps.PULL)) bindir = os.path.join(self.prime_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.STAGE) self.handler.mark_done(steps.PRIME, states.PrimeState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_prime( {"other_part": states.PrimeState({"bin/2"}, {"bin"})}) self.assertThat(self.handler.latest_step(), Equals(steps.STAGE)) self.assertThat(self.handler.next_step(), Equals(steps.PRIME)) 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_prime_state(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) self.assertThat(self.handler.next_step(), Equals(steps.PULL)) bindir = os.path.join(self.prime_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.STAGE) self.handler.mark_done(steps.PRIME, states.PrimeState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_prime({}) self.assertThat(self.handler.latest_step(), Equals(steps.STAGE)) self.assertThat(self.handler.next_step(), Equals(steps.PRIME)) self.assertFalse(os.path.exists(bindir))
def test_clean_prime_state_inconsistent_files(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) self.assertThat(self.handler.next_step(), Equals(steps.PULL)) self.handler.mark_done(steps.STAGE) self.handler.mark_done( steps.PRIME, states.PrimeState({"bin/1", "bin/2"}, {"bin", "not-there"})) # Only create a subset of the files and directories that were marked as primed bindir = os.path.join(self.prime_dir, "bin") os.makedirs(bindir) open(os.path.join(bindir, "1"), "w").close() self.handler.clean_prime({}) self.assertThat(self.handler.latest_step(), Equals(steps.STAGE)) self.assertThat(self.handler.next_step(), Equals(steps.PRIME)) self.assertFalse(os.path.exists(bindir))
def test_clean_prime_state_multiple_parts(self): self.assertRaises(errors.NoLatestStepError, self.handler.latest_step) self.assertThat(self.handler.next_step(), Equals(steps.PULL)) bindir = os.path.join(self.prime_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.STAGE) self.handler.mark_done(steps.PRIME, states.PrimeState({"bin/1", "bin/2"}, {"bin"})) self.handler.clean_prime({}) self.assertThat(self.handler.latest_step(), Equals(steps.STAGE)) self.assertThat(self.handler.next_step(), Equals(steps.PRIME)) 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 primed by this part", )
def prime_state_variant(request): """Return variants of prime_state.""" project, files, directories, dependency_paths, part_properties = request.param return states.PrimeState(files, directories, dependency_paths, part_properties, project)
def prime_state(): """Return a PrimeState.""" project, files, directories, dependency_paths, part_properties = _PRIME_DEFAULT return states.PrimeState(files, directories, dependency_paths, part_properties, project)