Mercurial > treepkg
diff test/test_packager.py @ 91:3ed079a7174a
Implement a way to stop a running treepackager.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 11 Sep 2007 17:24:56 +0000 |
parents | 3ae54f99db26 |
children | 73c67372c7f7 |
line wrap: on
line diff
--- a/test/test_packager.py Tue Sep 11 13:58:28 2007 +0000 +++ b/test/test_packager.py Tue Sep 11 17:24:56 2007 +0000 @@ -131,6 +131,75 @@ ["testpkg_2-kk1_all.deb", "testpkg_2-kk1_i386.changes"]) +class StoppingPackager(treepkg.packager.RevisionPackager): + + def package(self): + pass + +class StoppingTrack(treepkg.packager.PackageTrack): + + def __init__(self, do_package, do_stop, instructions_file, name, trackdir): + super(StoppingTrack, self).__init__(name, trackdir, "", "", "", + "", "") + self.do_package = do_package + self.do_stop = do_stop + self.instructions_file = instructions_file + + def package_if_updated(self, revision): + if self.do_stop: + writefile(self.instructions_file, "stop") + if self.do_package: + return StoppingPackager(self, 1) + else: + return None + + +class TestPackageGroupStop(unittest.TestCase, FileTestMixin): + + def setUp(self): + self.trackdir = self.create_temp_dir(self.id() + "-track") + self.instructions_file = os.path.join(self.trackdir, "instructions") + + def group(self, do_package=True, do_stop=True): + return PackagerGroup([StoppingTrack(do_package, do_stop, + self.instructions_file, + "test", self.trackdir)], + 1, instructions_file=self.instructions_file) + + def test_stop(self): + group = self.group(do_package=True, do_stop=True) + self.failUnless(group.check_package_tracks()) + + def test_no_stop(self): + group = self.group(do_package=True, do_stop=False) + self.failIf(group.check_package_tracks()) + + def test_instruction_removal(self): + # run once with stopping + group = self.group(do_package=True, do_stop=True) + self.failUnless(group.check_package_tracks()) + + # run again without stopping but using the same files. The + # instructions file should be removed automatically + group = self.group(do_package=True, do_stop=False) + self.failIf(group.check_package_tracks()) + + def test_stopping_without_packaging(self): + group = self.group(do_package=False, do_stop=True) + self.failUnless(group.check_package_tracks()) + + def test_stopping_between_checks(self): + group = self.group(do_package=False, do_stop=False) + # run check_package_tracks once + self.failIf(group.check_package_tracks()) + + # tell treepkg to stop + writefile(self.instructions_file, "stop") + + # check again. The check_package_tracks() may remove the + # instructions file but it must do so only the first time + self.failUnless(group.check_package_tracks()) + class TestPackageTrack(unittest.TestCase, FileTestMixin):