Skip to content

Commit 673bf2e

Browse files
author
deathaxe
authored
Tweak runners (#246)
This commit ... 1. applies some formal changes 2. assigns `finished` flag of DeferedTestRunner within `_stop_testing()` method.
1 parent 05c8dde commit 673bf2e

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

unittesting.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// do not copy
22
{
3-
"coverage_on_worker_thread": true,
3+
"coverage_on_worker_thread": true,
44
"reload_package_on_testing": false,
55
"show_reload_progress": false,
66
}

unittesting/core/py33/case.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from functools import wraps
21
import sys
32
import unittest
43
import warnings
4+
from functools import wraps
55
from unittest.case import _ExpectedFailure, _UnexpectedSuccess, SkipTest, _Outcome
66
from ...utils import isiterable
77

unittesting/core/py33/runner.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from functools import partial
1+
import sublime
22
import time
3-
from unittest.runner import TextTestRunner, registerResult
43
import warnings
5-
import sublime
6-
7-
8-
def defer(delay, callback, *args, **kwargs):
9-
# Rely on late binding in case a user patches it
10-
sublime.set_timeout(partial(callback, *args, **kwargs), delay)
114

5+
from functools import partial
6+
from unittest.runner import TextTestRunner, registerResult
127

138
DEFAULT_CONDITION_POLL_TIME = 17
149
DEFAULT_CONDITION_TIMEOUT = 4000
@@ -18,6 +13,11 @@ def defer(delay, callback, *args, **kwargs):
1813
run_on_worker = sublime.set_timeout_async
1914

2015

16+
def defer(delay, callback, *args, **kwargs):
17+
# Rely on late binding in case a user patches it
18+
sublime.set_timeout(partial(callback, *args, **kwargs), delay)
19+
20+
2121
class DeferringTextTestRunner(TextTestRunner):
2222
"""This test runner runs tests in deferred slices."""
2323

@@ -59,7 +59,8 @@ def _start_testing():
5959
warnings.filterwarnings(
6060
'module',
6161
category=DeprecationWarning,
62-
message='Please use assert\\w+ instead.')
62+
message='Please use assert\\w+ instead.'
63+
)
6364
startTestRun = getattr(result, 'startTestRun', None)
6465
if startTestRun is not None:
6566
startTestRun()
@@ -86,21 +87,19 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
8687
elif isinstance(condition, int):
8788
defer(condition, _continue_testing, deferred)
8889
elif condition == AWAIT_WORKER:
89-
run_on_worker(
90-
partial(defer, 0, _continue_testing, deferred)
91-
)
90+
run_on_worker(partial(defer, 0, _continue_testing, deferred))
9291
else:
9392
defer(0, _continue_testing, deferred)
9493

9594
except StopIteration:
9695
_stop_testing()
97-
self.finished = True
9896

9997
except Exception as e:
10098
_handle_error(e)
10199

102100
def _wait_condition(
103-
deferred, condition,
101+
deferred,
102+
condition,
104103
period=DEFAULT_CONDITION_POLL_TIME,
105104
timeout=self.condition_timeout,
106105
start_time=None
@@ -179,4 +178,6 @@ def _stop_testing():
179178
else:
180179
self.stream.write("\n")
181180

181+
self.finished = True
182+
182183
_start_testing()

unittesting/core/py38/runner.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from functools import partial
1+
import sublime
22
import time
3-
from unittest.runner import TextTestRunner, registerResult
43
import warnings
5-
import sublime
6-
7-
8-
def defer(delay, callback, *args, **kwargs):
9-
# Rely on late binding in case a user patches it
10-
sublime.set_timeout(partial(callback, *args, **kwargs), delay)
114

5+
from functools import partial
6+
from unittest.runner import TextTestRunner, registerResult
127

138
DEFAULT_CONDITION_POLL_TIME = 17
149
DEFAULT_CONDITION_TIMEOUT = 4000
@@ -18,6 +13,11 @@ def defer(delay, callback, *args, **kwargs):
1813
run_on_worker = sublime.set_timeout_async
1914

2015

16+
def defer(delay, callback, *args, **kwargs):
17+
# Rely on late binding in case a user patches it
18+
sublime.set_timeout(partial(callback, *args, **kwargs), delay)
19+
20+
2121
class DeferringTextTestRunner(TextTestRunner):
2222
"""This test runner runs tests in deferred slices."""
2323

@@ -59,9 +59,11 @@ def _start_testing():
5959
# noisy. The -Wd and -Wa flags can be used to bypass this
6060
# only when self.warnings is None.
6161
if self.warnings in ['default', 'always']:
62-
warnings.filterwarnings('module',
63-
category=DeprecationWarning,
64-
message=r'Please use assert\w+ instead.')
62+
warnings.filterwarnings(
63+
'module',
64+
category=DeprecationWarning,
65+
message=r'Please use assert\w+ instead.'
66+
)
6567
startTestRun = getattr(result, 'startTestRun', None)
6668
if startTestRun is not None:
6769
startTestRun()
@@ -87,21 +89,19 @@ def _continue_testing(deferred, send_value=None, throw_value=None):
8789
elif isinstance(condition, int):
8890
defer(condition, _continue_testing, deferred)
8991
elif condition == AWAIT_WORKER:
90-
run_on_worker(
91-
partial(defer, 0, _continue_testing, deferred)
92-
)
92+
run_on_worker(partial(defer, 0, _continue_testing, deferred))
9393
else:
9494
defer(0, _continue_testing, deferred)
9595

9696
except StopIteration:
9797
_stop_testing()
98-
self.finished = True
9998

10099
except Exception as e:
101100
_handle_error(e)
102101

103102
def _wait_condition(
104-
deferred, condition,
103+
deferred,
104+
condition,
105105
period=DEFAULT_CONDITION_POLL_TIME,
106106
timeout=self.condition_timeout,
107107
start_time=None
@@ -180,4 +180,6 @@ def _stop_testing():
180180
else:
181181
self.stream.write("\n")
182182

183+
self.finished = True
184+
183185
_start_testing()

0 commit comments

Comments
 (0)