Skip to content

Commit abbb629

Browse files
author
deathaxe
authored
Reformat using black (#260)
1 parent 15f9f73 commit abbb629

13 files changed

+198
-143
lines changed

unittesting/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"tests_dir": "tests",
1515
"pattern": "test*.py",
1616
# runner
17-
"async": False, # deprecated
17+
"async": False, # deprecated
1818
"deferred": True,
1919
"condition_timeout": 4000,
2020
"failfast": False,
@@ -26,7 +26,7 @@
2626
"reload_package_on_testing": True,
2727
# coverage
2828
"coverage": False,
29-
"coverage_on_worker_thread": False, # experimental
29+
"coverage_on_worker_thread": False, # experimental
3030
"generate_html_report": False,
3131
"generate_xml_report": False,
3232
}

unittesting/core/py33/case.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313
from .runner import defer
1414

15-
__all__ = [
16-
"DeferrableTestCase",
17-
"expectedFailure"
18-
]
15+
__all__ = ["DeferrableTestCase", "expectedFailure"]
1916

2017

2118
def expectedFailure(func):
@@ -28,6 +25,7 @@ def wrapper(*args, **kwargs):
2825
except Exception:
2926
raise _ExpectedFailure(sys.exc_info())
3027
raise _UnexpectedSuccess
28+
3129
return wrapper
3230

3331

@@ -72,19 +70,21 @@ def run(self, result=None):
7270
orig_result = result
7371
if result is None:
7472
result = self.defaultTestResult()
75-
startTestRun = getattr(result, 'startTestRun', None)
73+
startTestRun = getattr(result, "startTestRun", None)
7674
if startTestRun is not None:
7775
startTestRun()
7876

7977
result.startTest(self)
8078

8179
testMethod = getattr(self, self._testMethodName)
82-
if getattr(self.__class__, "__unittest_skip__", False) or \
83-
getattr(testMethod, "__unittest_skip__", False):
80+
if getattr(self.__class__, "__unittest_skip__", False) or getattr(
81+
testMethod, "__unittest_skip__", False
82+
):
8483
# If the class or method was skipped.
8584
try:
86-
skip_why = getattr(self.__class__, '__unittest_skip_why__', '') or \
87-
getattr(testMethod, '__unittest_skip_why__', '')
85+
skip_why = getattr(
86+
self.__class__, "__unittest_skip_why__", ""
87+
) or getattr(testMethod, "__unittest_skip_why__", "")
8888
self._addSkip(result, skip_why)
8989
finally:
9090
result.stopTest(self)
@@ -109,29 +109,31 @@ def run(self, result=None):
109109
for exc_info in outcome.failures:
110110
result.addFailure(self, exc_info)
111111
if outcome.unexpectedSuccess is not None:
112-
addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
112+
addUnexpectedSuccess = getattr(result, "addUnexpectedSuccess", None)
113113
if addUnexpectedSuccess is not None:
114114
addUnexpectedSuccess(self)
115115
else:
116116
warnings.warn(
117117
"TestResult has no addUnexpectedSuccess method, reporting as failures",
118-
RuntimeWarning)
118+
RuntimeWarning,
119+
)
119120
result.addFailure(self, outcome.unexpectedSuccess)
120121

121122
if outcome.expectedFailure is not None:
122-
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
123+
addExpectedFailure = getattr(result, "addExpectedFailure", None)
123124
if addExpectedFailure is not None:
124125
addExpectedFailure(self, outcome.expectedFailure)
125126
else:
126127
warnings.warn(
127128
"TestResult has no addExpectedFailure method, reporting as passes",
128-
RuntimeWarning)
129+
RuntimeWarning,
130+
)
129131
result.addSuccess(self)
130132
return result
131133
finally:
132134
result.stopTest(self)
133135
if orig_result is None:
134-
stopTestRun = getattr(result, 'stopTestRun', None)
136+
stopTestRun = getattr(result, "stopTestRun", None)
135137
if stopTestRun is not None:
136138
stopTestRun()
137139

unittesting/core/py33/runner.py

+39-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
DEFAULT_CONDITION_POLL_TIME = 17
1010
DEFAULT_CONDITION_TIMEOUT = 4000
11-
AWAIT_WORKER = 'AWAIT_WORKER'
11+
AWAIT_WORKER = "AWAIT_WORKER"
1212
# Extract `set_timeout_async`, t.i. *avoid* late binding, in case a user
1313
# patches it
1414
run_on_worker = sublime.set_timeout_async
@@ -34,7 +34,8 @@ def __init__(
3434
condition_timeout=DEFAULT_CONDITION_TIMEOUT,
3535
):
3636
super(DeferringTextTestRunner, self).__init__(
37-
stream, descriptions, verbosity, failfast, buffer, resultclass, warnings)
37+
stream, descriptions, verbosity, failfast, buffer, resultclass, warnings
38+
)
3839
self.condition_timeout = condition_timeout
3940

4041
def run(self, test):
@@ -56,13 +57,13 @@ def _start_testing():
5657
# no more than once per module, because they can be fairly
5758
# noisy. The -Wd and -Wa flags can be used to bypass this
5859
# only when self.warnings is None.
59-
if self.warnings in ['default', 'always']:
60+
if self.warnings in ["default", "always"]:
6061
warnings.filterwarnings(
61-
'module',
62+
"module",
6263
category=DeprecationWarning,
63-
message='Please use assert\\w+ instead.'
64+
message="Please use assert\\w+ instead.",
6465
)
65-
startTestRun = getattr(result, 'startTestRun', None)
66+
startTestRun = getattr(result, "startTestRun", None)
6667
if startTestRun is not None:
6768
startTestRun()
6869
try:
@@ -81,8 +82,11 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
8182

8283
if callable(condition):
8384
defer(0, _wait_condition, deferred, condition)
84-
elif isinstance(condition, dict) and "condition" in condition and \
85-
callable(condition["condition"]):
85+
elif (
86+
isinstance(condition, dict)
87+
and "condition" in condition
88+
and callable(condition["condition"])
89+
):
8690
period = condition.get("period", DEFAULT_CONDITION_POLL_TIME)
8791
defer(period, _wait_condition, deferred, **condition)
8892
elif isinstance(condition, int):
@@ -103,7 +107,7 @@ def _wait_condition(
103107
condition,
104108
period=DEFAULT_CONDITION_POLL_TIME,
105109
timeout=self.condition_timeout,
106-
start_time=None
110+
start_time=None,
107111
):
108112
if start_time is None:
109113
start_time = time.time()
@@ -118,41 +122,56 @@ def _wait_condition(
118122
_continue_testing(deferred, send_value=send_value)
119123
elif (time.time() - start_time) * 1000 >= timeout:
120124
error = TimeoutError(
121-
'Condition not fulfilled within {:.2f} seconds'
122-
.format(timeout / 1000)
125+
"Condition not fulfilled within {:.2f} seconds".format(
126+
timeout / 1000
127+
)
123128
)
124129
_continue_testing(deferred, throw_value=error)
125130
else:
126-
defer(period, _wait_condition, deferred, condition, period, timeout, start_time)
131+
defer(
132+
period,
133+
_wait_condition,
134+
deferred,
135+
condition,
136+
period,
137+
timeout,
138+
start_time,
139+
)
127140

128141
def _handle_error(e):
129-
stopTestRun = getattr(result, 'stopTestRun', None)
142+
stopTestRun = getattr(result, "stopTestRun", None)
130143
if stopTestRun is not None:
131144
stopTestRun()
132145
self.finished = True
133146
raise e
134147

135148
def _stop_testing():
136149
with warnings.catch_warnings():
137-
stopTestRun = getattr(result, 'stopTestRun', None)
150+
stopTestRun = getattr(result, "stopTestRun", None)
138151
if stopTestRun is not None:
139152
stopTestRun()
140153

141154
stopTime = time.time()
142155
timeTaken = stopTime - startTime
143156
result.printErrors()
144-
if hasattr(result, 'separator2'):
157+
if hasattr(result, "separator2"):
145158
self.stream.writeln(result.separator2)
146159
run = result.testsRun
147-
self.stream.writeln("Ran %d test%s in %.3fs" %
148-
(run, run != 1 and "s" or "", timeTaken))
160+
self.stream.writeln(
161+
"Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken)
162+
)
149163
self.stream.writeln()
150164

151165
expectedFails = unexpectedSuccesses = skipped = 0
152166
try:
153-
results = map(len, (result.expectedFailures,
154-
result.unexpectedSuccesses,
155-
result.skipped))
167+
results = map(
168+
len,
169+
(
170+
result.expectedFailures,
171+
result.unexpectedSuccesses,
172+
result.skipped,
173+
),
174+
)
156175
except AttributeError:
157176
pass
158177
else:

unittesting/core/py33/suite.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DeferrableTestSuite(TestSuite):
1111

1212
def run(self, result, debug=False):
1313
topLevel = False
14-
if getattr(result, '_testRunEntered', False) is False:
14+
if getattr(result, "_testRunEntered", False) is False:
1515
result._testRunEntered = topLevel = True
1616

1717
for test in self:
@@ -31,8 +31,9 @@ def run(self, result, debug=False):
3131
yield
3232
result._previousTestClass = test.__class__
3333

34-
if getattr(test.__class__, '_classSetupFailed', False) or \
35-
getattr(result, '_moduleSetUpFailed', False):
34+
if getattr(test.__class__, "_classSetupFailed", False) or getattr(
35+
result, "_moduleSetUpFailed", False
36+
):
3637
continue
3738

3839
if not debug:
@@ -56,7 +57,7 @@ def run(self, result, debug=False):
5657
result._testRunEntered = False
5758

5859
def _handleClassSetUp(self, test, result):
59-
previousClass = getattr(result, '_previousTestClass', None)
60+
previousClass = getattr(result, "_previousTestClass", None)
6061
currentClass = test.__class__
6162
if currentClass == previousClass:
6263
return
@@ -72,9 +73,9 @@ def _handleClassSetUp(self, test, result):
7273
# so its class will be a builtin-type
7374
pass
7475

75-
setUpClass = getattr(currentClass, 'setUpClass', None)
76+
setUpClass = getattr(currentClass, "setUpClass", None)
7677
if setUpClass is not None:
77-
_call_if_exists(result, '_setupStdout')
78+
_call_if_exists(result, "_setupStdout")
7879
try:
7980
deferred = setUpClass()
8081
if isinstance(deferred, DeferrableMethod):
@@ -84,26 +85,26 @@ def _handleClassSetUp(self, test, result):
8485
raise
8586
currentClass._classSetupFailed = True
8687
className = util.strclass(currentClass)
87-
errorName = 'setUpClass (%s)' % className
88+
errorName = "setUpClass (%s)" % className
8889
self._addClassOrModuleLevelException(result, e, errorName)
8990
finally:
90-
_call_if_exists(result, '_restoreStdout')
91+
_call_if_exists(result, "_restoreStdout")
9192

9293
def _tearDownPreviousClass(self, test, result):
93-
previousClass = getattr(result, '_previousTestClass', None)
94+
previousClass = getattr(result, "_previousTestClass", None)
9495
currentClass = test.__class__
9596
if currentClass == previousClass:
9697
return
97-
if getattr(previousClass, '_classSetupFailed', False):
98+
if getattr(previousClass, "_classSetupFailed", False):
9899
return
99-
if getattr(result, '_moduleSetUpFailed', False):
100+
if getattr(result, "_moduleSetUpFailed", False):
100101
return
101102
if getattr(previousClass, "__unittest_skip__", False):
102103
return
103104

104-
tearDownClass = getattr(previousClass, 'tearDownClass', None)
105+
tearDownClass = getattr(previousClass, "tearDownClass", None)
105106
if tearDownClass is not None:
106-
_call_if_exists(result, '_setupStdout')
107+
_call_if_exists(result, "_setupStdout")
107108
try:
108109
deferred = tearDownClass()
109110
if isinstance(deferred, DeferrableMethod):
@@ -112,7 +113,7 @@ def _tearDownPreviousClass(self, test, result):
112113
if isinstance(result, _DebugResult):
113114
raise
114115
className = util.strclass(previousClass)
115-
errorName = 'tearDownClass (%s)' % className
116+
errorName = "tearDownClass (%s)" % className
116117
self._addClassOrModuleLevelException(result, e, errorName)
117118
finally:
118-
_call_if_exists(result, '_restoreStdout')
119+
_call_if_exists(result, "_restoreStdout")

unittesting/core/py38/case.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
from .runner import defer
99

10-
__all__ = [
11-
"DeferrableTestCase",
12-
"expectedFailure"
13-
]
10+
__all__ = ["DeferrableTestCase", "expectedFailure"]
1411

1512

1613
class DeferrableTestCase(TestCase):
@@ -43,27 +40,29 @@ def run(self, result=None):
4340
orig_result = result
4441
if result is None:
4542
result = self.defaultTestResult()
46-
startTestRun = getattr(result, 'startTestRun', None)
43+
startTestRun = getattr(result, "startTestRun", None)
4744
if startTestRun is not None:
4845
startTestRun()
4946

5047
result.startTest(self)
5148

5249
testMethod = getattr(self, self._testMethodName)
53-
if (getattr(self.__class__, "__unittest_skip__", False) or
54-
getattr(testMethod, "__unittest_skip__", False)):
50+
if getattr(self.__class__, "__unittest_skip__", False) or getattr(
51+
testMethod, "__unittest_skip__", False
52+
):
5553
# If the class or method was skipped.
5654
try:
57-
skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
58-
or getattr(testMethod, '__unittest_skip_why__', ''))
55+
skip_why = getattr(
56+
self.__class__, "__unittest_skip_why__", ""
57+
) or getattr(testMethod, "__unittest_skip_why__", "")
5958
self._addSkip(result, self, skip_why)
6059
finally:
6160
result.stopTest(self)
6261
return
63-
expecting_failure_method = getattr(testMethod,
64-
"__unittest_expecting_failure__", False)
65-
expecting_failure_class = getattr(self,
66-
"__unittest_expecting_failure__", False)
62+
expecting_failure_method = getattr(
63+
testMethod, "__unittest_expecting_failure__", False
64+
)
65+
expecting_failure_class = getattr(self, "__unittest_expecting_failure__", False)
6766
expecting_failure = expecting_failure_class or expecting_failure_method
6867
outcome = _Outcome(result)
6968
try:
@@ -103,7 +102,7 @@ def run(self, result=None):
103102
finally:
104103
result.stopTest(self)
105104
if orig_result is None:
106-
stopTestRun = getattr(result, 'stopTestRun', None)
105+
stopTestRun = getattr(result, "stopTestRun", None)
107106
if stopTestRun is not None:
108107
stopTestRun()
109108

0 commit comments

Comments
 (0)