Skip to content

Commit 29c953d

Browse files
committed
test: update test.support and test_io to 3.10
Initially this is only meant to be a small update for `test_io.py`. But it turns out that `test.support` need a lot of cleanup especially for `test.support.warnings_helper`.
1 parent e4ce0d5 commit 29c953d

37 files changed

+677
-732
lines changed

Lib/test/support/__init__.py

Lines changed: 107 additions & 488 deletions
Large diffs are not rendered by default.

Lib/test/test_asyncore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from test.support import os_helper
1414
from test.support import socket_helper
1515
from test.support import threading_helper
16+
from test.support import warnings_helper
1617
from io import BytesIO
1718

1819
if support.PGO:
@@ -421,7 +422,7 @@ def test_resource_warning(self):
421422
f = asyncore.file_wrapper(fd)
422423

423424
os.close(fd)
424-
with support.check_warnings(('', ResourceWarning)):
425+
with warnings_helper.check_warnings(('', ResourceWarning)):
425426
f = None
426427
support.gc_collect()
427428

Lib/test/test_builtin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from functools import partial
2121
from contextlib import ExitStack
2222
from operator import neg
23-
from test.support import check_warnings, swap_attr
23+
from test.support import swap_attr
24+
from test.support.warnings_helper import check_warnings
2425
from test.support.script_helper import assert_python_ok
2526
from test.support.os_helper import EnvironmentVarGuard, TESTFN, unlink
2627
from unittest.mock import MagicMock, patch

Lib/test/test_bytes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import test.support
1919
import test.string_tests
2020
import test.list_tests
21-
from test.support import bigaddrspacetest, MAX_Py_ssize_t, import_helper
21+
from test.support import bigaddrspacetest, MAX_Py_ssize_t, import_helper, warnings_helper
2222
from test.support.script_helper import assert_python_failure
2323

2424

2525
if sys.flags.bytes_warning:
2626
def check_bytes_warnings(func):
2727
@functools.wraps(func)
2828
def wrapper(*args, **kw):
29-
with test.support.check_warnings(('', BytesWarning)):
29+
with warnings_helper.check_warnings(('', BytesWarning)):
3030
return func(*args, **kw)
3131
return wrapper
3232
else:
@@ -1805,7 +1805,7 @@ def test_return_self(self):
18051805
"BytesWarning is needed for this test: use -bb option")
18061806
def test_compare(self):
18071807
def bytes_warning():
1808-
return test.support.check_warnings(('', BytesWarning))
1808+
return test.warnings_helper.check_warningswarnings(('', BytesWarning))
18091809
with bytes_warning():
18101810
b'' == ''
18111811
with bytes_warning():

Lib/test/test_codeop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import unittest
77
import warnings
88
from test import support
9+
from test.support import warnings_helper
910

1011
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
1112
import io
@@ -313,8 +314,8 @@ def test_filename(self):
313314
# TODO: RUSTPYTHON
314315
@unittest.expectedFailure
315316
def test_warning(self):
316-
# Test that the warning is only returned once.
317-
with support.check_warnings(
317+
# Teswarnings_helper.check_warningsonly returned once.
318+
with warnings_helper.check_warnings(
318319
(".*literal", SyntaxWarning),
319320
(".*invalid", DeprecationWarning),
320321
) as w:

Lib/test/test_exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
cpython_only, gc_collect,
1313
no_tracing, script_helper,
1414
SuppressCrashReport,
15-
check_warnings,)
15+
)
1616
from test.support.os_helper import TESTFN, unlink
1717
from test.support.import_helper import import_module
18+
from test.support.warnings_helper import check_warnings
1819
from test import support
1920

2021
class NaiveException(Exception):

Lib/test/test_file.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import io
88
import _pyio as pyio
99

10-
from test import support
11-
from test.support import os_helper
10+
from test.support import os_helper, warnings_helper
1211
from test.support.os_helper import TESTFN
1312
from collections import UserList
1413

@@ -189,7 +188,7 @@ def testSetBufferSize(self):
189188
# make sure that explicitly setting the buffer size doesn't cause
190189
# misbehaviour especially with repeated close() calls
191190
for s in (-1, 0, 512):
192-
with support.check_no_warnings(self,
191+
with warnings_helper.check_no_warnings(self,
193192
message='line buffering',
194193
category=RuntimeWarning):
195194
self._checkBufferSize(s)

Lib/test/test_fileio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from weakref import proxy
1010
from functools import wraps
1111

12-
from test.support import (check_warnings, run_unittest,
13-
cpython_only, swap_attr)
12+
from test.support import run_unittest, cpython_only, swap_attr
1413
from test.support.os_helper import TESTFN, TESTFN_UNICODE, make_bad_fd
14+
from test.support.warnings_helper import check_warnings
1515
from collections import UserList
1616

1717
import _io # C implementation of io

Lib/test/test_ftplib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from test import support
2323
from test.support import threading_helper
2424
from test.support import socket_helper
25+
from test.support import warnings_helper
2526
from test.support.socket_helper import HOST, HOSTv6
2627

2728
import sys
@@ -622,8 +623,8 @@ def test_storlines(self):
622623
self.assertTrue(flag)
623624

624625
f = io.StringIO(RETR_DATA.replace('\r\n', '\n'))
625-
# storlines() expects a binary file, not a text file
626-
with support.check_warnings(('', BytesWarning), quiet=True):
626+
# stowarnings_helper.check_warningsary file, not a text file
627+
with warnings_helper.check_warnings(('', BytesWarning), quiet=True):
627628
self.assertRaises(TypeError, self.client.storlines, 'stor foo', f)
628629

629630
def test_nlst(self):

Lib/test/test_genericpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def test_nonascii_abspath(self):
525525

526526
def test_join_errors(self):
527527
# Check join() raises friendly TypeErrors.
528-
from .support import check_warnings
528+
from .support.warnings_helper import check_warnings
529529
with check_warnings(('', BytesWarning), quiet=True):
530530
errmsg = "Can't mix strings and bytes in path components"
531531
with self.assertRaisesRegex(TypeError, errmsg):
@@ -546,7 +546,7 @@ def test_join_errors(self):
546546

547547
def test_relpath_errors(self):
548548
# Check relpath() raises friendly TypeErrors.
549-
from .support import check_warnings
549+
from .support.warnings_helper import check_warnings
550550
with check_warnings(('', (BytesWarning, DeprecationWarning)),
551551
quiet=True):
552552
errmsg = "Can't mix strings and bytes in path components"

0 commit comments

Comments
 (0)