commit: 7fced72de7ab6d17cb1b87b9b3fe7152ce2470ef Author: Manuel RĂ¼ger <mrueg <AT> gentoo <DOT> org> AuthorDate: Mon Oct 15 12:05:15 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sun Oct 28 17:09:41 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7fced72d
tests: Drop unittest skip shim Python 2.6 is long gone, so clean up the code here Closes: https://github.com/gentoo/portage/pull/378 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/tests/__init__.py | 36 ++++------------------------------- repoman/lib/repoman/tests/__init__.py | 34 +++------------------------------ 2 files changed, 7 insertions(+), 63 deletions(-) diff --git a/lib/portage/tests/__init__.py b/lib/portage/tests/__init__.py index e149b5c0c..84341ddae 100644 --- a/lib/portage/tests/__init__.py +++ b/lib/portage/tests/__init__.py @@ -9,18 +9,7 @@ import sys import time import unittest -try: - from unittest.runner import _TextTestResult # new in python-2.7 -except ImportError: - from unittest import _TextTestResult - -try: - # They added the skip framework to python-2.7. - # Drop this once we drop python-2.6 support. - unittest_skip_shims = False - import unittest.SkipTest as SkipTest # new in python-2.7 -except ImportError: - unittest_skip_shims = True +from unittest.runner import TextTestResult as _TextTestResult import portage from portage import os @@ -148,7 +137,7 @@ def getTests(path, base_path): class TextTestResult(_TextTestResult): """ - We need a subclass of unittest._TextTestResult to handle tests with TODO + We need a subclass of unittest.runner.TextTestResult to handle tests with TODO This just adds an addTodo method that can be used to add tests that are marked TODO; these can be displayed later @@ -213,7 +202,7 @@ class TestCase(unittest.TestCase): self.setUp() except KeyboardInterrupt: raise - except SkipTest: + except unittest.SkipTest: raise except Exception: result.addError(self, sys.exc_info()) @@ -221,7 +210,7 @@ class TestCase(unittest.TestCase): testMethod() ok = True - except SkipTest as e: + except unittest.SkipTest as e: result.addPortageSkip(self, "%s: SKIP: %s" % (testMethod, str(e))) except self.failureException: @@ -292,23 +281,6 @@ class TestCase(unittest.TestCase): if os.path.exists(path): raise self.failureException('path exists when it should not: %s' % path) -if unittest_skip_shims: - # Shim code for <python-2.7. - class SkipTest(Exception): - """unittest.SkipTest shim for <python-2.7""" - - def skipTest(self, reason): - raise SkipTest(reason) - setattr(TestCase, 'skipTest', skipTest) - - def assertIn(self, member, container, msg=None): - self.assertTrue(member in container, msg=msg) - setattr(TestCase, 'assertIn', assertIn) - - def assertNotIn(self, member, container, msg=None): - self.assertFalse(member in container, msg=msg) - setattr(TestCase, 'assertNotIn', assertNotIn) - class TextTestRunner(unittest.TextTestRunner): """ We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable diff --git a/repoman/lib/repoman/tests/__init__.py b/repoman/lib/repoman/tests/__init__.py index d57ca9b10..48c52c499 100644 --- a/repoman/lib/repoman/tests/__init__.py +++ b/repoman/lib/repoman/tests/__init__.py @@ -9,18 +9,7 @@ import sys import time import unittest -try: - from unittest.runner import _TextTestResult # new in python-2.7 -except ImportError: - from unittest import _TextTestResult - -try: - # They added the skip framework to python-2.7. - # Drop this once we drop python-2.6 support. - unittest_skip_shims = False - import unittest.SkipTest as SkipTest # new in python-2.7 -except ImportError: - unittest_skip_shims = True +from unittest.runner import TextTestResult as _TextTestResult import repoman from repoman import REPOMAN_BASE_PATH @@ -152,7 +141,7 @@ def getTests(path, base_path): class TextTestResult(_TextTestResult): """ - We need a subclass of unittest._TextTestResult to handle tests with TODO + We need a subclass of unittest.runner.TextTestResult to handle tests with TODO This just adds an addTodo method that can be used to add tests that are marked TODO; these can be displayed later @@ -225,7 +214,7 @@ class TestCase(unittest.TestCase): try: testMethod() ok = True - except SkipTest as e: + except unittest.SkipTest as e: result.addPortageSkip(self, "%s: SKIP: %s" % (testMethod, str(e))) except self.failureException: @@ -296,23 +285,6 @@ class TestCase(unittest.TestCase): if os.path.exists(path): raise self.failureException('path exists when it should not: %s' % path) -if unittest_skip_shims: - # Shim code for <python-2.7. - class SkipTest(Exception): - """unittest.SkipTest shim for <python-2.7""" - - def skipTest(self, reason): - raise SkipTest(reason) - setattr(TestCase, 'skipTest', skipTest) - - def assertIn(self, member, container, msg=None): - self.assertTrue(member in container, msg=msg) - setattr(TestCase, 'assertIn', assertIn) - - def assertNotIn(self, member, container, msg=None): - self.assertFalse(member in container, msg=msg) - setattr(TestCase, 'assertNotIn', assertNotIn) - class TextTestRunner(unittest.TextTestRunner): """ We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable
