Skip to content

Commit c8748bc

Browse files
committed
Fix test.support imports
1 parent ef10487 commit c8748bc

24 files changed

+113
-90
lines changed

Lib/test/lock_tests.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import weakref
1111

1212
from test import support
13+
from test.support import threading_helper
1314

1415

1516
def _wait():
@@ -31,7 +32,7 @@ def __init__(self, f, n, wait_before_exit=False):
3132
self.started = []
3233
self.finished = []
3334
self._can_exit = not wait_before_exit
34-
self.wait_thread = support.wait_threads_exit()
35+
self.wait_thread = threading_helper.wait_threads_exit()
3536
self.wait_thread.__enter__()
3637

3738
def task():
@@ -67,10 +68,10 @@ def do_finish(self):
6768

6869
class BaseTestCase(unittest.TestCase):
6970
def setUp(self):
70-
self._threads = support.threading_setup()
71+
self._threads = threading_helper.threading_setup()
7172

7273
def tearDown(self):
73-
support.threading_cleanup(*self._threads)
74+
threading_helper.threading_cleanup(*self._threads)
7475
support.reap_children()
7576

7677
def assertTimeout(self, actual, expected):
@@ -235,7 +236,7 @@ def f():
235236
lock.acquire()
236237
phase.append(None)
237238

238-
with support.wait_threads_exit():
239+
with threading_helper.wait_threads_exit():
239240
start_new_thread(f, ())
240241
while len(phase) == 0:
241242
_wait()

Lib/test/pickletester.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
from test.support import os_helper
2626
from test.support import (
2727
TestFailed, run_with_locale, no_tracing,
28-
_2G, _4G, bigmemtest, reap_threads
28+
_2G, _4G, bigmemtest
2929
)
3030
from test.support.import_helper import forget
3131
from test.support.os_helper import TESTFN
32+
from test.support import threading_helper
3233
from test.support.warnings_helper import save_restore_warnings_filters
3334

3435
from pickle import bytes_types
@@ -1378,7 +1379,7 @@ def test_truncated_data(self):
13781379
for p in badpickles:
13791380
self.check_unpickling_error(self.truncated_errors, p)
13801381

1381-
@reap_threads
1382+
@threading_helper.reap_threads
13821383
def test_unpickle_module_race(self):
13831384
# https://bugs.python.org/issue34572
13841385
locker_module = dedent("""

Lib/test/test_asynchat.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from test import support
44
from test.support import socket_helper
5+
from test.support import threading_helper
56

67

78
import asynchat
@@ -105,10 +106,10 @@ class TestAsynchat(unittest.TestCase):
105106
usepoll = False
106107

107108
def setUp(self):
108-
self._threads = support.threading_setup()
109+
self._threads = threading_helper.threading_setup()
109110

110111
def tearDown(self):
111-
support.threading_cleanup(*self._threads)
112+
threading_helper.threading_cleanup(*self._threads)
112113

113114
def line_terminator_check(self, term, server_chunk):
114115
event = threading.Event()
@@ -124,7 +125,7 @@ def line_terminator_check(self, term, server_chunk):
124125
c.push(b"I'm not dead yet!" + term)
125126
c.push(SERVER_QUIT)
126127
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
127-
support.join_thread(s, timeout=TIMEOUT)
128+
threading_helper.join_thread(s)
128129

129130
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
130131

@@ -155,7 +156,7 @@ def numeric_terminator_check(self, termlen):
155156
c.push(data)
156157
c.push(SERVER_QUIT)
157158
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
158-
support.join_thread(s, timeout=TIMEOUT)
159+
threading_helper.join_thread(s)
159160

160161
self.assertEqual(c.contents, [data[:termlen]])
161162

@@ -175,7 +176,7 @@ def test_none_terminator(self):
175176
c.push(data)
176177
c.push(SERVER_QUIT)
177178
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
178-
support.join_thread(s, timeout=TIMEOUT)
179+
threading_helper.join_thread(s)
179180

180181
self.assertEqual(c.contents, [])
181182
self.assertEqual(c.buffer, data)
@@ -187,7 +188,7 @@ def test_simple_producer(self):
187188
p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)
188189
c.push_with_producer(p)
189190
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
190-
support.join_thread(s, timeout=TIMEOUT)
191+
threading_helper.join_thread(s)
191192

192193
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
193194

@@ -197,7 +198,7 @@ def test_string_producer(self):
197198
data = b"hello world\nI'm not dead yet!\n"
198199
c.push_with_producer(data+SERVER_QUIT)
199200
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
200-
support.join_thread(s, timeout=TIMEOUT)
201+
threading_helper.join_thread(s)
201202

202203
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
203204

@@ -208,7 +209,7 @@ def test_empty_line(self):
208209
c.push(b"hello world\n\nI'm not dead yet!\n")
209210
c.push(SERVER_QUIT)
210211
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
211-
support.join_thread(s, timeout=TIMEOUT)
212+
threading_helper.join_thread(s)
212213

213214
self.assertEqual(c.contents,
214215
[b"hello world", b"", b"I'm not dead yet!"])
@@ -227,7 +228,7 @@ def test_close_when_done(self):
227228
# where the server echoes all of its data before we can check that it
228229
# got any down below.
229230
s.start_resend_event.set()
230-
support.join_thread(s, timeout=TIMEOUT)
231+
threading_helper.join_thread(s)
231232

232233
self.assertEqual(c.contents, [])
233234
# the server might have been able to send a byte or two back, but this
@@ -248,7 +249,7 @@ def test_push(self):
248249
self.assertRaises(TypeError, c.push, 'unicode')
249250
c.push(SERVER_QUIT)
250251
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
251-
support.join_thread(s, timeout=TIMEOUT)
252+
threading_helper.join_thread(s)
252253
self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])
253254

254255

Lib/test/test_asyncore.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from test import support
1313
from test.support import os_helper
1414
from test.support import socket_helper
15+
from test.support import threading_helper
1516
from io import BytesIO
1617

1718
if support.PGO:
@@ -325,7 +326,7 @@ def setUp(self):
325326
def tearDown(self):
326327
asyncore.close_all()
327328

328-
@support.reap_threads
329+
@threading_helper.reap_threads
329330
def test_send(self):
330331
evt = threading.Event()
331332
sock = socket.socket()
@@ -362,7 +363,7 @@ def test_send(self):
362363

363364
self.assertEqual(cap.getvalue(), data*2)
364365
finally:
365-
support.join_thread(t, timeout=TIMEOUT)
366+
threading_helper.join_thread(t)
366367

367368

368369
@unittest.skipUnless(hasattr(asyncore, 'file_wrapper'),
@@ -768,7 +769,7 @@ def test_set_reuse_addr(self):
768769
self.assertTrue(s.socket.getsockopt(socket.SOL_SOCKET,
769770
socket.SO_REUSEADDR))
770771

771-
@support.reap_threads
772+
@threading_helper.reap_threads
772773
def test_quick_connect(self):
773774
# see: http://bugs.python.org/issue10340
774775
if self.family not in (socket.AF_INET, getattr(socket, "AF_INET6", object())):
@@ -790,7 +791,7 @@ def test_quick_connect(self):
790791
except OSError:
791792
pass
792793
finally:
793-
support.join_thread(t, timeout=TIMEOUT)
794+
threading_helper.join_thread(t)
794795

795796
class TestAPI_UseIPv4Sockets(BaseTestAPI):
796797
family = socket.AF_INET

Lib/test/test_enum.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from enum import Enum, IntEnum, EnumMeta, Flag, IntFlag, unique, auto
99
from io import StringIO
1010
from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL
11-
from test import support
11+
from test.support import ALWAYS_EQ, check__all__, threading_helper
1212
from datetime import timedelta
1313

1414

@@ -2489,7 +2489,7 @@ class Color(StrMixin, AllMixin, Flag):
24892489
# TODO: RUSTPYTHON
24902490
@unittest.expectedFailure
24912491
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, inconsistent test result on Windows due to threading")
2492-
@support.reap_threads
2492+
@threading_helper.reap_threads
24932493
def test_unique_composite(self):
24942494
# override __eq__ to be identity only
24952495
class TestFlag(Flag):
@@ -2519,7 +2519,7 @@ def cycle_enum():
25192519
threading.Thread(target=cycle_enum)
25202520
for _ in range(8)
25212521
]
2522-
with support.start_threads(threads):
2522+
with threading_helper.start_threads(threads):
25232523
pass
25242524
# check that only 248 members were created
25252525
self.assertFalse(
@@ -2922,7 +2922,7 @@ class Color(StrMixin, AllMixin, IntFlag):
29222922
# TODO: RUSTPYTHON
29232923
@unittest.expectedFailure
29242924
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, inconsistent test result on Windows due to threading")
2925-
@support.reap_threads
2925+
@threading_helper.reap_threads
29262926
def test_unique_composite(self):
29272927
# override __eq__ to be identity only
29282928
class TestFlag(IntFlag):
@@ -2952,7 +2952,7 @@ def cycle_enum():
29522952
threading.Thread(target=cycle_enum)
29532953
for _ in range(8)
29542954
]
2955-
with support.start_threads(threads):
2955+
with threading_helper.start_threads(threads):
29562956
pass
29572957
# check that only 248 members were created
29582958
self.assertFalse(
@@ -3183,7 +3183,7 @@ def test_inspect_classify_class_attrs(self):
31833183

31843184
class MiscTestCase(unittest.TestCase):
31853185
def test__all__(self):
3186-
support.check__all__(self, enum)
3186+
check__all__(self, enum)
31873187

31883188

31893189
# These are unordered here on purpose to ensure that declaration order

Lib/test/test_ftplib.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from unittest import TestCase, skipUnless
2222
from test import support
23+
from test.support import threading_helper
2324
from test.support import socket_helper
2425
from test.support.socket_helper import HOST, HOSTv6
2526

@@ -1094,11 +1095,11 @@ def test_main():
10941095
TestTLS_FTPClassMixin, TestTLS_FTPClass,
10951096
MiscTestCase]
10961097

1097-
thread_info = support.threading_setup()
1098+
thread_info = threading_helper.threading_setup()
10981099
try:
10991100
support.run_unittest(*tests)
11001101
finally:
1101-
support.threading_cleanup(*thread_info)
1102+
threading_helper.threading_cleanup(*thread_info)
11021103

11031104

11041105
if __name__ == '__main__':

Lib/test/test_functools.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from random import choice
99
import sys
1010
from test import support
11-
from test.support import import_helper
1211
import threading
1312
import time
1413
import typing
@@ -17,6 +16,9 @@
1716
from weakref import proxy
1817
import contextlib
1918

19+
from test.support import import_helper
20+
from test.support import threading_helper
21+
2022
import functools
2123

2224
py_functools = import_helper.import_fresh_module('functools', blocked=['_functools'])
@@ -1570,7 +1572,7 @@ def clear():
15701572
# create n threads in order to fill cache
15711573
threads = [threading.Thread(target=full, args=[k])
15721574
for k in range(n)]
1573-
with support.start_threads(threads):
1575+
with threading_helper.start_threads(threads):
15741576
start.set()
15751577

15761578
hits, misses, maxsize, currsize = f.cache_info()
@@ -1588,7 +1590,7 @@ def clear():
15881590
threads += [threading.Thread(target=full, args=[k])
15891591
for k in range(n)]
15901592
start.clear()
1591-
with support.start_threads(threads):
1593+
with threading_helper.start_threads(threads):
15921594
start.set()
15931595
finally:
15941596
sys.setswitchinterval(orig_si)
@@ -1610,7 +1612,7 @@ def test():
16101612
self.assertEqual(f(i), 3 * i)
16111613
stop.wait(10)
16121614
threads = [threading.Thread(target=test) for k in range(n)]
1613-
with support.start_threads(threads):
1615+
with threading_helper.start_threads(threads):
16141616
for i in range(m):
16151617
start.wait(10)
16161618
stop.reset()
@@ -1630,7 +1632,7 @@ def test(i, x):
16301632
self.assertEqual(f(x), 3 * x, i)
16311633
threads = [threading.Thread(target=test, args=(i, v))
16321634
for i, v in enumerate([1, 2, 2, 3, 2])]
1633-
with support.start_threads(threads):
1635+
with threading_helper.start_threads(threads):
16341636
pass
16351637

16361638
def test_need_for_rlock(self):
@@ -2526,7 +2528,7 @@ def test_threaded(self):
25262528
threading.Thread(target=lambda: item.cost)
25272529
for k in range(num_threads)
25282530
]
2529-
with support.start_threads(threads):
2531+
with threading_helper.start_threads(threads):
25302532
go.set()
25312533
finally:
25322534
sys.setswitchinterval(orig_si)

Lib/test/test_hashlib.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from test import support
2121
from test.support import _4G, bigmemtest
2222
from test.support.import_helper import import_fresh_module
23+
from test.support import threading_helper
2324
from http.client import HTTPException
2425

2526
# Were we compiled --with-pydebug or with #define Py_DEBUG?
@@ -898,7 +899,7 @@ def test_gil(self):
898899
'1cfceca95989f51f658e3f3ffe7f1cd43726c9e088c13ee10b46f57cef135b94'
899900
)
900901

901-
@support.reap_threads
902+
@threading_helper.reap_threads
902903
def test_threaded_hashing(self):
903904
# Updating the same hash object from several threads at once
904905
# using data chunk sizes containing the same byte sequences.

Lib/test/test_httpservers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import unittest
3131
from test import support
3232
from test.support import os_helper
33+
from test.support import threading_helper
3334

3435

3536
class NoLogRequestHandler:
@@ -64,7 +65,7 @@ def stop(self):
6465

6566
class BaseTestCase(unittest.TestCase):
6667
def setUp(self):
67-
self._threads = support.threading_setup()
68+
self._threads = threading_helper.threading_setup()
6869
os.environ = os_helper.EnvironmentVarGuard()
6970
self.server_started = threading.Event()
7071
self.thread = TestServerThread(self, self.request_handler)
@@ -75,7 +76,7 @@ def tearDown(self):
7576
self.thread.stop()
7677
self.thread = None
7778
os.environ.__exit__()
78-
support.threading_cleanup(*self._threads)
79+
threading_helper.threading_cleanup(*self._threads)
7980

8081
def request(self, uri, method='GET', body=None, headers={}):
8182
self.connection = http.client.HTTPConnection(self.HOST, self.PORT)

0 commit comments

Comments
 (0)