From b0c7c274d394ccfba2ea84fa6e9785f41f4cddd8 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 14 Jun 2009 14:34:11 +1000 Subject: Make RCS testcase subclasses dynamically. --- libbe/arch.py | 14 +++++++++----- libbe/bzr.py | 13 ++++++++----- libbe/git.py | 13 ++++++++----- libbe/hg.py | 13 ++++++++----- libbe/rcs.py | 24 +++++++++++++++++++++--- 5 files changed, 54 insertions(+), 23 deletions(-) (limited to 'libbe') 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()]) -- cgit From 1e2bb2b79fbb7a3eeb3f0a86d520b2a01c64ad64 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 14 Jun 2009 17:24:29 +1000 Subject: Refactor mega-testcases into separate true-or-false testcases. --- libbe/rcs.py | 307 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 229 insertions(+), 78 deletions(-) (limited to 'libbe') diff --git a/libbe/rcs.py b/libbe/rcs.py index ed5c7ee..b86ef80 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -547,93 +547,244 @@ class RCS(object): return (summary, body) +def setup_rcs_test_fixtures(testcase): + """ Set up test fixtures for RCS test case. """ + testcase.rcs = testcase.Class() + testcase.dir = Dir() + testcase.dirname = testcase.dir.path + + testcase.rcs_supports_set_user_id = ( + testcase.rcs.name not in ["None", "hg"]) + + if not testcase.rcs.installed(): + testcase.fail( + "%(name)s RCS not found" % vars(testcase.Class)) + + if testcase.Class.name != "None": + testcase.failIf( + testcase.rcs.detect(testcase.dirname), + "Detected %(name)s RCS before initialising" + % vars(testcase.Class)) + + testcase.rcs.init(testcase.dirname) + + class RCSTestCase(unittest.TestCase): + """ Test cases for base RCS class. """ + Class = RCS + def __init__(self, *args, **kwargs): - unittest.TestCase.__init__(self, *args, **kwargs) + super(RCSTestCase, self).__init__(*args, **kwargs) self.dirname = None - def instantiateRCS(self): - return self.Class() + def setUp(self): - self.dir = Dir() - self.dirname = self.dir.path - self.rcs = self.instantiateRCS() + super(RCSTestCase, self).setUp() + setup_rcs_test_fixtures(self) + def tearDown(self): del(self.rcs) - del(self.dirname) - def fullPath(self, path): - return os.path.join(self.dirname, path) - def assertPathExists(self, path): - fullpath = self.fullPath(path) - self.failUnless(os.path.exists(fullpath)==True, - "path %s does not exist" % fullpath) - def uidTest(self): - user_id = self.rcs.get_user_id() - self.failUnless(user_id != None, - "unable to get a user id") - user_idB = "John Doe " - if self.rcs.name in ["None", "hg"]: - self.assertRaises(SettingIDnotSupported, self.rcs.set_user_id, - user_idB) - else: - self.rcs.set_user_id(user_idB) - self.failUnless(self.rcs.get_user_id() == user_idB, - "user id not set correctly (was %s, is %s)" \ - % (user_id, self.rcs.get_user_id())) - self.failUnless(self.rcs.set_user_id(user_id) == None, - "unable to restore user id %s" % user_id) - self.failUnless(self.rcs.get_user_id() == user_id, - "unable to restore user id %s" % user_id) - def versionTest(self, path): - origpath = path - path = self.fullPath(path) - contentsA = "Lorem ipsum" - contentsB = "dolor sit amet" - self.rcs.set_file_contents(path,contentsA) - self.failUnless(self.rcs.get_file_contents(path)==contentsA, - "File contents not set or read correctly") - revision = self.rcs.commit("Commit current status") - self.failUnless(self.rcs.get_file_contents(path)==contentsA, - "Committing File contents not set or read correctly") - if self.rcs.versioned == True: - self.rcs.set_file_contents(path,contentsB) - self.failUnless(self.rcs.get_file_contents(path)==contentsB, - "File contents not set correctly after commit") - contentsArev = self.rcs.get_file_contents(path, revision) - self.failUnless(contentsArev==contentsA, \ - "Original file contents not saved in revision %s\n%s\n%s\n" \ - % (revision, contentsA, contentsArev)) - dup = self.rcs.duplicate_repo(revision) - duppath = os.path.join(dup, origpath) - dupcont = file(duppath, "rb").read() - self.failUnless(dupcont == contentsA) - self.rcs.remove_duplicate_repo() - def testRun(self): - self.failUnless(self.rcs.installed() == True, - "%s RCS not found" % self.Class.name) - if self.Class.name != "None": - self.failUnless(self.rcs.detect(self.dirname)==False, - "Detected %s RCS before initializing" \ - % self.Class.name) - self.rcs.init(self.dirname) - self.failUnless(self.rcs.detect(self.dirname)==True, - "Did not detect %s RCS after initializing" \ - % self.Class.name) + super(RCSTestCase, self).tearDown() + + def full_path(self, rel_path): + return os.path.join(self.dirname, rel_path) + + +class RCS_init_TestCase(RCSTestCase): + """ Test cases for RCS.init method. """ + + def test_detect_should_succeed_after_init(self): + """ Should detect RCS in directory after initialization. """ + self.failUnless( + self.rcs.detect(self.dirname), + "Did not detect %(name)s RCS after initialising" + % vars(self.Class)) + + def test_rcs_rootdir_in_specified_root_path(self): + """ RCS root directory should be in specified root path. """ rp = os.path.realpath(self.rcs.rootdir) dp = os.path.realpath(self.dirname) - self.failUnless(dp == rp or rp == None, - "%s RCS root in wrong dir (%s %s)" \ - % (self.Class.name, dp, rp)) - self.uidTest() - self.rcs.mkdir(self.fullPath('a')) - self.rcs.mkdir(self.fullPath('a/b')) - self.rcs.mkdir(self.fullPath('c')) - self.assertPathExists('a') - self.assertPathExists('a/b') - self.assertPathExists('c') - self.versionTest('a/text') - self.versionTest('a/b/text') - self.rcs.recursive_remove(self.fullPath('a')) + rcs_name = self.Class.name + self.failUnless( + dp == rp or rp == None, + "%(rcs_name)s RCS root in wrong dir (%(dp)s %(rp)s)" % vars()) + + +class RCS_get_user_id_TestCase(RCSTestCase): + """ Test cases for RCS.get_user_id method. """ + + def test_gets_existing_user_id(self): + """ Should get the existing user ID. """ + user_id = self.rcs.get_user_id() + self.failUnless( + user_id is not None, + "unable to get a user id") + + +class RCS_set_user_id_TestCase(RCSTestCase): + """ Test cases for RCS.set_user_id method. """ + + def setUp(self): + super(RCS_set_user_id_TestCase, self).setUp() + + self.prev_user_id = self.rcs.get_user_id() + + if self.rcs_supports_set_user_id: + self.test_new_user_id = "John Doe " + self.rcs.set_user_id(self.test_new_user_id) + + def tearDown(self): + if self.rcs_supports_set_user_id: + self.rcs.set_user_id(self.prev_user_id) + super(RCS_set_user_id_TestCase, self).tearDown() + + def test_raises_error_in_unsupported_vcs(self): + """ Should raise an error in a VCS that doesn't support it. """ + if self.rcs_supports_set_user_id: + return + self.assertRaises( + SettingIDnotSupported, + self.rcs.set_user_id, "foo") + + def test_updates_user_id_in_supporting_rcs(self): + """ Should update the user ID in an RCS that supports it. """ + if not self.rcs_supports_set_user_id: + return + user_id = self.rcs.get_user_id() + self.failUnlessEqual( + self.test_new_user_id, user_id, + "user id not set correctly (expected %s, got %s)" + % (self.test_new_user_id, user_id)) + + +def setup_rcs_revision_test_fixtures(testcase): + """ Set up revision test fixtures for RCS test case. """ + testcase.test_dirs = ['a', 'a/b', 'c'] + for path in testcase.test_dirs: + testcase.rcs.mkdir(testcase.full_path(path)) + + testcase.test_files = ['a/text', 'a/b/text'] + + testcase.test_contents = { + 'rev_1': "Lorem ipsum", + 'uncommitted': "dolor sit amet", + } + + +class RCS_mkdir_TestCase(RCSTestCase): + """ Test cases for RCS.mkdir method. """ + + def setUp(self): + super(RCS_mkdir_TestCase, self).setUp() + setup_rcs_revision_test_fixtures(self) + + def tearDown(self): + for path in reversed(sorted(self.test_dirs)): + self.rcs.recursive_remove(self.full_path(path)) + super(RCS_mkdir_TestCase, self).tearDown() + + def test_mkdir_creates_directory(self): + """ Should create specified directory in filesystem. """ + for path in self.test_dirs: + full_path = self.full_path(path) + self.failUnless( + os.path.exists(full_path), + "path %(full_path)s does not exist" % vars()) + + +class RCS_commit_TestCase(RCSTestCase): + """ Test cases for RCS.commit method. """ + + def setUp(self): + super(RCS_commit_TestCase, self).setUp() + setup_rcs_revision_test_fixtures(self) + + def tearDown(self): + for path in reversed(sorted(self.test_dirs)): + self.rcs.recursive_remove(self.full_path(path)) + super(RCS_commit_TestCase, self).tearDown() + + def test_file_contents_as_specified(self): + """ Should set file contents as specified. """ + test_contents = self.test_contents['rev_1'] + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents(full_path, test_contents) + current_contents = self.rcs.get_file_contents(full_path) + self.failUnlessEqual(test_contents, current_contents) + + def test_file_contents_as_committed(self): + """ Should have file contents as specified after commit. """ + test_contents = self.test_contents['rev_1'] + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents(full_path, test_contents) + revision = self.rcs.commit("Initial file contents.") + current_contents = self.rcs.get_file_contents(full_path) + self.failUnlessEqual(test_contents, current_contents) + + def test_file_contents_as_set_when_uncommitted(self): + """ Should set file contents as specified after commit. """ + if not self.rcs.versioned: + return + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents( + full_path, self.test_contents['rev_1']) + revision = self.rcs.commit("Initial file contents.") + self.rcs.set_file_contents( + full_path, self.test_contents['uncommitted']) + current_contents = self.rcs.get_file_contents(full_path) + self.failUnlessEqual( + self.test_contents['uncommitted'], current_contents) + + def test_revision_file_contents_as_committed(self): + """ Should get file contents as committed to specified revision. """ + if not self.rcs.versioned: + return + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents( + full_path, self.test_contents['rev_1']) + revision = self.rcs.commit("Initial file contents.") + self.rcs.set_file_contents( + full_path, self.test_contents['uncommitted']) + committed_contents = self.rcs.get_file_contents( + full_path, revision) + self.failUnlessEqual( + self.test_contents['rev_1'], committed_contents) + + +class RCS_duplicate_repo_TestCase(RCSTestCase): + """ Test cases for RCS.duplicate_repo method. """ + + def setUp(self): + super(RCS_duplicate_repo_TestCase, self).setUp() + setup_rcs_revision_test_fixtures(self) + + def tearDown(self): + self.rcs.remove_duplicate_repo() + for path in reversed(sorted(self.test_dirs)): + self.rcs.recursive_remove(self.full_path(path)) + super(RCS_duplicate_repo_TestCase, self).tearDown() + + def test_revision_file_contents_as_committed(self): + """ Should match file contents as committed to specified revision. """ + if not self.rcs.versioned: + return + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents( + full_path, self.test_contents['rev_1']) + revision = self.rcs.commit("Commit current status") + self.rcs.set_file_contents( + full_path, self.test_contents['uncommitted']) + dup_repo_path = self.rcs.duplicate_repo(revision) + dup_file_path = os.path.join(dup_repo_path, path) + dup_file_contents = file(dup_file_path, 'rb').read() + self.failUnlessEqual( + self.test_contents['rev_1'], dup_file_contents) + self.rcs.remove_duplicate_repo() def make_rcs_testcase_subclasses(rcs_class, namespace): -- cgit From 4029c15d863ea2d6a2ada5f2306b2c99dadcf75f Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 14 Jun 2009 17:27:18 +1000 Subject: Distinguish tests for VCS which can't handle an uninitialised identity. --- libbe/rcs.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libbe') diff --git a/libbe/rcs.py b/libbe/rcs.py index b86ef80..e9cd9ca 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -553,6 +553,8 @@ def setup_rcs_test_fixtures(testcase): testcase.dir = Dir() testcase.dirname = testcase.dir.path + testcase.rcs_supports_uninitialized_user_id = ( + testcase.rcs.name not in ["git"]) testcase.rcs_supports_set_user_id = ( testcase.rcs.name not in ["None", "hg"]) @@ -615,6 +617,9 @@ class RCS_get_user_id_TestCase(RCSTestCase): def test_gets_existing_user_id(self): """ Should get the existing user ID. """ + if not self.rcs_supports_uninitialized_user_id: + return + user_id = self.rcs.get_user_id() self.failUnless( user_id is not None, @@ -627,7 +632,10 @@ class RCS_set_user_id_TestCase(RCSTestCase): def setUp(self): super(RCS_set_user_id_TestCase, self).setUp() - self.prev_user_id = self.rcs.get_user_id() + if self.rcs_supports_uninitialized_user_id: + self.prev_user_id = self.rcs.get_user_id() + else: + self.prev_user_id = "Uninitialized identity " if self.rcs_supports_set_user_id: self.test_new_user_id = "John Doe " -- cgit From 3d68aa87e761a5347da8ec3afdc6ba2aa25d8a81 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 15 Jun 2009 20:13:22 +1000 Subject: Follow existing docstring whitespace convention. --- libbe/rcs.py | 84 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 21 deletions(-) (limited to 'libbe') diff --git a/libbe/rcs.py b/libbe/rcs.py index e9cd9ca..644ed7c 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -548,7 +548,9 @@ class RCS(object): def setup_rcs_test_fixtures(testcase): - """ Set up test fixtures for RCS test case. """ + """ + Set up test fixtures for RCS test case. + """ testcase.rcs = testcase.Class() testcase.dir = Dir() testcase.dirname = testcase.dir.path @@ -572,7 +574,9 @@ def setup_rcs_test_fixtures(testcase): class RCSTestCase(unittest.TestCase): - """ Test cases for base RCS class. """ + """ + Test cases for base RCS class. + """ Class = RCS @@ -593,17 +597,23 @@ class RCSTestCase(unittest.TestCase): class RCS_init_TestCase(RCSTestCase): - """ Test cases for RCS.init method. """ + """ + Test cases for RCS.init method. + """ def test_detect_should_succeed_after_init(self): - """ Should detect RCS in directory after initialization. """ + """ + Should detect RCS in directory after initialization. + """ self.failUnless( self.rcs.detect(self.dirname), "Did not detect %(name)s RCS after initialising" % vars(self.Class)) def test_rcs_rootdir_in_specified_root_path(self): - """ RCS root directory should be in specified root path. """ + """ + RCS root directory should be in specified root path. + """ rp = os.path.realpath(self.rcs.rootdir) dp = os.path.realpath(self.dirname) rcs_name = self.Class.name @@ -613,10 +623,14 @@ class RCS_init_TestCase(RCSTestCase): class RCS_get_user_id_TestCase(RCSTestCase): - """ Test cases for RCS.get_user_id method. """ + """ + Test cases for RCS.get_user_id method. + """ def test_gets_existing_user_id(self): - """ Should get the existing user ID. """ + """ + Should get the existing user ID. + """ if not self.rcs_supports_uninitialized_user_id: return @@ -627,7 +641,9 @@ class RCS_get_user_id_TestCase(RCSTestCase): class RCS_set_user_id_TestCase(RCSTestCase): - """ Test cases for RCS.set_user_id method. """ + """ + Test cases for RCS.set_user_id method. + """ def setUp(self): super(RCS_set_user_id_TestCase, self).setUp() @@ -647,7 +663,9 @@ class RCS_set_user_id_TestCase(RCSTestCase): super(RCS_set_user_id_TestCase, self).tearDown() def test_raises_error_in_unsupported_vcs(self): - """ Should raise an error in a VCS that doesn't support it. """ + """ + Should raise an error in a VCS that doesn't support it. + """ if self.rcs_supports_set_user_id: return self.assertRaises( @@ -655,7 +673,9 @@ class RCS_set_user_id_TestCase(RCSTestCase): self.rcs.set_user_id, "foo") def test_updates_user_id_in_supporting_rcs(self): - """ Should update the user ID in an RCS that supports it. """ + """ + Should update the user ID in an RCS that supports it. + """ if not self.rcs_supports_set_user_id: return user_id = self.rcs.get_user_id() @@ -666,7 +686,9 @@ class RCS_set_user_id_TestCase(RCSTestCase): def setup_rcs_revision_test_fixtures(testcase): - """ Set up revision test fixtures for RCS test case. """ + """ + Set up revision test fixtures for RCS test case. + """ testcase.test_dirs = ['a', 'a/b', 'c'] for path in testcase.test_dirs: testcase.rcs.mkdir(testcase.full_path(path)) @@ -680,7 +702,9 @@ def setup_rcs_revision_test_fixtures(testcase): class RCS_mkdir_TestCase(RCSTestCase): - """ Test cases for RCS.mkdir method. """ + """ + Test cases for RCS.mkdir method. + """ def setUp(self): super(RCS_mkdir_TestCase, self).setUp() @@ -692,7 +716,9 @@ class RCS_mkdir_TestCase(RCSTestCase): super(RCS_mkdir_TestCase, self).tearDown() def test_mkdir_creates_directory(self): - """ Should create specified directory in filesystem. """ + """ + Should create specified directory in filesystem. + """ for path in self.test_dirs: full_path = self.full_path(path) self.failUnless( @@ -701,7 +727,9 @@ class RCS_mkdir_TestCase(RCSTestCase): class RCS_commit_TestCase(RCSTestCase): - """ Test cases for RCS.commit method. """ + """ + Test cases for RCS.commit method. + """ def setUp(self): super(RCS_commit_TestCase, self).setUp() @@ -713,7 +741,9 @@ class RCS_commit_TestCase(RCSTestCase): super(RCS_commit_TestCase, self).tearDown() def test_file_contents_as_specified(self): - """ Should set file contents as specified. """ + """ + Should set file contents as specified. + """ test_contents = self.test_contents['rev_1'] for path in self.test_files: full_path = self.full_path(path) @@ -722,7 +752,9 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual(test_contents, current_contents) def test_file_contents_as_committed(self): - """ Should have file contents as specified after commit. """ + """ + Should have file contents as specified after commit. + """ test_contents = self.test_contents['rev_1'] for path in self.test_files: full_path = self.full_path(path) @@ -732,7 +764,9 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual(test_contents, current_contents) def test_file_contents_as_set_when_uncommitted(self): - """ Should set file contents as specified after commit. """ + """ + Should set file contents as specified after commit. + """ if not self.rcs.versioned: return for path in self.test_files: @@ -747,7 +781,9 @@ class RCS_commit_TestCase(RCSTestCase): self.test_contents['uncommitted'], current_contents) def test_revision_file_contents_as_committed(self): - """ Should get file contents as committed to specified revision. """ + """ + Should get file contents as committed to specified revision. + """ if not self.rcs.versioned: return for path in self.test_files: @@ -764,7 +800,9 @@ class RCS_commit_TestCase(RCSTestCase): class RCS_duplicate_repo_TestCase(RCSTestCase): - """ Test cases for RCS.duplicate_repo method. """ + """ + Test cases for RCS.duplicate_repo method. + """ def setUp(self): super(RCS_duplicate_repo_TestCase, self).setUp() @@ -777,7 +815,9 @@ class RCS_duplicate_repo_TestCase(RCSTestCase): super(RCS_duplicate_repo_TestCase, self).tearDown() def test_revision_file_contents_as_committed(self): - """ Should match file contents as committed to specified revision. """ + """ + Should match file contents as committed to specified revision. + """ if not self.rcs.versioned: return for path in self.test_files: @@ -796,7 +836,9 @@ class RCS_duplicate_repo_TestCase(RCSTestCase): def make_rcs_testcase_subclasses(rcs_class, namespace): - """ Make RCSTestCase subclasses for rcs_class in the 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)) -- cgit From 6ecbe654d3f33cbfb90bb767bffbd252144d08c9 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 21 Jun 2009 09:51:39 +1000 Subject: Conform new docstrings to PEP 257. --- libbe/rcs.py | 84 +++++++++++++++--------------------------------------------- 1 file changed, 21 insertions(+), 63 deletions(-) (limited to 'libbe') diff --git a/libbe/rcs.py b/libbe/rcs.py index 644ed7c..a5a1769 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -548,9 +548,7 @@ class RCS(object): def setup_rcs_test_fixtures(testcase): - """ - Set up test fixtures for RCS test case. - """ + """Set up test fixtures for RCS test case.""" testcase.rcs = testcase.Class() testcase.dir = Dir() testcase.dirname = testcase.dir.path @@ -574,9 +572,7 @@ def setup_rcs_test_fixtures(testcase): class RCSTestCase(unittest.TestCase): - """ - Test cases for base RCS class. - """ + """Test cases for base RCS class.""" Class = RCS @@ -597,23 +593,17 @@ class RCSTestCase(unittest.TestCase): class RCS_init_TestCase(RCSTestCase): - """ - Test cases for RCS.init method. - """ + """Test cases for RCS.init method.""" def test_detect_should_succeed_after_init(self): - """ - Should detect RCS in directory after initialization. - """ + """Should detect RCS in directory after initialization.""" self.failUnless( self.rcs.detect(self.dirname), "Did not detect %(name)s RCS after initialising" % vars(self.Class)) def test_rcs_rootdir_in_specified_root_path(self): - """ - RCS root directory should be in specified root path. - """ + """RCS root directory should be in specified root path.""" rp = os.path.realpath(self.rcs.rootdir) dp = os.path.realpath(self.dirname) rcs_name = self.Class.name @@ -623,14 +613,10 @@ class RCS_init_TestCase(RCSTestCase): class RCS_get_user_id_TestCase(RCSTestCase): - """ - Test cases for RCS.get_user_id method. - """ + """Test cases for RCS.get_user_id method.""" def test_gets_existing_user_id(self): - """ - Should get the existing user ID. - """ + """Should get the existing user ID.""" if not self.rcs_supports_uninitialized_user_id: return @@ -641,9 +627,7 @@ class RCS_get_user_id_TestCase(RCSTestCase): class RCS_set_user_id_TestCase(RCSTestCase): - """ - Test cases for RCS.set_user_id method. - """ + """Test cases for RCS.set_user_id method.""" def setUp(self): super(RCS_set_user_id_TestCase, self).setUp() @@ -663,9 +647,7 @@ class RCS_set_user_id_TestCase(RCSTestCase): super(RCS_set_user_id_TestCase, self).tearDown() def test_raises_error_in_unsupported_vcs(self): - """ - Should raise an error in a VCS that doesn't support it. - """ + """Should raise an error in a VCS that doesn't support it.""" if self.rcs_supports_set_user_id: return self.assertRaises( @@ -673,9 +655,7 @@ class RCS_set_user_id_TestCase(RCSTestCase): self.rcs.set_user_id, "foo") def test_updates_user_id_in_supporting_rcs(self): - """ - Should update the user ID in an RCS that supports it. - """ + """Should update the user ID in an RCS that supports it.""" if not self.rcs_supports_set_user_id: return user_id = self.rcs.get_user_id() @@ -686,9 +666,7 @@ class RCS_set_user_id_TestCase(RCSTestCase): def setup_rcs_revision_test_fixtures(testcase): - """ - Set up revision test fixtures for RCS test case. - """ + """Set up revision test fixtures for RCS test case.""" testcase.test_dirs = ['a', 'a/b', 'c'] for path in testcase.test_dirs: testcase.rcs.mkdir(testcase.full_path(path)) @@ -702,9 +680,7 @@ def setup_rcs_revision_test_fixtures(testcase): class RCS_mkdir_TestCase(RCSTestCase): - """ - Test cases for RCS.mkdir method. - """ + """Test cases for RCS.mkdir method.""" def setUp(self): super(RCS_mkdir_TestCase, self).setUp() @@ -716,9 +692,7 @@ class RCS_mkdir_TestCase(RCSTestCase): super(RCS_mkdir_TestCase, self).tearDown() def test_mkdir_creates_directory(self): - """ - Should create specified directory in filesystem. - """ + """Should create specified directory in filesystem.""" for path in self.test_dirs: full_path = self.full_path(path) self.failUnless( @@ -727,9 +701,7 @@ class RCS_mkdir_TestCase(RCSTestCase): class RCS_commit_TestCase(RCSTestCase): - """ - Test cases for RCS.commit method. - """ + """Test cases for RCS.commit method.""" def setUp(self): super(RCS_commit_TestCase, self).setUp() @@ -741,9 +713,7 @@ class RCS_commit_TestCase(RCSTestCase): super(RCS_commit_TestCase, self).tearDown() def test_file_contents_as_specified(self): - """ - Should set file contents as specified. - """ + """Should set file contents as specified.""" test_contents = self.test_contents['rev_1'] for path in self.test_files: full_path = self.full_path(path) @@ -752,9 +722,7 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual(test_contents, current_contents) def test_file_contents_as_committed(self): - """ - Should have file contents as specified after commit. - """ + """Should have file contents as specified after commit.""" test_contents = self.test_contents['rev_1'] for path in self.test_files: full_path = self.full_path(path) @@ -764,9 +732,7 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual(test_contents, current_contents) def test_file_contents_as_set_when_uncommitted(self): - """ - Should set file contents as specified after commit. - """ + """Should set file contents as specified after commit.""" if not self.rcs.versioned: return for path in self.test_files: @@ -781,9 +747,7 @@ class RCS_commit_TestCase(RCSTestCase): self.test_contents['uncommitted'], current_contents) def test_revision_file_contents_as_committed(self): - """ - Should get file contents as committed to specified revision. - """ + """Should get file contents as committed to specified revision.""" if not self.rcs.versioned: return for path in self.test_files: @@ -800,9 +764,7 @@ class RCS_commit_TestCase(RCSTestCase): class RCS_duplicate_repo_TestCase(RCSTestCase): - """ - Test cases for RCS.duplicate_repo method. - """ + """Test cases for RCS.duplicate_repo method.""" def setUp(self): super(RCS_duplicate_repo_TestCase, self).setUp() @@ -815,9 +777,7 @@ class RCS_duplicate_repo_TestCase(RCSTestCase): super(RCS_duplicate_repo_TestCase, self).tearDown() def test_revision_file_contents_as_committed(self): - """ - Should match file contents as committed to specified revision. - """ + """Should match file contents as committed to specified revision.""" if not self.rcs.versioned: return for path in self.test_files: @@ -836,9 +796,7 @@ class RCS_duplicate_repo_TestCase(RCSTestCase): def make_rcs_testcase_subclasses(rcs_class, namespace): - """ - Make RCSTestCase subclasses for rcs_class in the 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)) -- cgit