diff options
author | jpellerin <devnull@localhost> | 2009-10-17 02:54:39 -0400 |
---|---|---|
committer | jpellerin <devnull@localhost> | 2009-10-17 02:54:39 -0400 |
commit | 6a99019467d83338f0e820db25b0b0c170cdb42f (patch) | |
tree | 19d33f140f1768be725e1109fb27534a57b6dad9 | |
parent | 5c5ba6eaf9d48effbdad3a18244e280d6f88a16e (diff) | |
download | nose-6a99019467d83338f0e820db25b0b0c170cdb42f.tar.gz |
Fixed some more 2.7 failures
-rw-r--r-- | functional_tests/doc_tests/test_init_plugin/init_plugin.rst | 3 | ||||
-rw-r--r-- | nose/case.py | 17 | ||||
-rw-r--r-- | nose/util.py | 8 | ||||
-rw-r--r-- | unit_tests/test_cases.py | 9 | ||||
-rw-r--r-- | unit_tests/test_utils.py | 8 |
5 files changed, 25 insertions, 20 deletions
diff --git a/functional_tests/doc_tests/test_init_plugin/init_plugin.rst b/functional_tests/doc_tests/test_init_plugin/init_plugin.rst index fd2d268..4eaf0f6 100644 --- a/functional_tests/doc_tests/test_init_plugin/init_plugin.rst +++ b/functional_tests/doc_tests/test_init_plugin/init_plugin.rst @@ -32,6 +32,9 @@ raising any exceptions. ... def test_likes_cheese(self): ... """Widgets might like cheese""" ... self.widget.likes_cheese() + ... def shortDescription(self): # 2.7 compat + ... doc = self._testMethodDoc + ... return doc and doc.split("\n")[0].strip() or None The tests are bundled into a suite that we can pass to the test runner. diff --git a/nose/case.py b/nose/case.py index 3a7f464..8e78ff3 100644 --- a/nose/case.py +++ b/nose/case.py @@ -20,7 +20,7 @@ class Test(unittest.TestCase): When a plugin sees a test, it will always see an instance of this class. To access the actual test case that will be run, access the - test property of the nose.case.Test instance. + test property of the nose.case.Test instance. """ __test__ = False # do not collect def __init__(self, test, config=None, resultProxy=None): @@ -148,27 +148,24 @@ class Test(unittest.TestCase): if plug_test is not None: test = plug_test test(result) - + def shortDescription(self): desc = self.plugins.describeTest(self) if desc is not None: return desc - doc = self.test.shortDescription() - if doc is not None: - return doc # work around bug in unittest.TestCase.shortDescription # with multiline docstrings. test = self.test try: - doc = test._testMethodDoc # 2.5 + test._testMethodDoc = test._testMethodDoc.strip()# 2.5 except AttributeError: try: - doc = test._TestCase__testMethodDoc # 2.4 and earlier + # 2.4 and earlier + test._TestCase__testMethodDoc = \ + test._TestCase__testMethodDoc.strip() except AttributeError: pass - if doc is not None: - doc = doc.strip().split("\n")[0].strip() - return doc + return self.test.shortDescription() class TestBase(unittest.TestCase): diff --git a/nose/util.py b/nose/util.py index 0eb97a3..7b9c233 100644 --- a/nose/util.py +++ b/nose/util.py @@ -439,9 +439,13 @@ def test_address(test): "%s.%s" % (cls_adr[2], test.__name__)) # handle unittest.TestCase instances if isinstance(test, unittest.TestCase): - if hasattr(test, '_FunctionTestCase__testFunc'): + if (hasattr(test, '_FunctionTestCase__testFunc') # pre 2.7 + or hasattr(test, '_testFunc')): # 2.7 # unittest FunctionTestCase - return test_address(test._FunctionTestCase__testFunc) + try: + return test_address(test._FunctionTestCase__testFunc) + except AttributeError: + return test_address(test._testFunc) # regular unittest.TestCase cls_adr = test_address(test.__class__) # 2.5 compat: __testMethodName changed to _testMethodName diff --git a/unit_tests/test_cases.py b/unit_tests/test_cases.py index 2821708..2e1ca2a 100644 --- a/unit_tests/test_cases.py +++ b/unit_tests/test_cases.py @@ -243,9 +243,10 @@ class TestNoseTestWrapper(unittest.TestCase): case_b = nose.case.Test(TC('test_b')) case_c = nose.case.Test(TC('test_c')) - self.assertEqual(case_a.shortDescription(), "This is the description") - self.assertEqual(case_b.shortDescription(), "This is the description") - self.assertEqual(case_c.shortDescription(), None) - + assert case_a.shortDescription().endswith("This is the description") + assert case_b.shortDescription().endswith("This is the description") + assert case_c.shortDescription() in (None, # pre 2.7 + 'test_c (test_cases.TC)') # 2.7 + if __name__ == '__main__': unittest.main() diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index d63adce..4a26ec7 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -51,7 +51,7 @@ class TestUtils(unittest.TestCase): pass else: self.fail("Nonsense test name should throw ValueError") - + def test_test_address(self): # test addresses are specified as # package.module:class.method @@ -73,7 +73,7 @@ class TestUtils(unittest.TestCase): pass def test_two(self): pass - + class CustomTestType(type): pass class CustomTC(unittest.TestCase): @@ -82,7 +82,7 @@ class TestUtils(unittest.TestCase): pass def test_two(self): pass - + foo_funct = case.FunctionTestCase(baz) foo_functu = unittest.FunctionTestCase(baz) @@ -111,7 +111,7 @@ class TestUtils(unittest.TestCase): (me, __name__, 'baz')) self.assertEqual(test_address(foo_mtc), (me, __name__, 'Foo.bar')) - + def test_isclass_detects_classes(self): class TC(unittest.TestCase): pass |