Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a089d21

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21315)
1 parent 883bc63 commit a089d21

20 files changed

Lines changed: 69 additions & 49 deletions

Lib/ctypes/test/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
import unittest
33
from test import support
4+
from test.support import import_helper
5+
46

57
# skip tests if _ctypes was not built
6-
ctypes = support.import_module('ctypes')
8+
ctypes = import_helper.import_module('ctypes')
79
ctypes_symbols = dir(ctypes)
810

911
def need_symbol(name):

Lib/ctypes/test/test_find.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os.path
33
import sys
44
import test.support
5+
from test.support import os_helper
56
from ctypes import *
67
from ctypes.util import find_library
78

@@ -65,8 +66,8 @@ def test_gle(self):
6566
self.gle.gleGetJoinStyle
6667

6768
def test_shell_injection(self):
68-
result = find_library('; echo Hello shell > ' + test.support.TESTFN)
69-
self.assertFalse(os.path.lexists(test.support.TESTFN))
69+
result = find_library('; echo Hello shell > ' + os_helper.TESTFN)
70+
self.assertFalse(os.path.lexists(os_helper.TESTFN))
7071
self.assertIsNone(result)
7172

7273

@@ -100,7 +101,7 @@ def test_find_on_libpath(self):
100101
# LD_LIBRARY_PATH)
101102
self.assertIsNone(find_library(libname))
102103
# now add the location to LD_LIBRARY_PATH
103-
with test.support.EnvironmentVarGuard() as env:
104+
with os_helper.EnvironmentVarGuard() as env:
104105
KEY = 'LD_LIBRARY_PATH'
105106
if KEY not in env:
106107
v = d

Lib/test/test_bytes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import unittest
1717

1818
import test.support
19+
from test.support import import_helper
1920
import test.string_tests
2021
import test.list_tests
2122
from test.support import bigaddrspacetest, MAX_Py_ssize_t
@@ -967,7 +968,7 @@ def test_translate(self):
967968
self.assertEqual(c, b'hllo')
968969

969970
def test_sq_item(self):
970-
_testcapi = test.support.import_module('_testcapi')
971+
_testcapi = import_helper.import_module('_testcapi')
971972
obj = self.type2test((42,))
972973
with self.assertRaises(IndexError):
973974
_testcapi.sequence_getitem(obj, -2)
@@ -1024,8 +1025,8 @@ def __bytes__(self):
10241025

10251026
# Test PyBytes_FromFormat()
10261027
def test_from_format(self):
1027-
ctypes = test.support.import_module('ctypes')
1028-
_testcapi = test.support.import_module('_testcapi')
1028+
ctypes = import_helper.import_module('ctypes')
1029+
_testcapi = import_helper.import_module('_testcapi')
10291030
from ctypes import pythonapi, py_object
10301031
from ctypes import (
10311032
c_int, c_uint,

Lib/test/test_cgitb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from test.support import temp_dir
1+
from test.support.os_helper import temp_dir
22
from test.support.script_helper import assert_python_failure
33
import unittest
44
import sys

Lib/test/test_ctypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
2-
from test.support import import_module
2+
from test.support.import_helper import import_module
3+
34

45
ctypes_test = import_module('ctypes.test')
56

Lib/test/test_dbm.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
import unittest
44
import glob
5-
import test.support
5+
from test.support import import_helper
6+
from test.support import os_helper
67

78
# Skip tests if dbm module doesn't exist.
8-
dbm = test.support.import_module('dbm')
9+
dbm = import_helper.import_module('dbm')
910

1011
try:
1112
from dbm import ndbm
1213
except ImportError:
1314
ndbm = None
1415

15-
_fname = test.support.TESTFN
16+
_fname = os_helper.TESTFN
1617

1718
#
1819
# Iterates over every database module supported by dbm currently available,
@@ -34,7 +35,7 @@ def delete_files():
3435
# we don't know the precise name the underlying database uses
3536
# so we use glob to locate all names
3637
for f in glob.glob(glob.escape(_fname) + "*"):
37-
test.support.unlink(f)
38+
os_helper.unlink(f)
3839

3940

4041
class AnyDBMTestCase:
@@ -74,7 +75,7 @@ def test_anydbm_creation(self):
7475

7576
def test_anydbm_creation_n_file_exists_with_invalid_contents(self):
7677
# create an empty file
77-
test.support.create_empty_file(_fname)
78+
os_helper.create_empty_file(_fname)
7879
with dbm.open(_fname, 'n') as f:
7980
self.assertEqual(len(f), 0)
8081

@@ -169,18 +170,18 @@ def test_whichdb_ndbm(self):
169170
# Issue 17198: check that ndbm which is referenced in whichdb is defined
170171
db_file = '{}_ndbm.db'.format(_fname)
171172
with open(db_file, 'w'):
172-
self.addCleanup(test.support.unlink, db_file)
173+
self.addCleanup(os_helper.unlink, db_file)
173174
self.assertIsNone(self.dbm.whichdb(db_file[:-3]))
174175

175176
def tearDown(self):
176177
delete_files()
177178

178179
def setUp(self):
179180
delete_files()
180-
self.filename = test.support.TESTFN
181+
self.filename = os_helper.TESTFN
181182
self.d = dbm.open(self.filename, 'c')
182183
self.d.close()
183-
self.dbm = test.support.import_fresh_module('dbm')
184+
self.dbm = import_helper.import_fresh_module('dbm')
184185

185186
def test_keys(self):
186187
self.d = dbm.open(self.filename, 'c')

Lib/test/test_fcntl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import sys
77
import unittest
88
from multiprocessing import Process
9-
from test.support import (verbose, TESTFN, unlink, run_unittest, import_module,
10-
cpython_only)
9+
from test.support import (verbose, run_unittest, cpython_only)
10+
from test.support.import_helper import import_module
11+
from test.support.os_helper import TESTFN, unlink
12+
1113

1214
# Skip test if no fcntl module.
1315
fcntl = import_module('fcntl')

Lib/test/test_file.py

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

10-
from test.support import TESTFN
11-
from test import support
10+
from test.support.os_helper import TESTFN
11+
from test.support import os_helper
12+
from test.support import warnings_helper
1213
from collections import UserList
1314

1415
class AutoFileTests:
@@ -20,7 +21,7 @@ def setUp(self):
2021
def tearDown(self):
2122
if self.f:
2223
self.f.close()
23-
support.unlink(TESTFN)
24+
os_helper.unlink(TESTFN)
2425

2526
def testWeakRefs(self):
2627
# verify weak references
@@ -139,7 +140,7 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase):
139140
class OtherFileTests:
140141

141142
def tearDown(self):
142-
support.unlink(TESTFN)
143+
os_helper.unlink(TESTFN)
143144

144145
def testModeStrings(self):
145146
# check invalid mode strings
@@ -187,7 +188,7 @@ def testSetBufferSize(self):
187188
# make sure that explicitly setting the buffer size doesn't cause
188189
# misbehaviour especially with repeated close() calls
189190
for s in (-1, 0, 512):
190-
with support.check_no_warnings(self,
191+
with warnings_helper.check_no_warnings(self,
191192
message='line buffering',
192193
category=RuntimeWarning):
193194
self._checkBufferSize(s)

Lib/test/test_fstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import types
1313
import decimal
1414
import unittest
15-
from test.support import temp_cwd
15+
from test.support.os_helper import temp_cwd
1616
from test.support.script_helper import assert_python_failure
1717

1818
a_global = 'global variable'

Lib/test/test_httpservers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import unittest
3232
from test import support
33+
from test.support import os_helper
3334
from test.support import threading_helper
3435

3536

@@ -391,13 +392,13 @@ def close_conn():
391392
'undecodable name cannot always be decoded on macOS')
392393
@unittest.skipIf(sys.platform == 'win32',
393394
'undecodable name cannot be decoded on win32')
394-
@unittest.skipUnless(support.TESTFN_UNDECODABLE,
395-
'need support.TESTFN_UNDECODABLE')
395+
@unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
396+
'need os_helper.TESTFN_UNDECODABLE')
396397
def test_undecodable_filename(self):
397398
enc = sys.getfilesystemencoding()
398-
filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt'
399+
filename = os.fsdecode(os_helper.TESTFN_UNDECODABLE) + '.txt'
399400
with open(os.path.join(self.tempdir, filename), 'wb') as f:
400-
f.write(support.TESTFN_UNDECODABLE)
401+
f.write(os_helper.TESTFN_UNDECODABLE)
401402
response = self.request(self.base_url + '/')
402403
if sys.platform == 'darwin':
403404
# On Mac OS the HFS+ filesystem replaces bytes that aren't valid
@@ -414,7 +415,7 @@ def test_undecodable_filename(self):
414415
.encode(enc, 'surrogateescape'), body)
415416
response = self.request(self.base_url + '/' + quotedname)
416417
self.check_status_and_reason(response, HTTPStatus.OK,
417-
data=support.TESTFN_UNDECODABLE)
418+
data=os_helper.TESTFN_UNDECODABLE)
418419

419420
def test_get(self):
420421
#constructs the path relative to the root directory of the HTTPServer

0 commit comments

Comments
 (0)