From 84e3e4853204ecb77d09c0a7495313965386a6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 20:41:40 +0100 Subject: Apply 'except' fixer --- test/munittest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 16a61ae..35790cb 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -910,7 +910,7 @@ Examples: else: self.testNames = (self.defaultTest,) self.createTests() - except getopt.error, msg: + except getopt.error as msg: self.usageExit(msg) def createTests(self): -- cgit v1.2.1 From fa1c10acb020931e7cf0eb4de2ac0a874bae7c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 20:42:25 +0100 Subject: Apply 'raise' fixer --- test/munittest.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 35790cb..221d0b9 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -251,8 +251,8 @@ class TestCase: testMethod = getattr(self, methodName) self._testMethodDoc = testMethod.__doc__ except AttributeError: - raise ValueError, "no such test method in %s: %s" % \ - (self.__class__, methodName) + raise ValueError("no such test method in %s: %s" % \ + (self.__class__, methodName)) def setUp(self): "Hook method for setting up the test fixture before exercising it." @@ -361,15 +361,15 @@ class TestCase: def fail(self, msg=None): """Fail immediately, with the given message.""" - raise self.failureException, msg + raise self.failureException(msg) def failIf(self, expr, msg=None): "Fail the test if the expression is true." - if expr: raise self.failureException, msg + if expr: raise self.failureException(msg) def failUnless(self, expr, msg=None): """Fail the test unless the expression is true.""" - if not expr: raise self.failureException, msg + if not expr: raise self.failureException(msg) def failUnlessRaises(self, excClass, callableObj, *args, **kwargs): """Fail unless an exception of class excClass is thrown @@ -386,23 +386,21 @@ class TestCase: else: if hasattr(excClass,'__name__'): excName = excClass.__name__ else: excName = str(excClass) - raise self.failureException, excName + raise self.failureException(excName) def failUnlessEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ if not first == second: - raise self.failureException, \ - (msg or '%s != %s' % (`first`, `second`)) + raise self.failureException(msg or '%s != %s' % (`first`, `second`)) def failIfEqual(self, first, second, msg=None): """Fail if the two objects are equal as determined by the '==' operator. """ if first == second: - raise self.failureException, \ - (msg or '%s == %s' % (`first`, `second`)) + raise self.failureException(msg or '%s == %s' % (`first`, `second`)) def failUnlessAlmostEqual(self, first, second, places=7, msg=None): """Fail if the two objects are unequal as determined by their @@ -413,8 +411,7 @@ class TestCase: as significant digits (measured from the most significant digit). """ if round(second-first, places) != 0: - raise self.failureException, \ - (msg or '%s != %s within %s places' % (`first`, `second`, `places` )) + raise self.failureException(msg or '%s != %s within %s places' % (`first`, `second`, `places` )) def failIfAlmostEqual(self, first, second, places=7, msg=None): """Fail if the two objects are equal as determined by their @@ -425,8 +422,7 @@ class TestCase: as significant digits (measured from the most significant digit). """ if round(second-first, places) == 0: - raise self.failureException, \ - (msg or '%s == %s within %s places' % (`first`, `second`, `places`)) + raise self.failureException(msg or '%s == %s within %s places' % (`first`, `second`, `places`)) assertEqual = assertEquals = failUnlessEqual @@ -442,15 +438,15 @@ class TestCase: def skip(self, msg=None): """Skip the test""" - raise self.skipException, msg + raise self.skipException(msg) def skipIf(self, expr, msg=None): "Skip the test if the expression is true." - if expr: raise self.skipException, msg + if expr: raise self.skipException(msg) def skipUnless(self, expr, msg=None): """Skip the test unless the expression is true.""" - if not expr: raise self.skipException, msg + if not expr: raise self.skipException(msg) @@ -606,7 +602,7 @@ class TestLoader: parts = string.split(name, '.') if module is None: if not parts: - raise ValueError, "incomplete test name: %s" % name + raise ValueError("incomplete test name: %s" % name) else: parts_copy = parts[:] while parts_copy: @@ -633,11 +629,10 @@ class TestLoader: test = obj() if not isinstance(test, unittest.TestCase) and \ not isinstance(test, unittest.TestSuite): - raise ValueError, \ - "calling %s returned %s, not a test" % (obj,test) + raise ValueError("calling %s returned %s, not a test" % (obj,test)) return test else: - raise ValueError, "don't know how to make test from: %s" % obj + raise ValueError("don't know how to make test from: %s" % obj) def loadTestsFromNames(self, names, module=None): """Return a suite of all tests cases found using the given sequence -- cgit v1.2.1 From 0772e448446ca1252a4b1012ad2f9d2c96e29d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 20:44:18 +0100 Subject: Use %r instead of unnecessary repr calls --- test/munittest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 221d0b9..437248d 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -393,14 +393,14 @@ class TestCase: operator. """ if not first == second: - raise self.failureException(msg or '%s != %s' % (`first`, `second`)) + raise self.failureException(msg or '%r != %r' % (first, second)) def failIfEqual(self, first, second, msg=None): """Fail if the two objects are equal as determined by the '==' operator. """ if first == second: - raise self.failureException(msg or '%s == %s' % (`first`, `second`)) + raise self.failureException(msg or '%r == %r' % (first, second)) def failUnlessAlmostEqual(self, first, second, places=7, msg=None): """Fail if the two objects are unequal as determined by their @@ -411,7 +411,7 @@ class TestCase: as significant digits (measured from the most significant digit). """ if round(second-first, places) != 0: - raise self.failureException(msg or '%s != %s within %s places' % (`first`, `second`, `places` )) + raise self.failureException(msg or '%r != %r within %s places' % (first, second, places)) def failIfAlmostEqual(self, first, second, places=7, msg=None): """Fail if the two objects are equal as determined by their @@ -422,7 +422,7 @@ class TestCase: as significant digits (measured from the most significant digit). """ if round(second-first, places) == 0: - raise self.failureException(msg or '%s == %s within %s places' % (`first`, `second`, `places`)) + raise self.failureException(msg or '%r == %r within %r places' % (first, second, places)) assertEqual = assertEquals = failUnlessEqual -- cgit v1.2.1 From 4d97612f94e9d0799ad7786b6e7c6865ac21cd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 20:46:45 +0100 Subject: Remove trailing whitespace --- test/munittest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 437248d..f79a7cb 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -463,12 +463,12 @@ class TestSuite: self._tests = [] self.addTests(tests) self.description = description or '(no description)' - + def __repr__(self): return "<%s tests=%s>" % (_strclass(self.__class__), self._tests) __str__ = __repr__ - + def shortDescription(self): return self.description @@ -494,7 +494,7 @@ class TestSuite: def __call__(self, result): try: result.startSuite(self) except AttributeError: pass - + for test in self._tests: if result.shouldStop: break @@ -575,7 +575,7 @@ class TestLoader: description = (description.splitlines()[0]).strip() suite = self.suiteClass(instance_list, description) return suite - + def loadTestsFromModule(self, module): """Return a suite of all tests cases contained in the given module""" tests = [] @@ -735,7 +735,7 @@ class _TextTestResult(TestResult): except AttributeError: desc = '(no description)' self.stream.writeln(desc) self.depth += 1 - + def startTest(self, test): TestResult.startTest(self, test) if self.showAll: -- cgit v1.2.1 From c5b0bb36939c369e0aa8dea96cfbf7948ea6701c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 20:53:06 +0100 Subject: Apply 'print' fixer and add __future__ imports This way, there should be no change in behaviour under python2. --- test/munittest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index f79a7cb..ea96ae5 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + """ This is a modified version of the unittest module has been modified by Michael D. Stenner from Steve Purcell's version (revision 1.46, as @@ -881,8 +884,8 @@ Examples: self.runTests() def usageExit(self, msg=None): - if msg: print msg - print self.USAGE % self.__dict__ + if msg: print(msg) + print(self.USAGE % self.__dict__) sys.exit(2) def parseArgs(self, argv): -- cgit v1.2.1 From f303dd3f6eaf579e31d9d3f2fe8a0b4cbae50a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 21:04:32 +0100 Subject: Drop obsolete $Id tags git checkout . && git grep -e '\$Id:' -l|xargs perl -i -0pe 's|# \$Id:.*?\n\n||gms' --- test/munittest.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index ea96ae5..06fdd65 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -101,8 +101,6 @@ AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. """ -# $Id: munittest.py,v 1.2 2004/03/31 01:27:24 mstenner Exp $ - import time import sys import traceback -- cgit v1.2.1 From 735716711316f0254a90e36e487a6fdbeb11b602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 21:25:55 +0100 Subject: Apply 'idioms' fixer --- test/munittest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 06fdd65..1092758 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -619,12 +619,12 @@ class TestLoader: obj = getattr(obj, part) import unittest - if type(obj) == types.ModuleType: + if isinstance(obj, types.ModuleType): return self.loadTestsFromModule(obj) elif (isinstance(obj, (type, types.ClassType)) and issubclass(obj, unittest.TestCase)): return self.loadTestsFromTestCase(obj) - elif type(obj) == types.UnboundMethodType: + elif isinstance(obj, types.UnboundMethodType): return obj.im_class(obj.__name__) elif callable(obj): test = obj() @@ -865,7 +865,7 @@ Examples: """ def __init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=defaultTestLoader): - if type(module) == type(''): + if isinstance(module, type('')): self.module = __import__(module) for part in string.split(module,'.')[1:]: self.module = getattr(self.module, part) -- cgit v1.2.1 From ea4a93522b48528241d800fea06c83e36144d0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 22:28:39 +0100 Subject: Replace string function calls with method calls --- test/munittest.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 1092758..54d9a32 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -104,7 +104,6 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. import time import sys import traceback -import string import os import types @@ -191,7 +190,7 @@ class TestResult: def _exc_info_to_string(self, err): """Converts a sys.exc_info()-style tuple of values into a string.""" - return string.join(traceback.format_exception(*err), '') + return ''.join(traceback.format_exception(*err)) def __repr__(self): return "<%s run=%i errors=%i failures=%i>" % \ @@ -277,7 +276,7 @@ class TestCase: the specified test method's docstring. """ doc = self._testMethodDoc - return doc and string.strip(string.split(doc, "\n")[0]) or None + return doc and doc.split('\n')[0].strip() or None def id(self): return "%s.%s" % (_strclass(self.__class__), self._testMethodName) @@ -551,8 +550,7 @@ class FunctionTestCase(TestCase): def shortDescription(self): if self._description is not None: return self._description doc = self._testFunc.__doc__ - return doc and string.strip(string.split(doc, "\n")[0]) or None - + return doc and doc.split('\n')[0].strip() or None ############################################################################## @@ -600,7 +598,7 @@ class TestLoader: The method optionally resolves the names relative to a given module. """ - parts = string.split(name, '.') + parts = name.split('.') if module is None: if not parts: raise ValueError("incomplete test name: %s" % name) @@ -608,7 +606,7 @@ class TestLoader: parts_copy = parts[:] while parts_copy: try: - module = __import__(string.join(parts_copy,'.')) + module = __import__('.'.join(parts_copy)) break except ImportError: del parts_copy[-1] @@ -867,7 +865,7 @@ Examples: argv=None, testRunner=None, testLoader=defaultTestLoader): if isinstance(module, type('')): self.module = __import__(module) - for part in string.split(module,'.')[1:]: + for part in module.split('.')[1:]: self.module = getattr(self.module, part) else: self.module = module -- cgit v1.2.1 From 20b796f4e737a05b105bfd5e25dcaaba2ab97c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 23:01:09 +0100 Subject: Add cmp() for compatibility with python2 --- test/munittest.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 54d9a32..f573821 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -107,6 +107,12 @@ import traceback import os import types +try: + cmp +except NameError: + def cmp(a, b): + return (a > b) - (a < b) + ############################################################################## # Exported classes and functions ############################################################################## -- cgit v1.2.1 From ba45a7987c2fe3982a5d22b3df913c946ff1ab0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 23:31:29 +0100 Subject: Use six.{class,integer}_types to hide python2/python3 differences --- test/munittest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index f573821..6cb01cf 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -107,6 +107,8 @@ import traceback import os import types +from six import class_types + try: cmp except NameError: @@ -586,7 +588,7 @@ class TestLoader: tests = [] for name in dir(module): obj = getattr(module, name) - if (isinstance(obj, (type, types.ClassType)) and + if (isinstance(obj, class_types) and issubclass(obj, TestCase) and not obj in [TestCase, FunctionTestCase]): tests.append(self.loadTestsFromTestCase(obj)) @@ -625,7 +627,7 @@ class TestLoader: import unittest if isinstance(obj, types.ModuleType): return self.loadTestsFromModule(obj) - elif (isinstance(obj, (type, types.ClassType)) and + elif (isinstance(obj, class_types) and issubclass(obj, unittest.TestCase)): return self.loadTestsFromTestCase(obj) elif isinstance(obj, types.UnboundMethodType): -- cgit v1.2.1 From ff2bc666887f4de880996fe4892ee26c788a7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Feb 2019 23:32:16 +0100 Subject: Drop support for custom sorting of test cases This probably wasn't used, and is hard to keep compatible under python3. --- test/munittest.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 6cb01cf..e524a25 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -653,18 +653,16 @@ class TestLoader: def getTestCaseNames(self, testCaseClass): """Return a sorted sequence of method names found within testCaseClass """ - testFnNames = filter(lambda n,p=self.testMethodPrefix: n[:len(p)] == p, - dir(testCaseClass)) + testFnNames = [n for n in dir(testCaseClass) + if n.startswith(self.testMethodPrefix)] + for baseclass in testCaseClass.__bases__: for testFnName in self.getTestCaseNames(baseclass): if testFnName not in testFnNames: # handle overridden methods testFnNames.append(testFnName) - if self.sortTestMethodsUsing: - testFnNames.sort(self.sortTestMethodsUsing) + testFnNames.sort() return testFnNames - - defaultTestLoader = TestLoader() -- cgit v1.2.1 From 699e75daefdb9b75038e75bff850319e4165bd40 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Tue, 12 Feb 2019 08:27:51 +0100 Subject: Use unittest instead of custom boilerplate code --- test/munittest.py | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index e524a25..f99b0d9 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -106,6 +106,7 @@ import sys import traceback import os import types +import unittest from six import class_types @@ -206,7 +207,7 @@ class TestResult: len(self.failures)) -class TestCase: +class TestCase(unittest.TestCase): """A class whose instances are single test cases. By default, the test code itself should be placed in a method named @@ -249,27 +250,6 @@ class TestCase: interrupt_skips = 0 - def __init__(self, methodName='runTest'): - """Create an instance of the class that will use the named test - method when executed. Raises a ValueError if the instance does - not have a method with the specified name. - """ - try: - self._testMethodName = methodName - testMethod = getattr(self, methodName) - self._testMethodDoc = testMethod.__doc__ - except AttributeError: - raise ValueError("no such test method in %s: %s" % \ - (self.__class__, methodName)) - - def setUp(self): - "Hook method for setting up the test fixture before exercising it." - pass - - def tearDown(self): - "Hook method for deconstructing the test fixture after testing it." - pass - def countTestCases(self): return 1 @@ -296,9 +276,6 @@ class TestCase: return "<%s testMethod=%s>" % \ (_strclass(self.__class__), self._testMethodName) - def run(self, result=None): - return self(result) - def __call__(self, result=None): if result is None: result = self.defaultTestResult() result.startTest(self) -- cgit v1.2.1 From dfcee1393714dde8761833ca13aa302309d124eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 12 Feb 2019 21:57:24 +0100 Subject: Apply 'methodattrs' fixer Just a cleanup. --- test/munittest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index f99b0d9..2a7eaf8 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -608,7 +608,7 @@ class TestLoader: issubclass(obj, unittest.TestCase)): return self.loadTestsFromTestCase(obj) elif isinstance(obj, types.UnboundMethodType): - return obj.im_class(obj.__name__) + return obj.__self__.__class__(obj.__name__) elif callable(obj): test = obj() if not isinstance(test, unittest.TestCase) and \ -- cgit v1.2.1 From 2ca83d087d32a4a30597af0e60d7927c64f46153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 24 Feb 2019 10:44:53 +0100 Subject: Replace some type() with specific class names We know what the types of basic types are, let's just put that directly in the code. It seems more idiomatic and slightly more efficient to do things this way. --- test/munittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index 2a7eaf8..e41d7c9 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -108,7 +108,7 @@ import os import types import unittest -from six import class_types +from six import class_types, string_types try: cmp @@ -846,7 +846,7 @@ Examples: """ def __init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=defaultTestLoader): - if isinstance(module, type('')): + if isinstance(module, string_types): self.module = __import__(module) for part in module.split('.')[1:]: self.module = getattr(self.module, part) -- cgit v1.2.1 From b3bf754bc371c60f95fac2b9ad503653022b79d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 24 Feb 2019 10:57:10 +0100 Subject: Drop some unnecessary continuation backslashes When the expression is already in parentheses, the backslash has no effect. --- test/munittest.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/munittest.py') diff --git a/test/munittest.py b/test/munittest.py index e41d7c9..5fdf6f6 100644 --- a/test/munittest.py +++ b/test/munittest.py @@ -556,7 +556,7 @@ class TestLoader: instance_list = map(testCaseClass, name_list) description = getattr(testCaseClass, '__doc__') \ or testCaseClass.__name__ - description = (description.splitlines()[0]).strip() + description = description.splitlines()[0].strip() suite = self.suiteClass(instance_list, description) return suite @@ -611,8 +611,7 @@ class TestLoader: return obj.__self__.__class__(obj.__name__) elif callable(obj): test = obj() - if not isinstance(test, unittest.TestCase) and \ - not isinstance(test, unittest.TestSuite): + if not isinstance(test, (unittest.TestCase, unittest.TestSuite)): raise ValueError("calling %s returned %s, not a test" % (obj,test)) return test else: @@ -802,8 +801,8 @@ class TextTestRunner: self.stream.writeln() if not result.wasSuccessful(): self.stream.write("FAILED (") - failed, errored, skipped = map(len, \ - (result.failures, result.errors, result.skipped)) + failed, errored, skipped = map(len, + (result.failures, result.errors, result.skipped)) if failed: self.stream.write("failures=%d" % failed) if errored: -- cgit v1.2.1