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 | |
parent | a711ecf10df62e30d83c1941065404c53fecd35b (diff) | |
download | bugseverywhere-b0c7c274d394ccfba2ea84fa6e9785f41f4cddd8.tar.gz |
Make RCS testcase subclasses dynamically.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/arch.py | 14 | ||||
-rw-r--r-- | libbe/bzr.py | 13 | ||||
-rw-r--r-- | libbe/git.py | 13 | ||||
-rw-r--r-- | libbe/hg.py | 13 | ||||
-rw-r--r-- | libbe/rcs.py | 24 |
5 files changed, 54 insertions, 23 deletions
diff --git a/libbe/arch.py b/libbe/arch.py index fd953a4..73bef35 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import sys import os import shutil import time @@ -23,7 +25,8 @@ import doctest import config from beuuid import uuid_gen -from rcs import RCS, RCStestCase, CommandError +import rcs +from rcs import RCS client = config.get_val("arch_client") if client is None: @@ -270,9 +273,10 @@ class CantAddFile(Exception): def __init__(self, file): self.file = file Exception.__init__(self, "Can't automatically add file %s" % file) - -class ArchTestCase(RCStestCase): - Class = Arch -unitsuite = unittest.TestLoader().loadTestsFromTestCase(ArchTestCase) + + +rcs.make_rcs_testcase_subclasses(Arch, sys.modules[__name__]) + +unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) diff --git a/libbe/bzr.py b/libbe/bzr.py index a0ae715..4a01d8a 100644 --- a/libbe/bzr.py +++ b/libbe/bzr.py @@ -14,12 +14,15 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import sys import os import re import unittest import doctest -from rcs import RCS, RCStestCase, CommandError +import rcs +from rcs import RCS def new(): return Bzr() @@ -79,7 +82,7 @@ class Bzr(RCS): def postcommit(self): try: self._u_invoke_client('merge') - except CommandError, e: + except rcs.CommandError, e: if ('No merge branch known or specified' in e.err_str or 'No merge location known or specified' in e.err_str): pass @@ -91,8 +94,8 @@ class Bzr(RCS): if len(self._u_invoke_client('status', directory=directory)[1]) > 0: self.commit('Merge from upstream') -class BzrTestCase(RCStestCase): - Class = Bzr + +rcs.make_rcs_testcase_subclasses(Bzr, sys.modules[__name__]) -unitsuite = unittest.TestLoader().loadTestsFromTestCase(BzrTestCase) +unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) diff --git a/libbe/git.py b/libbe/git.py index 046e72e..4a1ddee 100644 --- a/libbe/git.py +++ b/libbe/git.py @@ -13,12 +13,15 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import sys import os import re import unittest import doctest -from rcs import RCS, RCStestCase, CommandError +import rcs +from rcs import RCS def new(): return Git() @@ -91,9 +94,9 @@ class Git(RCS): assert len(match.groups()) == 3 revision = match.groups()[1] return revision - -class GitTestCase(RCStestCase): - Class = Git -unitsuite = unittest.TestLoader().loadTestsFromTestCase(GitTestCase) + +rcs.make_rcs_testcase_subclasses(Git, sys.modules[__name__]) + +unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) diff --git a/libbe/hg.py b/libbe/hg.py index 27cbb79..52f8a96 100644 --- a/libbe/hg.py +++ b/libbe/hg.py @@ -13,12 +13,15 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import sys import os import re import unittest import doctest -from rcs import RCS, RCStestCase, CommandError, SettingIDnotSupported +import rcs +from rcs import RCS def new(): return Hg() @@ -49,7 +52,7 @@ class Hg(RCS): standard Mercurial. http://www.selenic.com/mercurial/wiki/index.cgi/ConfigExtension """ - raise SettingIDnotSupported + raise rcs.SettingIDnotSupported def _rcs_add(self, path): self._u_invoke_client("add", path) def _rcs_remove(self, path): @@ -79,8 +82,8 @@ class Hg(RCS): revision = match.groups()[0] return revision -class HgTestCase(RCStestCase): - Class = Hg + +rcs.make_rcs_testcase_subclasses(Hg, sys.modules[__name__]) -unitsuite = unittest.TestLoader().loadTestsFromTestCase(HgTestCase) +unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) 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()]) |