diff options
author | John Doe <jdoe@example.com> | 2009-06-14 14:34:11 +1000 |
---|---|---|
committer | John Doe <jdoe@example.com> | 2009-06-14 14:34:11 +1000 |
commit | b0c7c274d394ccfba2ea84fa6e9785f41f4cddd8 (patch) | |
tree | 2fa7b24b86aa2151d62400afabf908bda72cd5bc /libbe/rcs.py | |
parent | a711ecf10df62e30d83c1941065404c53fecd35b (diff) | |
download | bugseverywhere-b0c7c274d394ccfba2ea84fa6e9785f41f4cddd8.tar.gz |
Make RCS testcase subclasses dynamically.
Diffstat (limited to 'libbe/rcs.py')
-rw-r--r-- | libbe/rcs.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libbe/rcs.py b/libbe/rcs.py index 3519c3d..ed5c7ee 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -546,8 +546,8 @@ class RCS(object): f.close return (summary, body) - -class RCStestCase(unittest.TestCase): + +class RCSTestCase(unittest.TestCase): Class = RCS def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) @@ -635,5 +635,23 @@ class RCStestCase(unittest.TestCase): self.versionTest('a/b/text') self.rcs.recursive_remove(self.fullPath('a')) -unitsuite = unittest.TestLoader().loadTestsFromTestCase(RCStestCase) + +def make_rcs_testcase_subclasses(rcs_class, namespace): + """ Make RCSTestCase subclasses for rcs_class in the namespace. """ + rcs_testcase_classes = [ + c for c in ( + ob for ob in globals().values() if isinstance(ob, type)) + if issubclass(c, RCSTestCase)] + + for base_class in rcs_testcase_classes: + testcase_class_name = rcs_class.__name__ + base_class.__name__ + testcase_class_bases = (base_class,) + testcase_class_dict = dict(base_class.__dict__) + testcase_class_dict['Class'] = rcs_class + testcase_class = type( + testcase_class_name, testcase_class_bases, testcase_class_dict) + setattr(namespace, testcase_class_name, testcase_class) + + +unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) |