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 | |
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...
-rw-r--r-- | becommands/assign.py | 3 | ||||
-rw-r--r-- | becommands/close.py | 3 | ||||
-rw-r--r-- | becommands/comment.py | 3 | ||||
-rw-r--r-- | becommands/commit.py | 3 | ||||
-rw-r--r-- | becommands/depend.py | 3 | ||||
-rw-r--r-- | becommands/diff.py | 3 | ||||
-rw-r--r-- | becommands/list.py | 3 | ||||
-rw-r--r-- | becommands/merge.py | 3 | ||||
-rw-r--r-- | becommands/new.py | 5 | ||||
-rw-r--r-- | becommands/open.py | 3 | ||||
-rw-r--r-- | becommands/remove.py | 3 | ||||
-rw-r--r-- | becommands/set.py | 3 | ||||
-rw-r--r-- | becommands/severity.py | 3 | ||||
-rw-r--r-- | becommands/show.py | 3 | ||||
-rw-r--r-- | becommands/status.py | 3 | ||||
-rw-r--r-- | becommands/subscribe.py | 6 | ||||
-rw-r--r-- | becommands/tag.py | 3 | ||||
-rw-r--r-- | becommands/target.py | 3 | ||||
-rw-r--r-- | libbe/arch.py | 6 | ||||
-rw-r--r-- | libbe/bugdir.py | 81 | ||||
-rw-r--r-- | libbe/diff.py | 3 |
21 files changed, 93 insertions, 56 deletions
diff --git a/becommands/assign.py b/becommands/assign.py index 7b32bdd..794f028 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -23,7 +23,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> bd.bug_from_shortname("a").assigned is None True @@ -42,6 +42,7 @@ def execute(args, manipulate_encodings=True): >>> bd._clear_bugs() >>> bd.bug_from_shortname("a").assigned is None True + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/close.py b/becommands/close.py index 12848b2..0532ed2 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -24,7 +24,7 @@ def execute(args, manipulate_encodings=True): """ >>> from libbe import bugdir >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("a").status open @@ -32,6 +32,7 @@ def execute(args, manipulate_encodings=True): >>> bd._clear_bugs() >>> print bd.bug_from_shortname("a").status closed + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/comment.py b/becommands/comment.py index 14872a3..69e3a41 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -28,7 +28,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import time - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["a", "This is a comment about a"], manipulate_encodings=False) >>> bd._clear_bugs() @@ -60,6 +60,7 @@ def execute(args, manipulate_encodings=True): >>> print comment.body I like cheese <BLANKLINE> + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/commit.py b/becommands/commit.py index 4f3bdbd..fb85651 100644 --- a/becommands/commit.py +++ b/becommands/commit.py @@ -22,13 +22,14 @@ def execute(args, manipulate_encodings=True): """ >>> import os, time >>> from libbe import bug - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> full_path = "testfile" >>> test_contents = "A test file" >>> bd.rcs.set_file_contents(full_path, test_contents) >>> execute(["Added %s." % (full_path)], manipulate_encodings=False) # doctest: +ELLIPSIS Committed ... + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/depend.py b/becommands/depend.py index fd38bd1..3d63e2f 100644 --- a/becommands/depend.py +++ b/becommands/depend.py @@ -21,7 +21,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> from libbe import utility - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> bd.save() >>> os.chdir(bd.root) >>> execute(["a", "b"], manipulate_encodings=False) @@ -34,6 +34,7 @@ def execute(args, manipulate_encodings=True): Blocks on a: b closed >>> execute(["-r", "a", "b"], manipulate_encodings=False) + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/diff.py b/becommands/diff.py index 1ab2135..034823d 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -23,7 +23,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> bd.set_sync_with_disk(True) >>> original = bd.rcs.commit("Original status") >>> bug = bd.bug_from_uuid("a") @@ -48,6 +48,7 @@ def execute(args, manipulate_encodings=True): ... else: ... print "This directory is not revision-controlled." This directory is not revision-controlled. + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/list.py b/becommands/list.py index 50038e6..12e1e29 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -29,13 +29,14 @@ AVAILABLE_CMPS.remove("attr") # a cmp_* template. def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute([], manipulate_encodings=False) a:om: Bug A >>> execute(["--status", "all"], manipulate_encodings=False) a:om: Bug A b:cm: Bug B + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/merge.py b/becommands/merge.py index 6651869..f212b01 100644 --- a/becommands/merge.py +++ b/becommands/merge.py @@ -21,7 +21,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> from libbe import utility - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> bd.set_sync_with_disk(True) >>> a = bd.bug_from_shortname("a") >>> a.comment_root.time = 0 @@ -120,6 +120,7 @@ def execute(args, manipulate_encodings=True): Merged into bug a >>> print b.status closed + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/new.py b/becommands/new.py index 2487bac..1900c7a 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -23,12 +23,12 @@ def execute(args, manipulate_encodings=True): """ >>> import os, time >>> from libbe import bug - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> bug.uuid_gen = lambda: "X" >>> execute (["this is a test",], manipulate_encodings=False) Created bug with ID X - >>> bd.load() + >>> bd.load() # breaks simple bug dir rcs for cleanup! >>> bug = bd.bug_from_uuid("X") >>> print bug.summary this is a test @@ -38,6 +38,7 @@ def execute(args, manipulate_encodings=True): minor >>> bug.target == None True + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/open.py b/becommands/open.py index bfb54ea..0c6bf05 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -23,7 +23,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("b").status closed @@ -31,6 +31,7 @@ def execute(args, manipulate_encodings=True): >>> bd._clear_bugs() >>> print bd.bug_from_shortname("b").status open + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/remove.py b/becommands/remove.py index bc7b5ed..8d85033 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -21,7 +21,7 @@ def execute(args, manipulate_encodings=True): """ >>> from libbe import mapfile >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("b").status closed @@ -33,6 +33,7 @@ def execute(args, manipulate_encodings=True): ... except bugdir.NoBugMatches: ... print "Bug not found" Bug not found + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/set.py b/becommands/set.py index f7fca54..e78a1ea 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -35,7 +35,7 @@ def _value_string(bd, setting): def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["target"], manipulate_encodings=False) None @@ -45,6 +45,7 @@ def execute(args, manipulate_encodings=True): >>> execute(["target", "none"], manipulate_encodings=False) >>> execute(["target"], manipulate_encodings=False) None + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/severity.py b/becommands/severity.py index a14a96b..660586e 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -23,7 +23,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["a"], manipulate_encodings=False) minor @@ -33,6 +33,7 @@ def execute(args, manipulate_encodings=True): >>> execute(["a", "none"], manipulate_encodings=False) Traceback (most recent call last): UserError: Invalid severity level: none + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/show.py b/becommands/show.py index bb16fe5..50bd6eb 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -25,7 +25,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute (["a",], manipulate_encodings=False) # doctest: +ELLIPSIS ID : a @@ -50,6 +50,7 @@ def execute(args, manipulate_encodings=True): <created>...</created> <summary>Bug A</summary> </bug> + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/status.py b/becommands/status.py index e4db787..f315003 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -20,7 +20,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["a"], manipulate_encodings=False) open @@ -30,6 +30,7 @@ def execute(args, manipulate_encodings=True): >>> execute(["a", "none"], manipulate_encodings=False) Traceback (most recent call last): UserError: Invalid status: none + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/subscribe.py b/becommands/subscribe.py index 64a2867..b754937 100644 --- a/becommands/subscribe.py +++ b/becommands/subscribe.py @@ -57,7 +57,7 @@ class InvalidType (ValueError): def execute(args, manipulate_encodings=True): """ - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> bd.set_sync_with_disk(True) >>> os.chdir(bd.root) >>> a = bd.bug_from_shortname("a") @@ -96,6 +96,7 @@ def execute(args, manipulate_encodings=True): >>> execute(["-s","Jane Doe <J@doe.com>", "DIR"], manipulate_encodings=False) # doctest: +NORMALIZE_WHITESPACE Subscriptions for bug directory: Jane Doe <J@doe.com> all * + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) @@ -337,7 +338,7 @@ def get_bugdir_subscribers(bugdir, server): where id is either a bug.uuid (in the case of a bug subscription) or "DIR" (in the case of a bugdir subscription). - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir(sync_with_disk=False) >>> a = bd.bug_from_shortname("a") >>> bd.extra_strings = subscribe(bd.extra_strings, "John Doe <j@doe.com>", [BUGDIR_TYPE_ALL], ["a.com"], BUGDIR_TYPE_ALL) >>> bd.extra_strings = subscribe(bd.extra_strings, "Jane Doe <J@doe.com>", [BUGDIR_TYPE_NEW], ["*"], BUGDIR_TYPE_ALL) @@ -351,6 +352,7 @@ def get_bugdir_subscribers(bugdir, server): [<SubscriptionType: all>] >>> get_bugdir_subscribers(bd, "b.net") {'Jane Doe <J@doe.com>': {'DIR': [<SubscriptionType: new>]}} + >>> bd.cleanup() """ subscribers = {} for sub in get_subscribers(bugdir.extra_strings, BUGDIR_TYPE_ALL, server, diff --git a/becommands/tag.py b/becommands/tag.py index e749a31..ecd853f 100644 --- a/becommands/tag.py +++ b/becommands/tag.py @@ -21,7 +21,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> from libbe import utility - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> bd.set_sync_with_disk(True) >>> os.chdir(bd.root) >>> a = bd.bug_from_shortname("a") @@ -66,6 +66,7 @@ def execute(args, manipulate_encodings=True): Tags for a: Alphabetically first >>> execute(["--remove", "a", "Alphabetically first"], manipulate_encodings=False) + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) diff --git a/becommands/target.py b/becommands/target.py index 5d0453a..7e41451 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -25,7 +25,7 @@ __desc__ = __doc__ def execute(args, manipulate_encodings=True): """ >>> import os - >>> bd = bugdir.simple_bug_dir() + >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["a"], manipulate_encodings=False) No target assigned. @@ -37,6 +37,7 @@ def execute(args, manipulate_encodings=True): >>> execute(["a", "none"], manipulate_encodings=False) >>> execute(["a"], manipulate_encodings=False) No target assigned. + >>> bd.cleanup() """ parser = get_parser() options, args = parser.parse_args(args) 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 |