diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-31 14:59:06 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-31 14:59:06 -0400 |
commit | 58cba607535cd33c97fd5dc3737c9da4afa9a6bb (patch) | |
tree | 7f5cfec092fe27735bf1228fb124601a920fc85f /libbe | |
parent | 3c4ce1b4519186007f2568569b1bff55cdbb108f (diff) | |
download | bugseverywhere-58cba607535cd33c97fd5dc3737c9da4afa9a6bb.tar.gz |
Improved unittest cleanup by adding BugDir.cleanup().
Also simple_bug_dir -> SimpleBugDir class, which allows me to add
utility.Dir cleanup to SimpleBugDir.cleanup().
Still having a bit of trouble with the becommand.new tests due to
bugdir loading though...
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/arch.py | 6 | ||||
-rw-r--r-- | libbe/bugdir.py | 81 | ||||
-rw-r--r-- | libbe/diff.py | 3 |
3 files changed, 54 insertions, 36 deletions
diff --git a/libbe/arch.py b/libbe/arch.py index 1bdc8ae..63e39e3 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -62,7 +62,11 @@ class Arch(RCS): self._create_project(path) self._add_project_code(path) def _create_archive(self, path): - # Create a new archive + """ + Create a temporary Arch archive in the directory PATH. This + archive will be removed by + __del__->cleanup->_rcs_cleanup->_remove_archive + """ # http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive assert self._archive_name == None id = self.get_user_id() diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 0bcf27e..0eb4a6c 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -321,6 +321,12 @@ settings easy. Don't set this attribute. Set .rcs instead, and self.rcs = rcs self._setup_user_id(self.user_id) + def __del__(self): + self.cleanup() + + def cleanup(self): + self.rcs.cleanup() + # methods for getting the BugDir situated in the filesystem def _find_root(self, path): @@ -585,12 +591,13 @@ settings easy. Don't set this attribute. Set .rcs instead, and def bug_from_shortname(self, shortname): """ - >>> bd = simple_bug_dir(sync_with_disk=False) + >>> bd = SimpleBugDir(sync_with_disk=False) >>> bug_a = bd.bug_from_shortname('a') >>> print type(bug_a) <class 'libbe.bug.Bug'> >>> print bug_a a:om: Bug A + >>> bd.cleanup() """ matches = [] self._bug_map_gen() @@ -619,43 +626,47 @@ settings easy. Don't set this attribute. Set .rcs instead, and return True -def simple_bug_dir(sync_with_disk=True): +class SimpleBugDir (BugDir): """ For testing. Set sync_with_disk==False for a memory-only bugdir. - >>> bugdir = simple_bug_dir() + >>> bugdir = SimpleBugDir() >>> uuids = list(bugdir.list_uuids()) >>> uuids.sort() >>> print uuids ['a', 'b'] + >>> bugdir.cleanup() """ - if sync_with_disk == True: - dir = utility.Dir() - assert os.path.exists(dir.path) - root = dir.path - assert_new_BugDir = True - rcs_init = True - else: - root = "/" - assert_new_BugDir = False - rcs_init = False - bugdir = BugDir(root, sink_to_existing_root=False, + def __init__(self, sync_with_disk=True): + if sync_with_disk == True: + dir = utility.Dir() + assert os.path.exists(dir.path) + root = dir.path + assert_new_BugDir = True + rcs_init = True + else: + root = "/" + assert_new_BugDir = False + rcs_init = False + BugDir.__init__(self, root, sink_to_existing_root=False, assert_new_BugDir=assert_new_BugDir, allow_rcs_init=rcs_init, manipulate_encodings=False) - if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir. - bugdir._dir_ref = dir - bug_a = bugdir.new_bug("a", summary="Bug A") - bug_a.creator = "John Doe <jdoe@example.com>" - bug_a.time = 0 - bug_b = bugdir.new_bug("b", summary="Bug B") - bug_b.creator = "Jane Doe <jdoe@example.com>" - bug_b.time = 0 - bug_b.status = "closed" - if sync_with_disk == True: - bugdir.save() - bugdir.set_sync_with_disk(True) - return bugdir - + if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir. + self._dir_ref = dir + bug_a = self.new_bug("a", summary="Bug A") + bug_a.creator = "John Doe <jdoe@example.com>" + bug_a.time = 0 + bug_b = self.new_bug("b", summary="Bug B") + bug_b.creator = "Jane Doe <jdoe@example.com>" + bug_b.time = 0 + bug_b.status = "closed" + if sync_with_disk == True: + self.save() + self.set_sync_with_disk(True) + def cleanup(self): + if hasattr(self, "_dir_ref"): + self._dir_ref.cleanup() + BugDir.cleanup(self) class BugDirTestCase(unittest.TestCase): def setUp(self): @@ -664,7 +675,7 @@ class BugDirTestCase(unittest.TestCase): allow_rcs_init=True) self.rcs = self.bugdir.rcs def tearDown(self): - self.rcs.cleanup() + self.bugdir.cleanup() self.dir.cleanup() def fullPath(self, path): return os.path.join(self.dir.path, path) @@ -768,10 +779,11 @@ class SimpleBugDirTestCase (unittest.TestCase): self.bugdir.save() def tearDown(self): os.chdir(self.original_working_dir) + self.bugdir.cleanup() self.dir.cleanup() def testOnDiskCleanLoad(self): - """simple_bug_dir(sync_with_disk==True) should not import preexisting bugs.""" - bugdir = simple_bug_dir(sync_with_disk=True) + """SimpleBugDir(sync_with_disk==True) should not import preexisting bugs.""" + bugdir = SimpleBugDir(sync_with_disk=True) self.failUnless(bugdir.sync_with_disk==True, bugdir.sync_with_disk) uuids = sorted([bug.uuid for bug in bugdir]) self.failUnless(uuids == ['a', 'b'], uuids) @@ -781,9 +793,10 @@ class SimpleBugDirTestCase (unittest.TestCase): bugdir.load_all_bugs() uuids = sorted([bug.uuid for bug in bugdir]) self.failUnless(uuids == ['a', 'b'], uuids) + bugdir.cleanup() def testInMemoryCleanLoad(self): - """simple_bug_dir(sync_with_disk==False) should not import preexisting bugs.""" - bugdir = simple_bug_dir(sync_with_disk=False) + """SimpleBugDir(sync_with_disk==False) should not import preexisting bugs.""" + bugdir = SimpleBugDir(sync_with_disk=False) self.failUnless(bugdir.sync_with_disk==False, bugdir.sync_with_disk) uuids = sorted([bug.uuid for bug in bugdir]) self.failUnless(uuids == ['a', 'b'], uuids) @@ -793,7 +806,7 @@ class SimpleBugDirTestCase (unittest.TestCase): bugdir._clear_bugs() uuids = sorted([bug.uuid for bug in bugdir]) self.failUnless(uuids == [], uuids) - + bugdir.cleanup() unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) diff --git a/libbe/diff.py b/libbe/diff.py index 459da4b..1b52620 100644 --- a/libbe/diff.py +++ b/libbe/diff.py @@ -136,7 +136,7 @@ class Diff (object): """ Difference tree generator for BugDirs. >>> import copy - >>> bd = bugdir.simple_bug_dir(sync_with_disk=False) + >>> bd = bugdir.SimpleBugDir(sync_with_disk=False) >>> bd.user_id = "John Doe <j@doe.com>" >>> bd_new = copy.deepcopy(bd) >>> bd_new.target = "1.0" @@ -180,6 +180,7 @@ class Diff (object): New comments: from John Doe <j@doe.com> on Thu, 01 Jan 1970 00:00:00 +0000 I'm closing this bug... + >>> bd.cleanup() """ def __init__(self, old_bugdir, new_bugdir): self.old_bugdir = old_bugdir |