Skip to content

Commit 96a6a6d

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21412)
1 parent 61bb24a commit 96a6a6d

18 files changed

+154
-134
lines changed

Lib/test/test_cmd_line_script.py

Lines changed: 51 additions & 49 deletions
Large diffs are not rendered by default.

Lib/test/test_codeop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import unittest
77
from test import support
8+
from test.support import warnings_helper
89

910
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
1011
import io
@@ -305,7 +306,7 @@ def test_filename(self):
305306

306307
def test_warning(self):
307308
# Test that the warning is only returned once.
308-
with support.check_warnings((".*literal", SyntaxWarning)) as w:
309+
with warnings_helper.check_warnings((".*literal", SyntaxWarning)) as w:
309310
compile_command("0 is 0")
310311
self.assertEqual(len(w.warnings), 1)
311312

Lib/test/test_contextlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import unittest
88
from contextlib import * # Tests __all__
99
from test import support
10+
from test.support import os_helper
1011
import weakref
1112

1213

@@ -327,7 +328,7 @@ def testWithOpen(self):
327328
1 / 0
328329
self.assertTrue(f.closed)
329330
finally:
330-
support.unlink(tfn)
331+
os_helper.unlink(tfn)
331332

332333
class LockContextTestCase(unittest.TestCase):
333334

Lib/test/test_dbm_ndbm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from test import support
2-
support.import_module("dbm.ndbm") #skip if not supported
2+
from test.support import import_helper
3+
import_helper.import_module("dbm.ndbm") #skip if not supported
34
import os
45
import unittest
56
import dbm.ndbm

Lib/test/test_getargs2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import string
44
import sys
55
from test import support
6+
from test.support import import_helper
67
# Skip this test if the _testcapi module isn't available.
7-
_testcapi = support.import_module('_testcapi')
8+
_testcapi = import_helper.import_module('_testcapi')
89
from _testcapi import getargs_keywords, getargs_keyword_only
910

1011
# > How about the following counterproposal. This also changes some of

Lib/test/test_gettext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66

77
from test import support
8+
from test.support import os_helper
89

910

1011
# TODO:
@@ -129,14 +130,14 @@ def setUp(self):
129130
fp.write(base64.decodebytes(UMO_DATA))
130131
with open(MMOFILE, 'wb') as fp:
131132
fp.write(base64.decodebytes(MMO_DATA))
132-
self.env = support.EnvironmentVarGuard()
133+
self.env = os_helper.EnvironmentVarGuard()
133134
self.env['LANGUAGE'] = 'xx'
134135
gettext._translations.clear()
135136

136137
def tearDown(self):
137138
self.env.__exit__()
138139
del self.env
139-
support.rmtree(os.path.split(LOCALEDIR)[0])
140+
os_helper.rmtree(os.path.split(LOCALEDIR)[0])
140141

141142
GNU_MO_DATA_ISSUE_17898 = b'''\
142143
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z

Lib/test/test_glob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import sys
55
import unittest
66

7-
from test.support import (TESTFN, skip_unless_symlink,
8-
can_symlink, create_empty_file, change_cwd)
7+
from test.support.os_helper import (TESTFN, skip_unless_symlink,
8+
can_symlink, create_empty_file, change_cwd)
99

1010

1111
class GlobTests(unittest.TestCase):

Lib/test/test_import/__init__.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
from unittest import mock
2020

2121
import test.support
22-
from test.support import (
23-
TESTFN, forget, is_jython,
24-
make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask,
25-
unlink, unload, cpython_only, TESTFN_UNENCODABLE,
26-
temp_dir, DirsOnSysPath)
22+
from test.support import os_helper
23+
from test.support import (is_jython, swap_attr, swap_item, cpython_only)
24+
from test.support.import_helper import (
25+
forget, make_legacy_pyc, unlink, unload, DirsOnSysPath)
26+
from test.support.os_helper import (
27+
TESTFN, rmtree, temp_umask, TESTFN_UNENCODABLE, temp_dir)
2728
from test.support import script_helper
2829
from test.support import threading_helper
2930
from test.test_importlib.util import uncache
@@ -997,22 +998,22 @@ class TestSymbolicallyLinkedPackage(unittest.TestCase):
997998
tagged = package_name + '-tagged'
998999

9991000
def setUp(self):
1000-
test.support.rmtree(self.tagged)
1001-
test.support.rmtree(self.package_name)
1001+
os_helper.rmtree(self.tagged)
1002+
os_helper.rmtree(self.package_name)
10021003
self.orig_sys_path = sys.path[:]
10031004

10041005
# create a sample package; imagine you have a package with a tag and
10051006
# you want to symbolically link it from its untagged name.
10061007
os.mkdir(self.tagged)
1007-
self.addCleanup(test.support.rmtree, self.tagged)
1008+
self.addCleanup(os_helper.rmtree, self.tagged)
10081009
init_file = os.path.join(self.tagged, '__init__.py')
1009-
test.support.create_empty_file(init_file)
1010+
os_helper.create_empty_file(init_file)
10101011
assert os.path.exists(init_file)
10111012

10121013
# now create a symlink to the tagged package
10131014
# sample -> sample-tagged
10141015
os.symlink(self.tagged, self.package_name, target_is_directory=True)
1015-
self.addCleanup(test.support.unlink, self.package_name)
1016+
self.addCleanup(os_helper.unlink, self.package_name)
10161017
importlib.invalidate_caches()
10171018

10181019
self.assertEqual(os.path.isdir(self.package_name), True)
@@ -1027,7 +1028,7 @@ def tearDown(self):
10271028
not hasattr(sys, 'getwindowsversion')
10281029
or sys.getwindowsversion() >= (6, 0),
10291030
"Windows Vista or later required")
1030-
@test.support.skip_unless_symlink
1031+
@os_helper.skip_unless_symlink
10311032
def test_symlinked_dir_importable(self):
10321033
# make sure sample can only be imported from the current directory.
10331034
sys.path[:] = ['.']

Lib/test/test_locale.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from test.support import verbose, is_android, check_warnings
1+
from test.support import verbose, is_android
2+
from test.support.warnings_helper import check_warnings
23
import unittest
34
import locale
45
import sys

Lib/test/test_mailbox.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io
1010
import tempfile
1111
from test import support
12+
from test.support import os_helper
1213
import unittest
1314
import textwrap
1415
import mailbox
@@ -38,9 +39,9 @@ def _check_sample(self, msg):
3839
def _delete_recursively(self, target):
3940
# Delete a file or delete a directory recursively
4041
if os.path.isdir(target):
41-
support.rmtree(target)
42+
os_helper.rmtree(target)
4243
elif os.path.exists(target):
43-
support.unlink(target)
44+
os_helper.unlink(target)
4445

4546

4647
class TestMailbox(TestBase):
@@ -51,7 +52,7 @@ class TestMailbox(TestBase):
5152
_template = 'From: foo\n\n%s\n'
5253

5354
def setUp(self):
54-
self._path = support.TESTFN
55+
self._path = os_helper.TESTFN
5556
self._delete_recursively(self._path)
5657
self._box = self._factory(self._path)
5758

@@ -926,7 +927,7 @@ def refreshed():
926927
# the mtime and should cause a re-read. Note that "sleep
927928
# emulation" is still in effect, as skewfactor is -3.
928929
filename = os.path.join(self._path, 'cur', 'stray-file')
929-
support.create_empty_file(filename)
930+
os_helper.create_empty_file(filename)
930931
os.unlink(filename)
931932
self._box._refresh()
932933
self.assertTrue(refreshed())
@@ -980,7 +981,7 @@ def tearDown(self):
980981
self._box.close()
981982
self._delete_recursively(self._path)
982983
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
983-
support.unlink(lock_remnant)
984+
os_helper.unlink(lock_remnant)
984985

985986
def assertMailboxEmpty(self):
986987
with open(self._path) as f:
@@ -1312,7 +1313,7 @@ def tearDown(self):
13121313
self._box.close()
13131314
self._delete_recursively(self._path)
13141315
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
1315-
support.unlink(lock_remnant)
1316+
os_helper.unlink(lock_remnant)
13161317

13171318
def test_labels(self):
13181319
# Get labels from the mailbox
@@ -1369,7 +1370,7 @@ class TestMessage(TestBase, unittest.TestCase):
13691370
_factory = mailbox.Message # Overridden by subclasses to reuse tests
13701371

13711372
def setUp(self):
1372-
self._path = support.TESTFN
1373+
self._path = os_helper.TESTFN
13731374

13741375
def tearDown(self):
13751376
self._delete_recursively(self._path)
@@ -2019,7 +2020,7 @@ def _test_close(self, proxy):
20192020
class TestProxyFile(TestProxyFileBase, unittest.TestCase):
20202021

20212022
def setUp(self):
2022-
self._path = support.TESTFN
2023+
self._path = os_helper.TESTFN
20232024
self._file = open(self._path, 'wb+')
20242025

20252026
def tearDown(self):
@@ -2068,7 +2069,7 @@ def test_close(self):
20682069
class TestPartialFile(TestProxyFileBase, unittest.TestCase):
20692070

20702071
def setUp(self):
2071-
self._path = support.TESTFN
2072+
self._path = os_helper.TESTFN
20722073
self._file = open(self._path, 'wb+')
20732074

20742075
def tearDown(self):
@@ -2131,11 +2132,11 @@ class MaildirTestCase(unittest.TestCase):
21312132

21322133
def setUp(self):
21332134
# create a new maildir mailbox to work with:
2134-
self._dir = support.TESTFN
2135+
self._dir = os_helper.TESTFN
21352136
if os.path.isdir(self._dir):
2136-
support.rmtree(self._dir)
2137+
os_helper.rmtree(self._dir)
21372138
elif os.path.isfile(self._dir):
2138-
support.unlink(self._dir)
2139+
os_helper.unlink(self._dir)
21392140
os.mkdir(self._dir)
21402141
os.mkdir(os.path.join(self._dir, "cur"))
21412142
os.mkdir(os.path.join(self._dir, "tmp"))
@@ -2145,10 +2146,10 @@ def setUp(self):
21452146

21462147
def tearDown(self):
21472148
list(map(os.unlink, self._msgfiles))
2148-
support.rmdir(os.path.join(self._dir, "cur"))
2149-
support.rmdir(os.path.join(self._dir, "tmp"))
2150-
support.rmdir(os.path.join(self._dir, "new"))
2151-
support.rmdir(self._dir)
2149+
os_helper.rmdir(os.path.join(self._dir, "cur"))
2150+
os_helper.rmdir(os.path.join(self._dir, "tmp"))
2151+
os_helper.rmdir(os.path.join(self._dir, "new"))
2152+
os_helper.rmdir(self._dir)
21522153

21532154
def createMessage(self, dir, mbox=False):
21542155
t = int(time.time() % 1000000)
@@ -2174,23 +2175,23 @@ def test_empty_maildir(self):
21742175
"""Test an empty maildir mailbox"""
21752176
# Test for regression on bug #117490:
21762177
# Make sure the boxes attribute actually gets set.
2177-
self.mbox = mailbox.Maildir(support.TESTFN)
2178+
self.mbox = mailbox.Maildir(os_helper.TESTFN)
21782179
#self.assertTrue(hasattr(self.mbox, "boxes"))
21792180
#self.assertEqual(len(self.mbox.boxes), 0)
21802181
self.assertIsNone(self.mbox.next())
21812182
self.assertIsNone(self.mbox.next())
21822183

21832184
def test_nonempty_maildir_cur(self):
21842185
self.createMessage("cur")
2185-
self.mbox = mailbox.Maildir(support.TESTFN)
2186+
self.mbox = mailbox.Maildir(os_helper.TESTFN)
21862187
#self.assertEqual(len(self.mbox.boxes), 1)
21872188
self.assertIsNotNone(self.mbox.next())
21882189
self.assertIsNone(self.mbox.next())
21892190
self.assertIsNone(self.mbox.next())
21902191

21912192
def test_nonempty_maildir_new(self):
21922193
self.createMessage("new")
2193-
self.mbox = mailbox.Maildir(support.TESTFN)
2194+
self.mbox = mailbox.Maildir(os_helper.TESTFN)
21942195
#self.assertEqual(len(self.mbox.boxes), 1)
21952196
self.assertIsNotNone(self.mbox.next())
21962197
self.assertIsNone(self.mbox.next())
@@ -2199,7 +2200,7 @@ def test_nonempty_maildir_new(self):
21992200
def test_nonempty_maildir_both(self):
22002201
self.createMessage("cur")
22012202
self.createMessage("new")
2202-
self.mbox = mailbox.Maildir(support.TESTFN)
2203+
self.mbox = mailbox.Maildir(os_helper.TESTFN)
22032204
#self.assertEqual(len(self.mbox.boxes), 2)
22042205
self.assertIsNotNone(self.mbox.next())
22052206
self.assertIsNotNone(self.mbox.next())

0 commit comments

Comments
 (0)