diff options
author | Raymond Hettinger <python@rcn.com> | 2008-07-10 16:06:41 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-07-10 16:06:41 +0000 |
commit | 5930d8f05e501ac0327c8b752a21412b0fb97cae (patch) | |
tree | 449b6e6e4b40deb5ca602d3783f01901d4018a1d /Lib/unittest.py | |
parent | 930795b7e02835421ef1c998d0b99ffa5e930239 (diff) | |
download | cpython-git-5930d8f05e501ac0327c8b752a21412b0fb97cae.tar.gz |
Suppress -3 warnings in unittest.py
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r-- | Lib/unittest.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index b89fb473a2..b5c6befe90 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -68,7 +68,6 @@ __all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases']) # Backward compatibility ############################################################################## if sys.version_info[:2] < (2, 2): - False, True = 0, 1 def isinstance(obj, clsinfo): import __builtin__ if type(clsinfo) in (tuple, list): @@ -79,6 +78,14 @@ if sys.version_info[:2] < (2, 2): return 0 else: return __builtin__.isinstance(obj, clsinfo) +def _CmpToKey(mycmp): + 'Convert a cmp= function into a key= function' + class K(object): + def __init__(self, obj): + self.obj = obj + def __lt__(self, other): + return mycmp(self.obj, other.obj) == -1 + return K ############################################################################## # Test framework core @@ -429,7 +436,7 @@ class TestSuite: def addTest(self, test): # sanity checks - if not callable(test): + if not hasattr(test, '__call__'): raise TypeError("the test to add must be callable") if (isinstance(test, (type, types.ClassType)) and issubclass(test, (TestCase, TestSuite))): @@ -584,7 +591,7 @@ class TestLoader: return TestSuite([parent(obj.__name__)]) elif isinstance(obj, TestSuite): return obj - elif callable(obj): + elif hasattr(obj, '__call__'): test = obj() if isinstance(test, TestSuite): return test @@ -607,10 +614,10 @@ class TestLoader: """Return a sorted sequence of method names found within testCaseClass """ def isTestMethod(attrname, testCaseClass=testCaseClass, prefix=self.testMethodPrefix): - return attrname.startswith(prefix) and callable(getattr(testCaseClass, attrname)) + return attrname.startswith(prefix) and hasattr(getattr(testCaseClass, attrname), '__call__') testFnNames = filter(isTestMethod, dir(testCaseClass)) if self.sortTestMethodsUsing: - testFnNames.sort(self.sortTestMethodsUsing) + testFnNames.sort(key=_CmpToKey(self.sortTestMethodsUsing)) return testFnNames |