bpo-40275: Use new test.support helper submodules in tests by shihai1991 · Pull Request #21412 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 51 additions & 49 deletions Lib/test/test_cmd_line_script.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Lib/test/test_codeop.py
3 changes: 2 additions & 1 deletion Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
from contextlib import * # Tests __all__
from test import support
from test.support import os_helper
import weakref


Expand Down Expand Up @@ -327,7 +328,7 @@ def testWithOpen(self):
1 / 0
self.assertTrue(f.closed)
finally:
support.unlink(tfn)
os_helper.unlink(tfn)

class LockContextTestCase(unittest.TestCase):

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_dbm_ndbm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from test import support
support.import_module("dbm.ndbm") #skip if not supported
from test.support import import_helper
import_helper.import_module("dbm.ndbm") #skip if not supported
import os
import unittest
import dbm.ndbm
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import string
import sys
from test import support
from test.support import import_helper
# Skip this test if the _testcapi module isn't available.
_testcapi = support.import_module('_testcapi')
_testcapi = import_helper.import_module('_testcapi')
from _testcapi import getargs_keywords, getargs_keyword_only

# > How about the following counterproposal. This also changes some of
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

from test import support
from test.support import os_helper


# TODO:
Expand Down Expand Up @@ -129,14 +130,14 @@ def setUp(self):
fp.write(base64.decodebytes(UMO_DATA))
with open(MMOFILE, 'wb') as fp:
fp.write(base64.decodebytes(MMO_DATA))
self.env = support.EnvironmentVarGuard()
self.env = os_helper.EnvironmentVarGuard()
self.env['LANGUAGE'] = 'xx'
gettext._translations.clear()

def tearDown(self):
self.env.__exit__()
del self.env
support.rmtree(os.path.split(LOCALEDIR)[0])
os_helper.rmtree(os.path.split(LOCALEDIR)[0])

GNU_MO_DATA_ISSUE_17898 = b'''\
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
import unittest

from test.support import (TESTFN, skip_unless_symlink,
can_symlink, create_empty_file, change_cwd)
from test.support.os_helper import (TESTFN, skip_unless_symlink,
can_symlink, create_empty_file, change_cwd)


class GlobTests(unittest.TestCase):
Expand Down
23 changes: 12 additions & 11 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
from unittest import mock

import test.support
from test.support import (
TESTFN, forget, is_jython,
make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask,
unlink, unload, cpython_only, TESTFN_UNENCODABLE,
temp_dir, DirsOnSysPath)
from test.support import os_helper
from test.support import (is_jython, swap_attr, swap_item, cpython_only)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, DirsOnSysPath)
from test.support.os_helper import (
TESTFN, rmtree, temp_umask, TESTFN_UNENCODABLE, temp_dir)
from test.support import script_helper
from test.support import threading_helper
from test.test_importlib.util import uncache
Expand Down Expand Up @@ -997,22 +998,22 @@ class TestSymbolicallyLinkedPackage(unittest.TestCase):
tagged = package_name + '-tagged'

def setUp(self):
test.support.rmtree(self.tagged)
test.support.rmtree(self.package_name)
os_helper.rmtree(self.tagged)
os_helper.rmtree(self.package_name)
self.orig_sys_path = sys.path[:]

# create a sample package; imagine you have a package with a tag and
# you want to symbolically link it from its untagged name.
os.mkdir(self.tagged)
self.addCleanup(test.support.rmtree, self.tagged)
self.addCleanup(os_helper.rmtree, self.tagged)
init_file = os.path.join(self.tagged, '__init__.py')
test.support.create_empty_file(init_file)
os_helper.create_empty_file(init_file)
assert os.path.exists(init_file)

# now create a symlink to the tagged package
# sample -> sample-tagged
os.symlink(self.tagged, self.package_name, target_is_directory=True)
self.addCleanup(test.support.unlink, self.package_name)
self.addCleanup(os_helper.unlink, self.package_name)
importlib.invalidate_caches()

self.assertEqual(os.path.isdir(self.package_name), True)
Expand All @@ -1027,7 +1028,7 @@ def tearDown(self):
not hasattr(sys, 'getwindowsversion')
or sys.getwindowsversion() >= (6, 0),
"Windows Vista or later required")
@test.support.skip_unless_symlink
@os_helper.skip_unless_symlink
def test_symlinked_dir_importable(self):
# make sure sample can only be imported from the current directory.
sys.path[:] = ['.']
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_locale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.support import verbose, is_android, check_warnings
from test.support import verbose, is_android
from test.support.warnings_helper import check_warnings
import unittest
import locale
import sys
Expand Down
41 changes: 21 additions & 20 deletions Lib/test/test_mailbox.py
Loading