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
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from test.libregrtest.pgo import setup_pgo_tests
from test.libregrtest.utils import removepy, count, format_duration, printlist
from test import support
from test.support import os_helper


# bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()).
Expand Down Expand Up @@ -628,7 +629,7 @@ def main(self, tests=None, **kwargs):
# to a temporary and writable directory. If it's not possible to
# create or change the CWD, the original CWD will be used.
# The original CWD is available from support.SAVEDCWD.
with support.temp_cwd(test_cwd, quiet=True):
with os_helper.temp_cwd(test_cwd, quiet=True):
# When using multiprocessing, worker processes will use test_cwd
# as their parent temporary directory. So when the main process
# exit, it removes also subdirectories of worker processes.
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/libregrtest/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import unittest

from test import support
from test.support import import_helper
from test.support import os_helper
from test.libregrtest.refleak import dash_R, clear_caches
from test.libregrtest.save_env import saved_test_environment
from test.libregrtest.utils import format_duration, print_warning
Expand Down Expand Up @@ -216,7 +218,7 @@ def _runtest_inner2(ns, test_name):
abstest = get_abs_module(ns, test_name)

# remove the module from sys.module to reload it if it was already imported
support.unload(abstest)
import_helper.unload(abstest)

the_module = importlib.import_module(abstest)

Expand Down Expand Up @@ -313,7 +315,7 @@ def cleanup_test_droppings(test_name, verbose):
# since if a test leaves a file open, it cannot be deleted by name (while
# there's nothing we can do about that here either, we can display the
# name of the offending test, which is a real help).
for name in (support.TESTFN,):
for name in (os_helper.TESTFN,):
if not os.path.exists(name):
continue

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import urllib.request
import warnings
from test import support
from test.support import os_helper
from test.libregrtest.utils import print_warning
try:
import _multiprocessing, multiprocessing.process
Expand Down Expand Up @@ -241,7 +242,7 @@ def get_files(self):
return sorted(fn + ('/' if os.path.isdir(fn) else '')
for fn in os.listdir())
def restore_files(self, saved_value):
fn = support.TESTFN
fn = os_helper.TESTFN
if fn not in saved_value and (fn + '/') not in saved_value:
if os.path.isfile(fn):
support.unlink(fn)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/script_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import zipfile

from importlib.util import source_from_cache
from test.support import make_legacy_pyc
from test.support.import_helper import make_legacy_pyc


# Cached result of the expensive test performed in the function below.
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import unittest

from test import support
from test.support import import_helper
from test.support import script_helper


interpreters = support.import_module('_xxsubinterpreters')
interpreters = import_helper.import_module('_xxsubinterpreters')


##################################
Expand Down
19 changes: 10 additions & 9 deletions Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import unittest
from test import support
from test.support import os_helper
from test.support import _2G
import weakref
import pickle
Expand Down Expand Up @@ -366,13 +367,13 @@ def test_insert(self):
def test_tofromfile(self):
a = array.array(self.typecode, 2*self.example)
self.assertRaises(TypeError, a.tofile)
support.unlink(support.TESTFN)
f = open(support.TESTFN, 'wb')
os_helper.unlink(os_helper.TESTFN)
f = open(os_helper.TESTFN, 'wb')
try:
a.tofile(f)
f.close()
b = array.array(self.typecode)
f = open(support.TESTFN, 'rb')
f = open(os_helper.TESTFN, 'rb')
self.assertRaises(TypeError, b.fromfile)
b.fromfile(f, len(self.example))
self.assertEqual(b, array.array(self.typecode, self.example))
Expand All @@ -383,27 +384,27 @@ def test_tofromfile(self):
finally:
if not f.closed:
f.close()
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)

def test_fromfile_ioerror(self):
# Issue #5395: Check if fromfile raises a proper OSError
# instead of EOFError.
a = array.array(self.typecode)
f = open(support.TESTFN, 'wb')
f = open(os_helper.TESTFN, 'wb')
try:
self.assertRaises(OSError, a.fromfile, f, len(self.example))
finally:
f.close()
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)

def test_filewrite(self):
a = array.array(self.typecode, 2*self.example)
f = open(support.TESTFN, 'wb')
f = open(os_helper.TESTFN, 'wb')
try:
f.write(a)
f.close()
b = array.array(self.typecode)
f = open(support.TESTFN, 'rb')
f = open(os_helper.TESTFN, 'rb')
b.fromfile(f, len(self.example))
self.assertEqual(b, array.array(self.typecode, self.example))
self.assertNotEqual(a, b)
Expand All @@ -413,7 +414,7 @@ def test_filewrite(self):
finally:
if not f.closed:
f.close()
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)

def test_tofromlist(self):
a = array.array(self.typecode, 2*self.example)
Expand Down
16 changes: 9 additions & 7 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import textwrap
import unittest
from test import support
from test.support import os_helper
from test.support.script_helper import (
spawn_python, kill_python, assert_python_ok, assert_python_failure,
interpreter_requires_environment
Expand Down Expand Up @@ -141,11 +142,11 @@ def test_run_code(self):
# All good if execution is successful
assert_python_ok('-c', 'pass')

@unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII')
@unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
def test_non_ascii(self):
# Test handling of non-ascii data
command = ("assert(ord(%r) == %s)"
% (support.FS_NONASCII, ord(support.FS_NONASCII)))
% (os_helper.FS_NONASCII, ord(os_helper.FS_NONASCII)))
assert_python_ok('-c', command)

# On Windows, pass bytes to subprocess doesn't test how Python decodes the
Expand Down Expand Up @@ -463,8 +464,8 @@ def test_del___main__(self):
# Issue #15001: PyRun_SimpleFileExFlags() did crash because it kept a
# borrowed reference to the dict of __main__ module and later modify
# the dict whereas the module was destroyed
filename = support.TESTFN
self.addCleanup(support.unlink, filename)
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)
with open(filename, "w") as script:
print("import sys", file=script)
print("del sys.modules['__main__']", file=script)
Expand Down Expand Up @@ -499,7 +500,7 @@ def test_isolatedmode(self):
# dummyvar to prevent extraneous -E
dummyvar="")
self.assertEqual(out.strip(), b'1 1 1')
with support.temp_cwd() as tmpdir:
with os_helper.temp_cwd() as tmpdir:
fake = os.path.join(tmpdir, "uuid.py")
main = os.path.join(tmpdir, "main.py")
with open(fake, "w") as f:
Expand Down Expand Up @@ -561,7 +562,7 @@ def test_set_pycache_prefix(self):
elif opt is not None:
args[:0] = ['-X', f'pycache_prefix={opt}']
with self.subTest(envval=envval, opt=opt):
with support.temp_cwd():
with os_helper.temp_cwd():
assert_python_ok(*args, **env)

def run_xdev(self, *args, check_exitcode=True, xdev=True):
Expand Down Expand Up @@ -644,7 +645,8 @@ def test_xdev(self):

def check_warnings_filters(self, cmdline_option, envvar, use_pywarning=False):
if use_pywarning:
code = ("import sys; from test.support import import_fresh_module; "
code = ("import sys; from test.support.import_helper import "
"import_fresh_module; "
"warnings = import_fresh_module('warnings', blocked=['_warnings']); ")
else:
code = "import sys, warnings; "
Expand Down
12 changes: 7 additions & 5 deletions Lib/test/test_dbm_dumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import unittest
import dbm.dumb as dumbdbm
from test import support
from test.support import os_helper
from functools import partial

_fname = support.TESTFN
_fname = os_helper.TESTFN


def _delete_files():
for ext in [".dir", ".dat", ".bak"]:
Expand Down Expand Up @@ -264,7 +266,7 @@ def test_invalid_flag(self):
dumbdbm.open(_fname, flag)

def test_readonly_files(self):
with support.temp_dir() as dir:
with os_helper.temp_dir() as dir:
fname = os.path.join(dir, 'db')
with dumbdbm.open(fname, 'n') as f:
self.assertEqual(list(f.keys()), [])
Expand All @@ -277,12 +279,12 @@ def test_readonly_files(self):
self.assertEqual(sorted(f.keys()), sorted(self._dict))
f.close() # don't write

@unittest.skipUnless(support.TESTFN_NONASCII,
@unittest.skipUnless(os_helper.TESTFN_NONASCII,
'requires OS support of non-ASCII encodings')
def test_nonascii_filename(self):
filename = support.TESTFN_NONASCII
filename = os_helper.TESTFN_NONASCII
for suffix in ['.dir', '.dat', '.bak']:
self.addCleanup(support.unlink, filename + suffix)
self.addCleanup(os_helper.unlink, filename + suffix)
with dumbdbm.open(filename, 'c') as db:
db[b'key'] = b'value'
self.assertTrue(os.path.exists(filename + '.dat'))
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import locale
from test.support import (run_unittest, run_doctest, is_resource_enabled,
requires_IEEE_754, requires_docstrings)
from test.support import (import_fresh_module, TestFailed,
from test.support import (TestFailed,
run_with_locale, cpython_only)
from test.support.import_helper import import_fresh_module
import random
import inspect
import threading
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_global.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Verify that warnings are issued for global statements following use."""

from test.support import run_unittest, check_syntax_error, check_warnings
from test.support import run_unittest, check_syntax_error
from test.support.warnings_helper import check_warnings
import unittest
import warnings

Expand Down
38 changes: 20 additions & 18 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import py_compile
import sys
from test import support
from test.support import import_helper
from test.support import os_helper
from test.support import script_helper
import unittest
import warnings
Expand Down Expand Up @@ -107,8 +109,8 @@ def test_issue3594(self):
self.assertEqual(file.encoding, 'cp1252')
finally:
del sys.path[0]
support.unlink(temp_mod_name + '.py')
support.unlink(temp_mod_name + '.pyc')
os_helper.unlink(temp_mod_name + '.py')
os_helper.unlink(temp_mod_name + '.pyc')

def test_issue5604(self):
# Test cannot cover imp.load_compiled function.
Expand Down Expand Up @@ -192,10 +194,10 @@ def test_issue5604(self):
finally:
del sys.path[0]
for ext in ('.py', '.pyc'):
support.unlink(temp_mod_name + ext)
support.unlink(init_file_name + ext)
support.rmtree(test_package_name)
support.rmtree('__pycache__')
os_helper.unlink(temp_mod_name + ext)
os_helper.unlink(init_file_name + ext)
os_helper.rmtree(test_package_name)
os_helper.rmtree('__pycache__')

def test_issue9319(self):
path = os.path.dirname(__file__)
Expand All @@ -204,7 +206,7 @@ def test_issue9319(self):

def test_load_from_source(self):
# Verify that the imp module can correctly load and find .py files
# XXX (ncoghlan): It would be nice to use support.CleanImport
# XXX (ncoghlan): It would be nice to use import_helper.CleanImport
# here, but that breaks because the os module registers some
# handlers in copy_reg on import. Since CleanImport doesn't
# revert that registration, the module is left in a broken
Expand All @@ -213,7 +215,7 @@ def test_load_from_source(self):
# workaround
orig_path = os.path
orig_getenv = os.getenv
with support.EnvironmentVarGuard():
with os_helper.EnvironmentVarGuard():
x = imp.find_module("os")
self.addCleanup(x[0].close)
new_os = imp.load_module("os", *x)
Expand Down Expand Up @@ -299,11 +301,11 @@ def test_issue24748_load_module_skips_sys_modules_check(self):
@unittest.skipIf(sys.dont_write_bytecode,
"test meaningful only when writing bytecode")
def test_bug7732(self):
with support.temp_cwd():
source = support.TESTFN + '.py'
with os_helper.temp_cwd():
source = os_helper.TESTFN + '.py'
os.mkdir(source)
self.assertRaisesRegex(ImportError, '^No module',
imp.find_module, support.TESTFN, ["."])
imp.find_module, os_helper.TESTFN, ["."])

def test_multiple_calls_to_get_data(self):
# Issue #18755: make sure multiple calls to get_data() can succeed.
Expand Down Expand Up @@ -364,7 +366,7 @@ def test_pyc_invalidation_mode_from_cmdline(self):

def test_find_and_load_checked_pyc(self):
# issue 34056
with support.temp_cwd():
with os_helper.temp_cwd():
with open('mymod.py', 'wb') as fp:
fp.write(b'x = 42\n')
py_compile.compile(
Expand All @@ -383,24 +385,24 @@ class ReloadTests(unittest.TestCase):
reload()."""

def test_source(self):
# XXX (ncoghlan): It would be nice to use test.support.CleanImport
# XXX (ncoghlan): It would be nice to use test.import_helper.CleanImport
# here, but that breaks because the os module registers some
# handlers in copy_reg on import. Since CleanImport doesn't
# revert that registration, the module is left in a broken
# state after reversion. Reinitialising the module contents
# and just reverting os.environ to its previous state is an OK
# workaround
with support.EnvironmentVarGuard():
with os_helper.EnvironmentVarGuard():
import os
imp.reload(os)

def test_extension(self):
with support.CleanImport('time'):
with import_helper.CleanImport('time'):
import time
imp.reload(time)

def test_builtin(self):
with support.CleanImport('marshal'):
with import_helper.CleanImport('marshal'):
import marshal
imp.reload(marshal)

Expand Down Expand Up @@ -443,10 +445,10 @@ def test_source_from_cache(self):


class NullImporterTests(unittest.TestCase):
@unittest.skipIf(support.TESTFN_UNENCODABLE is None,
@unittest.skipIf(os_helper.TESTFN_UNENCODABLE is None,
"Need an undecodeable filename")
def test_unencodeable(self):
name = support.TESTFN_UNENCODABLE
name = os_helper.TESTFN_UNENCODABLE
os.mkdir(name)
try:
self.assertRaises(ImportError, imp.NullImporter, name)
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_ioctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import array
import unittest
from test.support import import_module, get_attribute
from test.support import get_attribute
from test.support.import_helper import import_module
import os, struct
fcntl = import_module('fcntl')
termios = import_module('termios')
Expand Down
Loading