bpo-40275: Use new test.support helper submodules in tests (GH-21764)
This commit is contained in:
parent
46e19b61d3
commit
598a951844
|
@ -5,6 +5,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import test.support
|
import test.support
|
||||||
|
from test.support import import_helper
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
|
|
||||||
libc_name = None
|
libc_name = None
|
||||||
|
@ -117,7 +118,7 @@ class LoaderTest(unittest.TestCase):
|
||||||
@unittest.skipUnless(os.name == "nt",
|
@unittest.skipUnless(os.name == "nt",
|
||||||
'test specific to Windows')
|
'test specific to Windows')
|
||||||
def test_load_dll_with_flags(self):
|
def test_load_dll_with_flags(self):
|
||||||
_sqlite3 = test.support.import_module("_sqlite3")
|
_sqlite3 = import_helper.import_module("_sqlite3")
|
||||||
src = _sqlite3.__file__
|
src = _sqlite3.__file__
|
||||||
if src.lower().endswith("_d.pyd"):
|
if src.lower().endswith("_d.pyd"):
|
||||||
ext = "_d.dll"
|
ext = "_d.dll"
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
import unittest
|
import unittest
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
|
|
||||||
from test.support import TESTFN, unlink
|
from test.support.os_helper import TESTFN, unlink
|
||||||
|
|
||||||
|
|
||||||
class CollationTests(unittest.TestCase):
|
class CollationTests(unittest.TestCase):
|
||||||
def CheckCreateCollationNotString(self):
|
def CheckCreateCollationNotString(self):
|
||||||
|
|
|
@ -28,8 +28,10 @@ import test.support.script_helper
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import hashlib_helper
|
from test.support import hashlib_helper
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
from test.support import threading_helper
|
from test.support import threading_helper
|
||||||
|
from test.support import warnings_helper
|
||||||
|
|
||||||
|
|
||||||
# Skip tests if _multiprocessing wasn't built.
|
# Skip tests if _multiprocessing wasn't built.
|
||||||
|
@ -615,7 +617,7 @@ class _TestProcess(BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _test_child_fd_inflation(self, evt, q):
|
def _test_child_fd_inflation(self, evt, q):
|
||||||
q.put(test.support.fd_count())
|
q.put(os_helper.fd_count())
|
||||||
evt.wait()
|
evt.wait()
|
||||||
|
|
||||||
def test_child_fd_inflation(self):
|
def test_child_fd_inflation(self):
|
||||||
|
@ -819,8 +821,8 @@ class _TestSubclassingProcess(BaseTestCase):
|
||||||
if self.TYPE == "threads":
|
if self.TYPE == "threads":
|
||||||
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
||||||
|
|
||||||
testfn = test.support.TESTFN
|
testfn = os_helper.TESTFN
|
||||||
self.addCleanup(test.support.unlink, testfn)
|
self.addCleanup(os_helper.unlink, testfn)
|
||||||
proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
|
proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
|
||||||
proc.start()
|
proc.start()
|
||||||
proc.join()
|
proc.join()
|
||||||
|
@ -849,8 +851,8 @@ class _TestSubclassingProcess(BaseTestCase):
|
||||||
if self.TYPE == 'threads':
|
if self.TYPE == 'threads':
|
||||||
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
||||||
|
|
||||||
testfn = test.support.TESTFN
|
testfn = os_helper.TESTFN
|
||||||
self.addCleanup(test.support.unlink, testfn)
|
self.addCleanup(os_helper.unlink, testfn)
|
||||||
|
|
||||||
for reason in (
|
for reason in (
|
||||||
[1, 2, 3],
|
[1, 2, 3],
|
||||||
|
@ -1114,7 +1116,7 @@ class _TestQueue(BaseTestCase):
|
||||||
close_queue(queue)
|
close_queue(queue)
|
||||||
|
|
||||||
def test_no_import_lock_contention(self):
|
def test_no_import_lock_contention(self):
|
||||||
with test.support.temp_cwd():
|
with os_helper.temp_cwd():
|
||||||
module_name = 'imported_by_an_imported_module'
|
module_name = 'imported_by_an_imported_module'
|
||||||
with open(module_name + '.py', 'w') as f:
|
with open(module_name + '.py', 'w') as f:
|
||||||
f.write("""if 1:
|
f.write("""if 1:
|
||||||
|
@ -1127,7 +1129,7 @@ class _TestQueue(BaseTestCase):
|
||||||
del q
|
del q
|
||||||
""")
|
""")
|
||||||
|
|
||||||
with test.support.DirsOnSysPath(os.getcwd()):
|
with import_helper.DirsOnSysPath(os.getcwd()):
|
||||||
try:
|
try:
|
||||||
__import__(module_name)
|
__import__(module_name)
|
||||||
except pyqueue.Empty:
|
except pyqueue.Empty:
|
||||||
|
@ -2688,8 +2690,8 @@ class _TestPool(BaseTestCase):
|
||||||
# force state to RUN to emit ResourceWarning in __del__()
|
# force state to RUN to emit ResourceWarning in __del__()
|
||||||
pool._state = multiprocessing.pool.RUN
|
pool._state = multiprocessing.pool.RUN
|
||||||
|
|
||||||
with support.check_warnings(('unclosed running multiprocessing pool',
|
with warnings_helper.check_warnings(
|
||||||
ResourceWarning)):
|
('unclosed running multiprocessing pool', ResourceWarning)):
|
||||||
pool = None
|
pool = None
|
||||||
support.gc_collect()
|
support.gc_collect()
|
||||||
|
|
||||||
|
@ -3199,14 +3201,14 @@ class _TestConnection(BaseTestCase):
|
||||||
p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
|
p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
|
||||||
p.daemon = True
|
p.daemon = True
|
||||||
p.start()
|
p.start()
|
||||||
self.addCleanup(test.support.unlink, test.support.TESTFN)
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
||||||
with open(test.support.TESTFN, "wb") as f:
|
with open(os_helper.TESTFN, "wb") as f:
|
||||||
fd = f.fileno()
|
fd = f.fileno()
|
||||||
if msvcrt:
|
if msvcrt:
|
||||||
fd = msvcrt.get_osfhandle(fd)
|
fd = msvcrt.get_osfhandle(fd)
|
||||||
reduction.send_handle(conn, fd, p.pid)
|
reduction.send_handle(conn, fd, p.pid)
|
||||||
p.join()
|
p.join()
|
||||||
with open(test.support.TESTFN, "rb") as f:
|
with open(os_helper.TESTFN, "rb") as f:
|
||||||
self.assertEqual(f.read(), b"foo")
|
self.assertEqual(f.read(), b"foo")
|
||||||
|
|
||||||
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
|
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
|
||||||
|
@ -3225,8 +3227,8 @@ class _TestConnection(BaseTestCase):
|
||||||
p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
|
p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
|
||||||
p.daemon = True
|
p.daemon = True
|
||||||
p.start()
|
p.start()
|
||||||
self.addCleanup(test.support.unlink, test.support.TESTFN)
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
||||||
with open(test.support.TESTFN, "wb") as f:
|
with open(os_helper.TESTFN, "wb") as f:
|
||||||
fd = f.fileno()
|
fd = f.fileno()
|
||||||
for newfd in range(256, MAXFD):
|
for newfd in range(256, MAXFD):
|
||||||
if not self._is_fd_assigned(newfd):
|
if not self._is_fd_assigned(newfd):
|
||||||
|
@ -3239,7 +3241,7 @@ class _TestConnection(BaseTestCase):
|
||||||
finally:
|
finally:
|
||||||
os.close(newfd)
|
os.close(newfd)
|
||||||
p.join()
|
p.join()
|
||||||
with open(test.support.TESTFN, "rb") as f:
|
with open(os_helper.TESTFN, "rb") as f:
|
||||||
self.assertEqual(f.read(), b"bar")
|
self.assertEqual(f.read(), b"bar")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import warnings_helper
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ class AllTest(unittest.TestCase):
|
||||||
|
|
||||||
def check_all(self, modname):
|
def check_all(self, modname):
|
||||||
names = {}
|
names = {}
|
||||||
with support.check_warnings(
|
with warnings_helper.check_warnings(
|
||||||
(".* (module|package)", DeprecationWarning),
|
(".* (module|package)", DeprecationWarning),
|
||||||
(".* (module|package)", PendingDeprecationWarning),
|
(".* (module|package)", PendingDeprecationWarning),
|
||||||
("", ResourceWarning),
|
("", ResourceWarning),
|
||||||
|
@ -31,7 +32,7 @@ class AllTest(unittest.TestCase):
|
||||||
raise NoAll(modname)
|
raise NoAll(modname)
|
||||||
names = {}
|
names = {}
|
||||||
with self.subTest(module=modname):
|
with self.subTest(module=modname):
|
||||||
with support.check_warnings(
|
with warnings_helper.check_warnings(
|
||||||
("", DeprecationWarning),
|
("", DeprecationWarning),
|
||||||
("", ResourceWarning),
|
("", ResourceWarning),
|
||||||
quiet=True):
|
quiet=True):
|
||||||
|
|
|
@ -12,7 +12,7 @@ from asyncio.proactor_events import _ProactorSocketTransport
|
||||||
from asyncio.proactor_events import _ProactorWritePipeTransport
|
from asyncio.proactor_events import _ProactorWritePipeTransport
|
||||||
from asyncio.proactor_events import _ProactorDuplexPipeTransport
|
from asyncio.proactor_events import _ProactorDuplexPipeTransport
|
||||||
from asyncio.proactor_events import _ProactorDatagramTransport
|
from asyncio.proactor_events import _ProactorDatagramTransport
|
||||||
from test import support
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
from test.test_asyncio import utils as test_utils
|
from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
@ -935,20 +935,20 @@ class ProactorEventLoopUnixSockSendfileTests(test_utils.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
with open(support.TESTFN, 'wb') as fp:
|
with open(os_helper.TESTFN, 'wb') as fp:
|
||||||
fp.write(cls.DATA)
|
fp.write(cls.DATA)
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
support.unlink(support.TESTFN)
|
os_helper.unlink(os_helper.TESTFN)
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.loop = asyncio.ProactorEventLoop()
|
self.loop = asyncio.ProactorEventLoop()
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
self.addCleanup(self.loop.close)
|
self.addCleanup(self.loop.close)
|
||||||
self.file = open(support.TESTFN, 'rb')
|
self.file = open(os_helper.TESTFN, 'rb')
|
||||||
self.addCleanup(self.file.close)
|
self.addCleanup(self.file.close)
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import warnings
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
from test.support import TestFailed
|
from test.support import TestFailed
|
||||||
from test.support.os_helper import FakePath
|
from test.support.os_helper import FakePath
|
||||||
from test import support, test_genericpath
|
from test import test_genericpath
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ class TestNtpath(NtpathTestCase):
|
||||||
os.mkdir(ABSTFN)
|
os.mkdir(ABSTFN)
|
||||||
self.addCleanup(os_helper.rmtree, ABSTFN)
|
self.addCleanup(os_helper.rmtree, ABSTFN)
|
||||||
|
|
||||||
with support.change_cwd(ABSTFN):
|
with os_helper.change_cwd(ABSTFN):
|
||||||
os.mkdir("subdir")
|
os.mkdir("subdir")
|
||||||
os.chdir("subdir")
|
os.chdir("subdir")
|
||||||
os.symlink(".", "recursive")
|
os.symlink(".", "recursive")
|
||||||
|
@ -443,11 +443,11 @@ class TestNtpath(NtpathTestCase):
|
||||||
|
|
||||||
self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short))
|
self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short))
|
||||||
|
|
||||||
with support.change_cwd(test_dir_long):
|
with os_helper.change_cwd(test_dir_long):
|
||||||
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
||||||
with support.change_cwd(test_dir_long.lower()):
|
with os_helper.change_cwd(test_dir_long.lower()):
|
||||||
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
||||||
with support.change_cwd(test_dir_short):
|
with os_helper.change_cwd(test_dir_short):
|
||||||
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
|
||||||
|
|
||||||
def test_expandvars(self):
|
def test_expandvars(self):
|
||||||
|
@ -673,7 +673,7 @@ class TestNtpath(NtpathTestCase):
|
||||||
# locations below cannot then refer to mount points
|
# locations below cannot then refer to mount points
|
||||||
#
|
#
|
||||||
drive, path = ntpath.splitdrive(sys.executable)
|
drive, path = ntpath.splitdrive(sys.executable)
|
||||||
with support.change_cwd(ntpath.dirname(sys.executable)):
|
with os_helper.change_cwd(ntpath.dirname(sys.executable)):
|
||||||
self.assertFalse(ntpath.ismount(drive.lower()))
|
self.assertFalse(ntpath.ismount(drive.lower()))
|
||||||
self.assertFalse(ntpath.ismount(drive.upper()))
|
self.assertFalse(ntpath.ismount(drive.upper()))
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import import_helper
|
||||||
support.requires('audio')
|
support.requires('audio')
|
||||||
|
|
||||||
from test.support import findfile
|
from test.support import findfile
|
||||||
|
|
||||||
ossaudiodev = support.import_module('ossaudiodev')
|
ossaudiodev = import_helper.import_module('ossaudiodev')
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -196,7 +196,7 @@ class PlatformTest(unittest.TestCase):
|
||||||
# using it, per
|
# using it, per
|
||||||
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
|
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
|
||||||
try:
|
try:
|
||||||
with support.EnvironmentVarGuard() as environ:
|
with os_helper.EnvironmentVarGuard() as environ:
|
||||||
if 'PROCESSOR_ARCHITEW6432' in environ:
|
if 'PROCESSOR_ARCHITEW6432' in environ:
|
||||||
del environ['PROCESSOR_ARCHITEW6432']
|
del environ['PROCESSOR_ARCHITEW6432']
|
||||||
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
|
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
|
||||||
|
|
|
@ -2,7 +2,9 @@ import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import unittest
|
import unittest
|
||||||
from posixpath import realpath, abspath, dirname, basename
|
from posixpath import realpath, abspath, dirname, basename
|
||||||
from test import support, test_genericpath
|
from test import test_genericpath
|
||||||
|
from test.support import import_helper
|
||||||
|
from test.support import os_helper
|
||||||
from test.support import FakePath
|
from test.support import FakePath
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
@ -15,7 +17,7 @@ except ImportError:
|
||||||
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
|
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
|
||||||
# being an absolute path, so we need this.
|
# being an absolute path, so we need this.
|
||||||
|
|
||||||
ABSTFN = abspath(support.TESTFN)
|
ABSTFN = abspath(os_helper.TESTFN)
|
||||||
|
|
||||||
def skip_if_ABSTFN_contains_backslash(test):
|
def skip_if_ABSTFN_contains_backslash(test):
|
||||||
"""
|
"""
|
||||||
|
@ -40,8 +42,8 @@ class PosixPathTest(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for suffix in ["", "1", "2"]:
|
for suffix in ["", "1", "2"]:
|
||||||
support.unlink(support.TESTFN + suffix)
|
os_helper.unlink(os_helper.TESTFN + suffix)
|
||||||
safe_rmdir(support.TESTFN + suffix)
|
safe_rmdir(os_helper.TESTFN + suffix)
|
||||||
|
|
||||||
def test_join(self):
|
def test_join(self):
|
||||||
self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"),
|
self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"),
|
||||||
|
@ -152,25 +154,25 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo")
|
self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo")
|
||||||
|
|
||||||
def test_islink(self):
|
def test_islink(self):
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "1"), False)
|
||||||
self.assertIs(posixpath.lexists(support.TESTFN + "2"), False)
|
self.assertIs(posixpath.lexists(os_helper.TESTFN + "2"), False)
|
||||||
|
|
||||||
with open(support.TESTFN + "1", "wb") as f:
|
with open(os_helper.TESTFN + "1", "wb") as f:
|
||||||
f.write(b"foo")
|
f.write(b"foo")
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "1"), False)
|
||||||
|
|
||||||
if support.can_symlink():
|
if os_helper.can_symlink():
|
||||||
os.symlink(support.TESTFN + "1", support.TESTFN + "2")
|
os.symlink(os_helper.TESTFN + "1", os_helper.TESTFN + "2")
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "2"), True)
|
||||||
os.remove(support.TESTFN + "1")
|
os.remove(os_helper.TESTFN + "1")
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "2"), True)
|
||||||
self.assertIs(posixpath.exists(support.TESTFN + "2"), False)
|
self.assertIs(posixpath.exists(os_helper.TESTFN + "2"), False)
|
||||||
self.assertIs(posixpath.lexists(support.TESTFN + "2"), True)
|
self.assertIs(posixpath.lexists(os_helper.TESTFN + "2"), True)
|
||||||
|
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "\udfff"), False)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "\udfff"), False)
|
||||||
self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\xff"), False)
|
self.assertIs(posixpath.islink(os.fsencode(os_helper.TESTFN) + b"\xff"), False)
|
||||||
self.assertIs(posixpath.islink(support.TESTFN + "\x00"), False)
|
self.assertIs(posixpath.islink(os_helper.TESTFN + "\x00"), False)
|
||||||
self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\x00"), False)
|
self.assertIs(posixpath.islink(os.fsencode(os_helper.TESTFN) + b"\x00"), False)
|
||||||
|
|
||||||
def test_ismount(self):
|
def test_ismount(self):
|
||||||
self.assertIs(posixpath.ismount("/"), True)
|
self.assertIs(posixpath.ismount("/"), True)
|
||||||
|
@ -190,7 +192,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertIs(posixpath.ismount('/\x00'), False)
|
self.assertIs(posixpath.ismount('/\x00'), False)
|
||||||
self.assertIs(posixpath.ismount(b'/\x00'), False)
|
self.assertIs(posixpath.ismount(b'/\x00'), False)
|
||||||
|
|
||||||
@unittest.skipUnless(support.can_symlink(),
|
@unittest.skipUnless(os_helper.can_symlink(),
|
||||||
"Test requires symlink support")
|
"Test requires symlink support")
|
||||||
def test_ismount_symlinks(self):
|
def test_ismount_symlinks(self):
|
||||||
# Symlinks are never mountpoints.
|
# Symlinks are never mountpoints.
|
||||||
|
@ -245,7 +247,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
|
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
|
||||||
|
|
||||||
def test_expanduser_home_envvar(self):
|
def test_expanduser_home_envvar(self):
|
||||||
with support.EnvironmentVarGuard() as env:
|
with os_helper.EnvironmentVarGuard() as env:
|
||||||
env['HOME'] = '/home/victor'
|
env['HOME'] = '/home/victor'
|
||||||
self.assertEqual(posixpath.expanduser("~"), "/home/victor")
|
self.assertEqual(posixpath.expanduser("~"), "/home/victor")
|
||||||
|
|
||||||
|
@ -261,7 +263,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
|
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
|
||||||
|
|
||||||
def test_expanduser_pwd(self):
|
def test_expanduser_pwd(self):
|
||||||
pwd = support.import_module('pwd')
|
pwd = import_helper.import_module('pwd')
|
||||||
|
|
||||||
self.assertIsInstance(posixpath.expanduser("~/"), str)
|
self.assertIsInstance(posixpath.expanduser("~/"), str)
|
||||||
self.assertIsInstance(posixpath.expanduser(b"~/"), bytes)
|
self.assertIsInstance(posixpath.expanduser(b"~/"), bytes)
|
||||||
|
@ -281,7 +283,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes)
|
self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes)
|
||||||
self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes)
|
self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes)
|
||||||
|
|
||||||
with support.EnvironmentVarGuard() as env:
|
with os_helper.EnvironmentVarGuard() as env:
|
||||||
# expanduser should fall back to using the password database
|
# expanduser should fall back to using the password database
|
||||||
del env['HOME']
|
del env['HOME']
|
||||||
|
|
||||||
|
@ -348,7 +350,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
os.symlink(ABSTFN+"1", ABSTFN)
|
os.symlink(ABSTFN+"1", ABSTFN)
|
||||||
self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
|
self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN)
|
os_helper.unlink(ABSTFN)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "symlink"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
"Missing symlink implementation")
|
"Missing symlink implementation")
|
||||||
|
@ -358,7 +360,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN)
|
os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN)
|
||||||
self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
|
self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN)
|
os_helper.unlink(ABSTFN)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "symlink"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
"Missing symlink implementation")
|
"Missing symlink implementation")
|
||||||
|
@ -392,15 +394,15 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c")
|
self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c")
|
||||||
|
|
||||||
# Test using relative path as well.
|
# Test using relative path as well.
|
||||||
with support.change_cwd(dirname(ABSTFN)):
|
with os_helper.change_cwd(dirname(ABSTFN)):
|
||||||
self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
|
self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN)
|
os_helper.unlink(ABSTFN)
|
||||||
support.unlink(ABSTFN+"1")
|
os_helper.unlink(ABSTFN+"1")
|
||||||
support.unlink(ABSTFN+"2")
|
os_helper.unlink(ABSTFN+"2")
|
||||||
support.unlink(ABSTFN+"y")
|
os_helper.unlink(ABSTFN+"y")
|
||||||
support.unlink(ABSTFN+"c")
|
os_helper.unlink(ABSTFN+"c")
|
||||||
support.unlink(ABSTFN+"a")
|
os_helper.unlink(ABSTFN+"a")
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "symlink"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
"Missing symlink implementation")
|
"Missing symlink implementation")
|
||||||
|
@ -413,8 +415,8 @@ class PosixPathTest(unittest.TestCase):
|
||||||
os.symlink('self/self/self', ABSTFN + '/link')
|
os.symlink('self/self/self', ABSTFN + '/link')
|
||||||
self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
|
self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN + '/self')
|
os_helper.unlink(ABSTFN + '/self')
|
||||||
support.unlink(ABSTFN + '/link')
|
os_helper.unlink(ABSTFN + '/link')
|
||||||
safe_rmdir(ABSTFN)
|
safe_rmdir(ABSTFN)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "symlink"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
|
@ -430,11 +432,11 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)
|
self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)
|
||||||
|
|
||||||
# Test using relative path as well.
|
# Test using relative path as well.
|
||||||
with support.change_cwd(ABSTFN):
|
with os_helper.change_cwd(ABSTFN):
|
||||||
self.assertEqual(realpath('%d' % depth), ABSTFN)
|
self.assertEqual(realpath('%d' % depth), ABSTFN)
|
||||||
finally:
|
finally:
|
||||||
for i in range(depth + 1):
|
for i in range(depth + 1):
|
||||||
support.unlink(ABSTFN + '/%d' % i)
|
os_helper.unlink(ABSTFN + '/%d' % i)
|
||||||
safe_rmdir(ABSTFN)
|
safe_rmdir(ABSTFN)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "symlink"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
|
@ -450,10 +452,10 @@ class PosixPathTest(unittest.TestCase):
|
||||||
os.mkdir(ABSTFN + "/y")
|
os.mkdir(ABSTFN + "/y")
|
||||||
os.symlink(ABSTFN + "/y", ABSTFN + "/k")
|
os.symlink(ABSTFN + "/y", ABSTFN + "/k")
|
||||||
|
|
||||||
with support.change_cwd(ABSTFN + "/k"):
|
with os_helper.change_cwd(ABSTFN + "/k"):
|
||||||
self.assertEqual(realpath("a"), ABSTFN + "/y/a")
|
self.assertEqual(realpath("a"), ABSTFN + "/y/a")
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN + "/k")
|
os_helper.unlink(ABSTFN + "/k")
|
||||||
safe_rmdir(ABSTFN + "/y")
|
safe_rmdir(ABSTFN + "/y")
|
||||||
safe_rmdir(ABSTFN)
|
safe_rmdir(ABSTFN)
|
||||||
|
|
||||||
|
@ -477,11 +479,11 @@ class PosixPathTest(unittest.TestCase):
|
||||||
# Absolute path.
|
# Absolute path.
|
||||||
self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
|
self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
|
||||||
# Relative path.
|
# Relative path.
|
||||||
with support.change_cwd(dirname(ABSTFN)):
|
with os_helper.change_cwd(dirname(ABSTFN)):
|
||||||
self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
|
self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
|
||||||
ABSTFN + "/k")
|
ABSTFN + "/k")
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN + "/link-y")
|
os_helper.unlink(ABSTFN + "/link-y")
|
||||||
safe_rmdir(ABSTFN + "/k/y")
|
safe_rmdir(ABSTFN + "/k/y")
|
||||||
safe_rmdir(ABSTFN + "/k")
|
safe_rmdir(ABSTFN + "/k")
|
||||||
safe_rmdir(ABSTFN)
|
safe_rmdir(ABSTFN)
|
||||||
|
@ -497,12 +499,12 @@ class PosixPathTest(unittest.TestCase):
|
||||||
os.mkdir(ABSTFN)
|
os.mkdir(ABSTFN)
|
||||||
os.mkdir(ABSTFN + "/k")
|
os.mkdir(ABSTFN + "/k")
|
||||||
os.symlink(ABSTFN, ABSTFN + "link")
|
os.symlink(ABSTFN, ABSTFN + "link")
|
||||||
with support.change_cwd(dirname(ABSTFN)):
|
with os_helper.change_cwd(dirname(ABSTFN)):
|
||||||
base = basename(ABSTFN)
|
base = basename(ABSTFN)
|
||||||
self.assertEqual(realpath(base + "link"), ABSTFN)
|
self.assertEqual(realpath(base + "link"), ABSTFN)
|
||||||
self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
|
self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
|
||||||
finally:
|
finally:
|
||||||
support.unlink(ABSTFN + "link")
|
os_helper.unlink(ABSTFN + "link")
|
||||||
safe_rmdir(ABSTFN + "/k")
|
safe_rmdir(ABSTFN + "/k")
|
||||||
safe_rmdir(ABSTFN)
|
safe_rmdir(ABSTFN)
|
||||||
|
|
||||||
|
@ -627,9 +629,9 @@ class PathLikeTests(unittest.TestCase):
|
||||||
path = posixpath
|
path = posixpath
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file_name = support.TESTFN
|
self.file_name = os_helper.TESTFN
|
||||||
self.file_path = FakePath(support.TESTFN)
|
self.file_path = FakePath(os_helper.TESTFN)
|
||||||
self.addCleanup(support.unlink, self.file_name)
|
self.addCleanup(os_helper.unlink, self.file_name)
|
||||||
with open(self.file_name, 'xb', 0) as file:
|
with open(self.file_name, 'xb', 0) as file:
|
||||||
file.write(b"test_posixpath.PathLikeTests")
|
file.write(b"test_posixpath.PathLikeTests")
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ class PyCompileCLITestCase(unittest.TestCase):
|
||||||
file.write('x = 123\n')
|
file.write('x = 123\n')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
support.rmtree(self.directory)
|
os_helper.rmtree(self.directory)
|
||||||
|
|
||||||
def pycompilecmd(self, *args, **kwargs):
|
def pycompilecmd(self, *args, **kwargs):
|
||||||
# assert_python_* helpers don't return proc object. We'll just use
|
# assert_python_* helpers don't return proc object. We'll just use
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
# -*- coding: koi8-r -*-
|
# -*- coding: koi8-r -*-
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TESTFN, unlink, unload, rmtree, script_helper, captured_stdout
|
from test.support import script_helper, captured_stdout
|
||||||
|
from test.support.os_helper import TESTFN, unlink, rmtree
|
||||||
|
from test.support.import_helper import unload
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
@ -27,7 +28,7 @@ class TestCase(unittest.TestCase):
|
||||||
# we're not about to delete. If we're running under -j, that
|
# we're not about to delete. If we're running under -j, that
|
||||||
# means the test harness provided directory isn't a safe option.
|
# means the test harness provided directory isn't a safe option.
|
||||||
# See http://bugs.python.org/issue15526 for more details
|
# See http://bugs.python.org/issue15526 for more details
|
||||||
with support.change_cwd(path.dirname(sys.executable)):
|
with os_helper.change_cwd(path.dirname(sys.executable)):
|
||||||
empty = path.join(path.dirname(__file__), "empty.vbs")
|
empty = path.join(path.dirname(__file__), "empty.vbs")
|
||||||
startfile(empty)
|
startfile(empty)
|
||||||
startfile(empty, "open")
|
startfile(empty, "open")
|
||||||
|
|
|
@ -3,15 +3,17 @@ import importlib
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import import_helper
|
||||||
|
from test.support import warnings_helper
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestUntestedModules(unittest.TestCase):
|
class TestUntestedModules(unittest.TestCase):
|
||||||
def test_untested_modules_can_be_imported(self):
|
def test_untested_modules_can_be_imported(self):
|
||||||
untested = ('encodings', 'formatter')
|
untested = ('encodings', 'formatter')
|
||||||
with support.check_warnings(quiet=True):
|
with warnings_helper.check_warnings(quiet=True):
|
||||||
for name in untested:
|
for name in untested:
|
||||||
try:
|
try:
|
||||||
support.import_module('test.test_{}'.format(name))
|
import_helper.import_module('test.test_{}'.format(name))
|
||||||
except unittest.SkipTest:
|
except unittest.SkipTest:
|
||||||
importlib.import_module(name)
|
importlib.import_module(name)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,7 +6,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test.support import os_helper
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
raise unittest.SkipTest("test only relevant on win32")
|
raise unittest.SkipTest("test only relevant on win32")
|
||||||
|
@ -109,7 +109,7 @@ class WindowsConsoleIOTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_conout_path(self):
|
def test_conout_path(self):
|
||||||
temp_path = tempfile.mkdtemp()
|
temp_path = tempfile.mkdtemp()
|
||||||
self.addCleanup(support.rmtree, temp_path)
|
self.addCleanup(os_helper.rmtree, temp_path)
|
||||||
|
|
||||||
conout_path = os.path.join(temp_path, 'CONOUT$')
|
conout_path = os.path.join(temp_path, 'CONOUT$')
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import functools
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import import_fresh_module
|
from test.support.import_helper import import_fresh_module
|
||||||
|
|
||||||
OS_ENV_LOCK = threading.Lock()
|
OS_ENV_LOCK = threading.Lock()
|
||||||
TZPATH_LOCK = threading.Lock()
|
TZPATH_LOCK = threading.Lock()
|
||||||
|
|
Loading…
Reference in New Issue