1 |
commit: 7fced72de7ab6d17cb1b87b9b3fe7152ce2470ef |
2 |
Author: Manuel RĂ¼ger <mrueg <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Oct 15 12:05:15 2018 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Oct 28 17:09:41 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7fced72d |
7 |
|
8 |
tests: Drop unittest skip shim |
9 |
|
10 |
Python 2.6 is long gone, so clean up the code here |
11 |
|
12 |
Closes: https://github.com/gentoo/portage/pull/378 |
13 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
14 |
|
15 |
lib/portage/tests/__init__.py | 36 ++++------------------------------- |
16 |
repoman/lib/repoman/tests/__init__.py | 34 +++------------------------------ |
17 |
2 files changed, 7 insertions(+), 63 deletions(-) |
18 |
|
19 |
diff --git a/lib/portage/tests/__init__.py b/lib/portage/tests/__init__.py |
20 |
index e149b5c0c..84341ddae 100644 |
21 |
--- a/lib/portage/tests/__init__.py |
22 |
+++ b/lib/portage/tests/__init__.py |
23 |
@@ -9,18 +9,7 @@ import sys |
24 |
import time |
25 |
import unittest |
26 |
|
27 |
-try: |
28 |
- from unittest.runner import _TextTestResult # new in python-2.7 |
29 |
-except ImportError: |
30 |
- from unittest import _TextTestResult |
31 |
- |
32 |
-try: |
33 |
- # They added the skip framework to python-2.7. |
34 |
- # Drop this once we drop python-2.6 support. |
35 |
- unittest_skip_shims = False |
36 |
- import unittest.SkipTest as SkipTest # new in python-2.7 |
37 |
-except ImportError: |
38 |
- unittest_skip_shims = True |
39 |
+from unittest.runner import TextTestResult as _TextTestResult |
40 |
|
41 |
import portage |
42 |
from portage import os |
43 |
@@ -148,7 +137,7 @@ def getTests(path, base_path): |
44 |
|
45 |
class TextTestResult(_TextTestResult): |
46 |
""" |
47 |
- We need a subclass of unittest._TextTestResult to handle tests with TODO |
48 |
+ We need a subclass of unittest.runner.TextTestResult to handle tests with TODO |
49 |
|
50 |
This just adds an addTodo method that can be used to add tests |
51 |
that are marked TODO; these can be displayed later |
52 |
@@ -213,7 +202,7 @@ class TestCase(unittest.TestCase): |
53 |
self.setUp() |
54 |
except KeyboardInterrupt: |
55 |
raise |
56 |
- except SkipTest: |
57 |
+ except unittest.SkipTest: |
58 |
raise |
59 |
except Exception: |
60 |
result.addError(self, sys.exc_info()) |
61 |
@@ -221,7 +210,7 @@ class TestCase(unittest.TestCase): |
62 |
|
63 |
testMethod() |
64 |
ok = True |
65 |
- except SkipTest as e: |
66 |
+ except unittest.SkipTest as e: |
67 |
result.addPortageSkip(self, "%s: SKIP: %s" % |
68 |
(testMethod, str(e))) |
69 |
except self.failureException: |
70 |
@@ -292,23 +281,6 @@ class TestCase(unittest.TestCase): |
71 |
if os.path.exists(path): |
72 |
raise self.failureException('path exists when it should not: %s' % path) |
73 |
|
74 |
-if unittest_skip_shims: |
75 |
- # Shim code for <python-2.7. |
76 |
- class SkipTest(Exception): |
77 |
- """unittest.SkipTest shim for <python-2.7""" |
78 |
- |
79 |
- def skipTest(self, reason): |
80 |
- raise SkipTest(reason) |
81 |
- setattr(TestCase, 'skipTest', skipTest) |
82 |
- |
83 |
- def assertIn(self, member, container, msg=None): |
84 |
- self.assertTrue(member in container, msg=msg) |
85 |
- setattr(TestCase, 'assertIn', assertIn) |
86 |
- |
87 |
- def assertNotIn(self, member, container, msg=None): |
88 |
- self.assertFalse(member in container, msg=msg) |
89 |
- setattr(TestCase, 'assertNotIn', assertNotIn) |
90 |
- |
91 |
class TextTestRunner(unittest.TextTestRunner): |
92 |
""" |
93 |
We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable |
94 |
|
95 |
diff --git a/repoman/lib/repoman/tests/__init__.py b/repoman/lib/repoman/tests/__init__.py |
96 |
index d57ca9b10..48c52c499 100644 |
97 |
--- a/repoman/lib/repoman/tests/__init__.py |
98 |
+++ b/repoman/lib/repoman/tests/__init__.py |
99 |
@@ -9,18 +9,7 @@ import sys |
100 |
import time |
101 |
import unittest |
102 |
|
103 |
-try: |
104 |
- from unittest.runner import _TextTestResult # new in python-2.7 |
105 |
-except ImportError: |
106 |
- from unittest import _TextTestResult |
107 |
- |
108 |
-try: |
109 |
- # They added the skip framework to python-2.7. |
110 |
- # Drop this once we drop python-2.6 support. |
111 |
- unittest_skip_shims = False |
112 |
- import unittest.SkipTest as SkipTest # new in python-2.7 |
113 |
-except ImportError: |
114 |
- unittest_skip_shims = True |
115 |
+from unittest.runner import TextTestResult as _TextTestResult |
116 |
|
117 |
import repoman |
118 |
from repoman import REPOMAN_BASE_PATH |
119 |
@@ -152,7 +141,7 @@ def getTests(path, base_path): |
120 |
|
121 |
class TextTestResult(_TextTestResult): |
122 |
""" |
123 |
- We need a subclass of unittest._TextTestResult to handle tests with TODO |
124 |
+ We need a subclass of unittest.runner.TextTestResult to handle tests with TODO |
125 |
|
126 |
This just adds an addTodo method that can be used to add tests |
127 |
that are marked TODO; these can be displayed later |
128 |
@@ -225,7 +214,7 @@ class TestCase(unittest.TestCase): |
129 |
try: |
130 |
testMethod() |
131 |
ok = True |
132 |
- except SkipTest as e: |
133 |
+ except unittest.SkipTest as e: |
134 |
result.addPortageSkip(self, "%s: SKIP: %s" % |
135 |
(testMethod, str(e))) |
136 |
except self.failureException: |
137 |
@@ -296,23 +285,6 @@ class TestCase(unittest.TestCase): |
138 |
if os.path.exists(path): |
139 |
raise self.failureException('path exists when it should not: %s' % path) |
140 |
|
141 |
-if unittest_skip_shims: |
142 |
- # Shim code for <python-2.7. |
143 |
- class SkipTest(Exception): |
144 |
- """unittest.SkipTest shim for <python-2.7""" |
145 |
- |
146 |
- def skipTest(self, reason): |
147 |
- raise SkipTest(reason) |
148 |
- setattr(TestCase, 'skipTest', skipTest) |
149 |
- |
150 |
- def assertIn(self, member, container, msg=None): |
151 |
- self.assertTrue(member in container, msg=msg) |
152 |
- setattr(TestCase, 'assertIn', assertIn) |
153 |
- |
154 |
- def assertNotIn(self, member, container, msg=None): |
155 |
- self.assertFalse(member in container, msg=msg) |
156 |
- setattr(TestCase, 'assertNotIn', assertNotIn) |
157 |
- |
158 |
class TextTestRunner(unittest.TextTestRunner): |
159 |
""" |
160 |
We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable |