import textwrap
from test import support
+from test.support import import_helper
+from test.support import os_helper
from test.support.script_helper import (
make_pkg, make_script, make_zip_pkg, make_zip_script,
assert_python_ok, assert_python_failure, spawn_python, kill_python)
self.check_repl_stderr_flush(True)
def test_basic_script(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
self._check_script(script_name, script_name, script_name,
script_dir, None,
def test_script_abspath(self):
# pass the script using the relative path, expect the absolute path
# in __file__
- with support.temp_cwd() as script_dir:
+ with os_helper.temp_cwd() as script_dir:
self.assertTrue(os.path.isabs(script_dir), script_dir)
script_name = _make_test_script(script_dir, 'script')
importlib.machinery.SourceFileLoader)
def test_script_compiled(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
self._check_script(pyc_file, pyc_file,
pyc_file, script_dir, None,
importlib.machinery.SourcelessFileLoader)
def test_directory(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
self._check_script(script_dir, script_name, script_dir,
script_dir, '',
importlib.machinery.SourceFileLoader)
def test_directory_compiled(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
self._check_script(script_dir, pyc_file, script_dir,
script_dir, '',
importlib.machinery.SourcelessFileLoader)
def test_directory_error(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
msg = "can't find '__main__' module in %r" % script_dir
self._check_import_error(script_dir, msg)
def test_zipfile(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
self._check_script(zip_name, run_name, zip_name, zip_name, '',
zipimport.zipimporter)
def test_zipfile_compiled_timestamp(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
compiled_name = py_compile.compile(
script_name, doraise=True,
zipimport.zipimporter)
def test_zipfile_compiled_checked_hash(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
compiled_name = py_compile.compile(
script_name, doraise=True,
zipimport.zipimporter)
def test_zipfile_compiled_unchecked_hash(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
compiled_name = py_compile.compile(
script_name, doraise=True,
zipimport.zipimporter)
def test_zipfile_error(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'not_main')
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
msg = "can't find '__main__' module in %r" % zip_name
self._check_import_error(zip_name, msg)
def test_module_in_package(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, 'script')
cwd=script_dir)
def test_module_in_package_in_zipfile(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script')
self._check_script(["-m", "test_pkg.script"], run_name, run_name,
script_dir, 'test_pkg', zipimport.zipimporter,
PYTHONPATH=zip_name, cwd=script_dir)
def test_module_in_subpackage_in_zipfile(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
self._check_script(["-m", "test_pkg.test_pkg.script"], run_name, run_name,
script_dir, 'test_pkg.test_pkg',
PYTHONPATH=zip_name, cwd=script_dir)
def test_package(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, '__main__')
cwd=script_dir)
def test_package_compiled(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, '__main__')
compiled_name = py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
self._check_script(["-m", "test_pkg"], pyc_file,
pyc_file, script_dir, 'test_pkg',
importlib.machinery.SourcelessFileLoader,
cwd=script_dir)
def test_package_error(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
msg = ("'test_pkg' is a package and cannot "
self._check_import_error(["-m", "test_pkg"], msg, cwd=script_dir)
def test_package_recursion(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
main_dir = os.path.join(pkg_dir, '__main__')
def test_issue8202(self):
# Make sure package __init__ modules see "-m" in sys.argv0 while
# searching for the module to execute
- with support.temp_dir() as script_dir:
- with support.change_cwd(path=script_dir):
+ with os_helper.temp_dir() as script_dir:
+ with os_helper.change_cwd(path=script_dir):
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
script_name = _make_test_script(pkg_dir, 'script')
def test_issue8202_dash_c_file_ignored(self):
# Make sure a "-c" file in the current directory
# does not alter the value of sys.path[0]
- with support.temp_dir() as script_dir:
- with support.change_cwd(path=script_dir):
+ with os_helper.temp_dir() as script_dir:
+ with os_helper.change_cwd(path=script_dir):
with open("-c", "w") as f:
f.write("data")
rc, out, err = assert_python_ok('-c',
def test_issue8202_dash_m_file_ignored(self):
# Make sure a "-m" file in the current directory
# does not alter the value of sys.path[0]
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'other')
- with support.change_cwd(path=script_dir):
+ with os_helper.change_cwd(path=script_dir):
with open("-m", "w") as f:
f.write("data")
rc, out, err = assert_python_ok('-m', 'other', *example_args,
def test_issue20884(self):
# On Windows, script with encoding cookie and LF line ending
# will be failed.
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = os.path.join(script_dir, "issue20884.py")
with open(script_name, "w", newline='\n') as f:
f.write("#coding: iso-8859-1\n")
f.write('x'*80 + '\n')
f.write('"""\n')
- with support.change_cwd(path=script_dir):
+ with os_helper.change_cwd(path=script_dir):
rc, out, err = assert_python_ok(script_name)
self.assertEqual(b"", out)
self.assertEqual(b"", err)
@contextlib.contextmanager
def setup_test_pkg(self, *args):
- with support.temp_dir() as script_dir, \
- support.change_cwd(path=script_dir):
+ with os_helper.temp_dir() as script_dir, \
+ os_helper.change_cwd(path=script_dir):
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir, *args)
yield pkg_dir
self.assertNotIn(b'Traceback', err)
def test_dash_m_bad_pyc(self):
- with support.temp_dir() as script_dir, \
- support.change_cwd(path=script_dir):
+ with os_helper.temp_dir() as script_dir, \
+ os_helper.change_cwd(path=script_dir):
os.mkdir('test_pkg')
# Create invalid *.pyc as empty file
with open('test_pkg/__init__.pyc', 'wb'):
self.assertNotIn(b'Traceback', err)
def test_hint_when_triying_to_import_a_py_file(self):
- with support.temp_dir() as script_dir, \
- support.change_cwd(path=script_dir):
+ with os_helper.temp_dir() as script_dir, \
+ os_helper.change_cwd(path=script_dir):
# Create invalid *.pyc as empty file
with open('asyncio.py', 'wb'):
pass
except:
raise NameError from None
""")
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = stderr.decode('ascii').split('\n')
# Mac OS X denies the creation of a file with an invalid UTF-8 name.
# Windows allows creating a name with an arbitrary bytes name, but
# Python cannot a undecodable bytes argument to a subprocess.
- if (support.TESTFN_UNDECODABLE
+ if (os_helper.TESTFN_UNDECODABLE
and sys.platform not in ('win32', 'darwin')):
- name = os.fsdecode(support.TESTFN_UNDECODABLE)
- elif support.TESTFN_NONASCII:
- name = support.TESTFN_NONASCII
+ name = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
+ elif os_helper.TESTFN_NONASCII:
+ name = os_helper.TESTFN_NONASCII
else:
- self.skipTest("need support.TESTFN_NONASCII")
+ self.skipTest("need os_helper.TESTFN_NONASCII")
# Issue #16218
source = 'print(ascii(__file__))\n'
script_name = _make_test_script(os.getcwd(), name, source)
- self.addCleanup(support.unlink, script_name)
+ self.addCleanup(os_helper.unlink, script_name)
rc, stdout, stderr = assert_python_ok(script_name)
self.assertEqual(
ascii(script_name),
if error:
sys.exit(error)
""")
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = stderr.decode('ascii')
def test_syntaxerror_unindented_caret_position(self):
script = "1 + 1 = 2\n"
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
if True:
1 + 1 = 2
""")
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
def test_syntaxerror_multi_line_fstring(self):
script = 'foo = f"""{}\nfoo"""\n'
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
self.assertEqual(
def test_syntaxerror_invalid_escape_sequence_multi_line(self):
script = 'foo = """\\q"""\n'
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(
'-Werror', script_name,
""")
# Always show full path diffs on errors
self.maxDiff = None
- with support.temp_dir() as work_dir, support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as work_dir, os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__', script)
# Reference output comes from directly executing __main__.py
# We omit PYTHONPATH and user site to align with isolated mode
""")
# Always show full path diffs on errors
self.maxDiff = None
- with support.temp_dir() as work_dir:
+ with os_helper.temp_dir() as work_dir:
script_dir = os.path.join(work_dir, "script_pkg")
os.mkdir(script_dir)
script_name = _make_test_script(script_dir, '__main__', script)
import sys
import unittest
from test import support
+from test.support import warnings_helper
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
import io
def test_warning(self):
# Test that the warning is only returned once.
- with support.check_warnings((".*literal", SyntaxWarning)) as w:
+ with warnings_helper.check_warnings((".*literal", SyntaxWarning)) as w:
compile_command("0 is 0")
self.assertEqual(len(w.warnings), 1)
import unittest
from contextlib import * # Tests __all__
from test import support
+from test.support import os_helper
import weakref
1 / 0
self.assertTrue(f.closed)
finally:
- support.unlink(tfn)
+ os_helper.unlink(tfn)
class LockContextTestCase(unittest.TestCase):
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
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
import unittest
from test import support
+from test.support import os_helper
# TODO:
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
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):
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
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)
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[:] = ['.']
-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
import io
import tempfile
from test import support
+from test.support import os_helper
import unittest
import textwrap
import mailbox
def _delete_recursively(self, target):
# Delete a file or delete a directory recursively
if os.path.isdir(target):
- support.rmtree(target)
+ os_helper.rmtree(target)
elif os.path.exists(target):
- support.unlink(target)
+ os_helper.unlink(target)
class TestMailbox(TestBase):
_template = 'From: foo\n\n%s\n'
def setUp(self):
- self._path = support.TESTFN
+ self._path = os_helper.TESTFN
self._delete_recursively(self._path)
self._box = self._factory(self._path)
# the mtime and should cause a re-read. Note that "sleep
# emulation" is still in effect, as skewfactor is -3.
filename = os.path.join(self._path, 'cur', 'stray-file')
- support.create_empty_file(filename)
+ os_helper.create_empty_file(filename)
os.unlink(filename)
self._box._refresh()
self.assertTrue(refreshed())
self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
- support.unlink(lock_remnant)
+ os_helper.unlink(lock_remnant)
def assertMailboxEmpty(self):
with open(self._path) as f:
self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
- support.unlink(lock_remnant)
+ os_helper.unlink(lock_remnant)
def test_labels(self):
# Get labels from the mailbox
_factory = mailbox.Message # Overridden by subclasses to reuse tests
def setUp(self):
- self._path = support.TESTFN
+ self._path = os_helper.TESTFN
def tearDown(self):
self._delete_recursively(self._path)
class TestProxyFile(TestProxyFileBase, unittest.TestCase):
def setUp(self):
- self._path = support.TESTFN
+ self._path = os_helper.TESTFN
self._file = open(self._path, 'wb+')
def tearDown(self):
class TestPartialFile(TestProxyFileBase, unittest.TestCase):
def setUp(self):
- self._path = support.TESTFN
+ self._path = os_helper.TESTFN
self._file = open(self._path, 'wb+')
def tearDown(self):
def setUp(self):
# create a new maildir mailbox to work with:
- self._dir = support.TESTFN
+ self._dir = os_helper.TESTFN
if os.path.isdir(self._dir):
- support.rmtree(self._dir)
+ os_helper.rmtree(self._dir)
elif os.path.isfile(self._dir):
- support.unlink(self._dir)
+ os_helper.unlink(self._dir)
os.mkdir(self._dir)
os.mkdir(os.path.join(self._dir, "cur"))
os.mkdir(os.path.join(self._dir, "tmp"))
def tearDown(self):
list(map(os.unlink, self._msgfiles))
- support.rmdir(os.path.join(self._dir, "cur"))
- support.rmdir(os.path.join(self._dir, "tmp"))
- support.rmdir(os.path.join(self._dir, "new"))
- support.rmdir(self._dir)
+ os_helper.rmdir(os.path.join(self._dir, "cur"))
+ os_helper.rmdir(os.path.join(self._dir, "tmp"))
+ os_helper.rmdir(os.path.join(self._dir, "new"))
+ os_helper.rmdir(self._dir)
def createMessage(self, dir, mbox=False):
t = int(time.time() % 1000000)
"""Test an empty maildir mailbox"""
# Test for regression on bug #117490:
# Make sure the boxes attribute actually gets set.
- self.mbox = mailbox.Maildir(support.TESTFN)
+ self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertTrue(hasattr(self.mbox, "boxes"))
#self.assertEqual(len(self.mbox.boxes), 0)
self.assertIsNone(self.mbox.next())
def test_nonempty_maildir_cur(self):
self.createMessage("cur")
- self.mbox = mailbox.Maildir(support.TESTFN)
+ self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 1)
self.assertIsNotNone(self.mbox.next())
self.assertIsNone(self.mbox.next())
def test_nonempty_maildir_new(self):
self.createMessage("new")
- self.mbox = mailbox.Maildir(support.TESTFN)
+ self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 1)
self.assertIsNotNone(self.mbox.next())
self.assertIsNone(self.mbox.next())
def test_nonempty_maildir_both(self):
self.createMessage("cur")
self.createMessage("new")
- self.mbox = mailbox.Maildir(support.TESTFN)
+ self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 2)
self.assertIsNotNone(self.mbox.next())
self.assertIsNotNone(self.mbox.next())
# tests __main__ module handling in multiprocessing
from test import support
+from test.support import import_helper
# Skip tests if _multiprocessing wasn't built.
-support.import_module('_multiprocessing')
+import_helper.import_module('_multiprocessing')
import importlib
import importlib.machinery
import os.path
import py_compile
+from test.support import os_helper
from test.support.script_helper import (
make_pkg, make_script, make_zip_pkg, make_zip_script,
assert_python_ok)
self._check_output(script_name, rc, out, err)
def test_basic_script(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
self._check_script(script_name)
def test_basic_script_no_suffix(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script',
omit_suffix=True)
self._check_script(script_name)
# a workaround for that case
# See https://github.com/ipython/ipython/issues/4698
source = test_source_main_skipped_in_children
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'ipython',
source=source)
self._check_script(script_name)
self._check_script(script_no_suffix)
def test_script_compiled(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
self._check_script(pyc_file)
def test_directory(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
self._check_script(script_dir)
def test_directory_compiled(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
self._check_script(script_dir)
def test_zipfile(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
def test_zipfile_compiled(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
compiled_name = py_compile.compile(script_name, doraise=True)
self._check_script(zip_name)
def test_module_in_package(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, 'check_sibling')
self._check_script(launch_name)
def test_module_in_package_in_zipfile(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script')
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name)
self._check_script(launch_name)
def test_module_in_subpackage_in_zipfile(self):
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name)
self._check_script(launch_name)
def test_package(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, '__main__',
def test_package_compiled(self):
source = self.main_in_children_source
- with support.temp_dir() as script_dir:
+ with os_helper.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, '__main__',
source=source)
compiled_name = py_compile.compile(script_name, doraise=True)
os.remove(script_name)
- pyc_file = support.make_legacy_pyc(script_name)
+ pyc_file = import_helper.make_legacy_pyc(script_name)
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
self._check_script(launch_name)
Test suite for OS X interpreter environment variables.
"""
-from test.support import EnvironmentVarGuard
+from test.support.os_helper import EnvironmentVarGuard
import subprocess
import sys
import sysconfig
-from test.support import run_unittest, unload, check_warnings, CleanImport
+from test.support import run_unittest
+from test.support.import_helper import unload, CleanImport
+from test.support.warnings_helper import check_warnings
import unittest
import sys
import importlib
import binascii
import collections
from test import support
+from test.support import os_helper
from io import BytesIO
from plistlib import UID
def tearDown(self):
try:
- os.unlink(support.TESTFN)
+ os.unlink(os_helper.TESTFN)
except:
pass
def test_io(self):
pl = self._create()
- with open(support.TESTFN, 'wb') as fp:
+ with open(os_helper.TESTFN, 'wb') as fp:
plistlib.dump(pl, fp)
- with open(support.TESTFN, 'rb') as fp:
+ with open(os_helper.TESTFN, 'rb') as fp:
pl2 = plistlib.load(fp)
self.assertEqual(dict(pl), dict(pl2))
import unittest
from test import support
+from test.support import import_helper
# Skip this test if _tkinter wasn't built.
-support.import_module('_tkinter')
+import_helper.import_module('_tkinter')
# Skip test if tk cannot be initialized.
support.requires('gui')
import pickle
import unittest
from test import support
+from test.support import import_helper
-turtle = support.import_module('turtle')
+
+turtle = import_helper.import_module('turtle')
Vec2D = turtle.Vec2D
test_config = """\
import faulthandler
-import test.support
+from test.support import import_helper
import unittest
-_xxtestfuzz = test.support.import_module('_xxtestfuzz')
+_xxtestfuzz = import_helper.import_module('_xxtestfuzz')
class TestFuzzer(unittest.TestCase):
import unittest.mock
from test import support
+from test.support import import_helper
+from test.support import os_helper
from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
self.meta_path = sys.meta_path[:]
self.path_hooks = sys.path_hooks[:]
sys.path_importer_cache.clear()
- self.modules_before = support.modules_setup()
+ self.modules_before = import_helper.modules_setup()
def tearDown(self):
sys.path[:] = self.path
sys.meta_path[:] = self.meta_path
sys.path_hooks[:] = self.path_hooks
sys.path_importer_cache.clear()
- support.modules_cleanup(*self.modules_before)
+ import_helper.modules_cleanup(*self.modules_before)
class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
def makeTree(self, files, dirName=TEMP_DIR):
# Create a filesystem based set of modules/packages
# defined by files under the directory dirName.
- self.addCleanup(support.rmtree, dirName)
+ self.addCleanup(os_helper.rmtree, dirName)
for name, (mtime, data) in files.items():
path = os.path.join(dirName, name)
# Create a zip archive based set of modules/packages
# defined by files in the zip file zipName. If the
# key 'stuff' exists in kw it is prepended to the archive.
- self.addCleanup(support.unlink, zipName)
+ self.addCleanup(os_helper.unlink, zipName)
with ZipFile(zipName, "w") as z:
for name, (mtime, data) in files.items():
packdir2 + TESTMOD + pyc_ext: (NOW, test_pyc),
"spam" + pyc_ext: (NOW, test_pyc)}
- self.addCleanup(support.unlink, TEMP_ZIP)
+ self.addCleanup(os_helper.unlink, TEMP_ZIP)
with ZipFile(TEMP_ZIP, "w") as z:
for name, (mtime, data) in files.items():
zinfo = ZipInfo(name, time.localtime(mtime))
files = {packdir2 + "__init__" + pyc_ext: (NOW, test_pyc),
packdir2 + TESTMOD + pyc_ext: (NOW, test_pyc)}
- self.addCleanup(support.unlink, TEMP_ZIP)
+ self.addCleanup(os_helper.unlink, TEMP_ZIP)
with ZipFile(TEMP_ZIP, "w") as z:
for name, (mtime, data) in files.items():
zinfo = ZipInfo(name, time.localtime(mtime))
self.assertEqual(loader.get_filename(mod_name), mod.__file__)
def testGetData(self):
- self.addCleanup(support.unlink, TEMP_ZIP)
+ self.addCleanup(os_helper.unlink, TEMP_ZIP)
with ZipFile(TEMP_ZIP, "w") as z:
z.compression = self.compression
name = "testdata.dat"
files = {TESTMOD + ".py": (NOW, raise_src)}
self.doTest(None, files, TESTMOD, call=self.doTraceback)
- @unittest.skipIf(support.TESTFN_UNENCODABLE is None,
+ @unittest.skipIf(os_helper.TESTFN_UNENCODABLE is None,
"need an unencodable filename")
def testUnencodable(self):
- filename = support.TESTFN_UNENCODABLE + ".zip"
- self.addCleanup(support.unlink, filename)
+ filename = os_helper.TESTFN_UNENCODABLE + ".zip"
+ self.addCleanup(os_helper.unlink, filename)
with ZipFile(filename, "w") as z:
zinfo = ZipInfo(TESTMOD + ".py", time.localtime(NOW))
zinfo.compress_type = self.compression
zipimport.zipimporter(filename).load_module(TESTMOD)
def testBytesPath(self):
- filename = support.TESTFN + ".zip"
- self.addCleanup(support.unlink, filename)
+ filename = os_helper.TESTFN + ".zip"
+ self.addCleanup(os_helper.unlink, filename)
with ZipFile(filename, "w") as z:
zinfo = ZipInfo(TESTMOD + ".py", time.localtime(NOW))
zinfo.compress_type = self.compression
self.assertZipFailure('A' * 33000)
def testEmptyFile(self):
- support.unlink(TESTMOD)
- support.create_empty_file(TESTMOD)
+ os_helper.unlink(TESTMOD)
+ os_helper.create_empty_file(TESTMOD)
self.assertZipFailure(TESTMOD)
def testFileUnreadable(self):
- support.unlink(TESTMOD)
+ os_helper.unlink(TESTMOD)
fd = os.open(TESTMOD, os.O_CREAT, 000)
try:
os.close(fd)
# If we leave "the read-only bit" set on Windows, nothing can
# delete TESTMOD, and later tests suffer bogus failures.
os.chmod(TESTMOD, 0o666)
- support.unlink(TESTMOD)
+ os_helper.unlink(TESTMOD)
def testNotZipFile(self):
- support.unlink(TESTMOD)
+ os_helper.unlink(TESTMOD)
fp = open(TESTMOD, 'w+')
fp.write('a' * 22)
fp.close()
# XXX: disabled until this works on Big-endian machines
def _testBogusZipFile(self):
- support.unlink(TESTMOD)
+ os_helper.unlink(TESTMOD)
fp = open(TESTMOD, 'w+')
fp.write(struct.pack('=I', 0x06054B50))
fp.write('a' * 18)
BadFileZipImportTestCase,
)
finally:
- support.unlink(TESTMOD)
+ os_helper.unlink(TESTMOD)
if __name__ == "__main__":
test_main()