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/audiotests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.support import findfile, TESTFN, unlink
from test.support import findfile
from test.support.os_helper import TESTFN, unlink
import array
import io
import pickle
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
from test import support
from test.support import os_helper


USAGE = """\
Expand Down Expand Up @@ -291,7 +292,7 @@ def _create_parser():
def relative_filename(string):
# CWD is replaced with a temporary dir before calling main(), so we
# join it with the saved CWD so it ends up where the user expects.
return os.path.join(support.SAVEDCWD, string)
return os.path.join(os_helper.SAVEDCWD, string)


def huntrleaks(string):
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def find_tests(self, tests):
# regex to match 'test_builtin' in line:
# '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
with open(os.path.join(os_helper.SAVEDCWD, self.ns.fromfile)) as fp:
for line in fp:
line = line.split('#', 1)[0]
line = line.strip()
Expand Down Expand Up @@ -559,7 +559,7 @@ def save_xml_result(self):
for k, v in totals.items():
root.set(k, str(v))

xmlpath = os.path.join(support.SAVEDCWD, self.ns.xmlpath)
xmlpath = os.path.join(os_helper.SAVEDCWD, self.ns.xmlpath)
with open(xmlpath, 'wb') as f:
for s in ET.tostringlist(root):
f.write(s)
Expand Down Expand Up @@ -597,7 +597,7 @@ def create_temp_dir(self):
test_cwd = 'test_python_worker_{}'.format(pid)
else:
test_cwd = 'test_python_{}'.format(pid)
test_cwd += support.FS_NONASCII
test_cwd += os_helper.FS_NONASCII
test_cwd = os.path.join(self.tmp_dir, test_cwd)
return test_cwd

Expand All @@ -609,10 +609,10 @@ def cleanup(self):
for name in glob.glob(path):
if os.path.isdir(name):
print("Remove directory: %s" % name)
support.rmtree(name)
os_helper.rmtree(name)
else:
print("Remove file: %s" % name)
support.unlink(name)
os_helper.unlink(name)

def main(self, tests=None, **kwargs):
self.parse_args(kwargs)
Expand All @@ -629,7 +629,7 @@ def main(self, tests=None, **kwargs):
# Run the tests in a context manager that temporarily changes the CWD
# 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.
# The original CWD is available from os_helper.SAVEDCWD.
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
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/runtest_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import traceback
import types
from test import support
from test.support import os_helper

from test.libregrtest.runtest import (
runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME,
Expand Down Expand Up @@ -70,7 +71,7 @@ def run_test_in_subprocess(testname, ns):
stderr=subprocess.PIPE,
universal_newlines=True,
close_fds=(os.name != 'nt'),
cwd=support.SAVEDCWD,
cwd=os_helper.SAVEDCWD,
**kw)


Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_aifc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from test.support import check_no_resource_warning, findfile, TESTFN, unlink
from test.support import findfile
from test.support.os_helper import TESTFN, unlink
from test.support.warnings_helper import check_no_resource_warning
import unittest
from unittest import mock
from test import audiotests
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import shutil
import subprocess
import threading
from test.support import import_helper
from test.support import threading_helper
from test.support import unlink
from test.support.os_helper import unlink
import _compression
import sys


# Skip tests if the bz2 module doesn't exist.
bz2 = support.import_module('bz2')
bz2 = import_helper.import_module('bz2')
from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor

has_cmdline_bunzip2 = None
Expand Down
9 changes: 6 additions & 3 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
from weakref import proxy
import contextlib

from test.support import import_helper
from test.support import threading_helper
from test.support.script_helper import assert_python_ok

import functools

py_functools = support.import_fresh_module('functools', blocked=['_functools'])
c_functools = support.import_fresh_module('functools', fresh=['_functools'])
py_functools = import_helper.import_fresh_module('functools',
blocked=['_functools'])
c_functools = import_helper.import_fresh_module('functools',
fresh=['_functools'])

decimal = support.import_fresh_module('decimal', fresh=['_decimal'])
decimal = import_helper.import_fresh_module('decimal', fresh=['_decimal'])

@contextlib.contextmanager
def replaced_module(name, replacement):
Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ast
import unittest
from test import support
from test.support import import_helper
from textwrap import dedent
import os
import re
Expand All @@ -24,17 +25,17 @@ def check_syntax_error(self, err, basename, lineno, offset=1):
self.assertEqual(err.offset, offset)

def test_future1(self):
with support.CleanImport('future_test1'):
with import_helper.CleanImport('future_test1'):
from test import future_test1
self.assertEqual(future_test1.result, 6)

def test_future2(self):
with support.CleanImport('future_test2'):
with import_helper.CleanImport('future_test2'):
from test import future_test2
self.assertEqual(future_test2.result, 6)

def test_future3(self):
with support.CleanImport('test_future3'):
with import_helper.CleanImport('test_future3'):
from test import test_future3

def test_badfuture3(self):
Expand Down Expand Up @@ -113,7 +114,7 @@ def test_parserhack(self):
self.fail("syntax error didn't occur")

def test_multiple_features(self):
with support.CleanImport("test.test_future5"):
with import_helper.CleanImport("test.test_future5"):
from test import test_future5

def test_unicode_literals_exec(self):
Expand Down
12 changes: 7 additions & 5 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import tempfile
from test.support.script_helper import assert_python_ok, assert_python_failure
from test import support
from test.support import os_helper
from test.support import socket_helper
from test.support import threading_helper
from test.support import warnings_helper
from test.support.logging_helper import TestHandler
import textwrap
import threading
Expand Down Expand Up @@ -1169,7 +1171,7 @@ class ConfigFileTest(BaseTest):

"""Reading logging config from a .ini-style config file."""

check_no_resource_warning = support.check_no_resource_warning
check_no_resource_warning = warnings_helper.check_no_resource_warning
expected_log_pat = r"^(\w+) \+\+ (\w+)$"

# config0 is a standard configuration.
Expand Down Expand Up @@ -1756,7 +1758,7 @@ def setUp(self):

def tearDown(self):
SocketHandlerTest.tearDown(self)
support.unlink(self.address)
os_helper.unlink(self.address)

class DatagramHandlerTest(BaseTest):

Expand Down Expand Up @@ -1837,7 +1839,7 @@ def setUp(self):

def tearDown(self):
DatagramHandlerTest.tearDown(self)
support.unlink(self.address)
os_helper.unlink(self.address)

class SysLogHandlerTest(BaseTest):

Expand Down Expand Up @@ -1921,7 +1923,7 @@ def setUp(self):

def tearDown(self):
SysLogHandlerTest.tearDown(self)
support.unlink(self.address)
os_helper.unlink(self.address)

@unittest.skipUnless(socket_helper.IPV6_ENABLED,
'IPv6 support required for this test.')
Expand Down Expand Up @@ -2175,7 +2177,7 @@ class ConfigDictTest(BaseTest):

"""Reading logging config from a dictionary."""

check_no_resource_warning = support.check_no_resource_warning
check_no_resource_warning = warnings_helper.check_no_resource_warning
expected_log_pat = r"^(\w+) \+\+ (\w+)$"

# config0 is a standard configuration.
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import threading
import time
import unittest
from test.support import TESTFN, run_unittest, cpython_only
from test.support import run_unittest, cpython_only
from test.support import threading_helper
from test.support.os_helper import TESTFN


try:
select.poll
Expand Down
35 changes: 18 additions & 17 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest
from test import libregrtest
from test import support
from test.support import os_helper
from test.libregrtest import utils


Expand Down Expand Up @@ -161,12 +162,12 @@ def test_ignore(self):
self.assertEqual(ns.ignore_tests, ['pattern'])
self.checkError([opt], 'expected one argument')

self.addCleanup(support.unlink, support.TESTFN)
with open(support.TESTFN, "w") as fp:
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
with open(os_helper.TESTFN, "w") as fp:
print('matchfile1', file=fp)
print('matchfile2', file=fp)

filename = os.path.abspath(support.TESTFN)
filename = os.path.abspath(os_helper.TESTFN)
ns = libregrtest._parse_args(['-m', 'match',
'--ignorefile', filename])
self.assertEqual(ns.ignore_tests,
Expand All @@ -183,12 +184,12 @@ def test_match(self):
'-m', 'pattern2'])
self.assertEqual(ns.match_tests, ['pattern1', 'pattern2'])

self.addCleanup(support.unlink, support.TESTFN)
with open(support.TESTFN, "w") as fp:
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
with open(os_helper.TESTFN, "w") as fp:
print('matchfile1', file=fp)
print('matchfile2', file=fp)

filename = os.path.abspath(support.TESTFN)
filename = os.path.abspath(os_helper.TESTFN)
ns = libregrtest._parse_args(['-m', 'match',
'--matchfile', filename])
self.assertEqual(ns.match_tests,
Expand Down Expand Up @@ -237,7 +238,7 @@ def test_memlimit(self):

def test_testdir(self):
ns = libregrtest._parse_args(['--testdir', 'foo'])
self.assertEqual(ns.testdir, os.path.join(support.SAVEDCWD, 'foo'))
self.assertEqual(ns.testdir, os.path.join(os_helper.SAVEDCWD, 'foo'))
self.checkError(['--testdir'], 'expected one argument')

def test_runleaks(self):
Expand Down Expand Up @@ -284,7 +285,7 @@ def test_coverdir(self):
with self.subTest(opt=opt):
ns = libregrtest._parse_args([opt, 'foo'])
self.assertEqual(ns.coverdir,
os.path.join(support.SAVEDCWD, 'foo'))
os.path.join(os_helper.SAVEDCWD, 'foo'))
self.checkError([opt], 'expected one argument')

def test_nocoverdir(self):
Expand Down Expand Up @@ -363,7 +364,7 @@ def setUp(self):
self.testdir = os.path.realpath(os.path.dirname(__file__))

self.tmptestdir = tempfile.mkdtemp()
self.addCleanup(support.rmtree, self.tmptestdir)
self.addCleanup(os_helper.rmtree, self.tmptestdir)

def create_test(self, name=None, code=None):
if not name:
Expand All @@ -384,7 +385,7 @@ def test_empty_test(self):
name = self.TESTNAME_PREFIX + name
path = os.path.join(self.tmptestdir, name + '.py')

self.addCleanup(support.unlink, path)
self.addCleanup(os_helper.unlink, path)
# Use 'x' mode to ensure that we do not override existing tests
try:
with open(path, 'x', encoding='utf-8') as fp:
Expand Down Expand Up @@ -770,8 +771,8 @@ def test_fromfile(self):
# Write the list of files using a format similar to regrtest output:
# [1/2] test_1
# [2/2] test_2
filename = support.TESTFN
self.addCleanup(support.unlink, filename)
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)

# test format '0:00:00 [2/7] test_opcodes -- test_grammar took 0 sec'
with open(filename, "w") as fp:
Expand Down Expand Up @@ -886,7 +887,7 @@ def check_leak(self, code, what):
test = self.create_test('huntrleaks', code=code)

filename = 'reflog.txt'
self.addCleanup(support.unlink, filename)
self.addCleanup(os_helper.unlink, filename)
output = self.run_tests('--huntrleaks', '3:3:', test,
exitcode=2,
stderr=subprocess.STDOUT)
Expand Down Expand Up @@ -997,8 +998,8 @@ def test_method4(self):
testname = self.create_test(code=code)

# only run a subset
filename = support.TESTFN
self.addCleanup(support.unlink, filename)
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)

subset = [
# only ignore the method name
Expand Down Expand Up @@ -1038,8 +1039,8 @@ def test_method4(self):
self.assertEqual(methods, all_methods)

# only run a subset
filename = support.TESTFN
self.addCleanup(support.unlink, filename)
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)

subset = [
# only match the method name
Expand Down
Loading