summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericpath.py
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2020-08-03 16:49:18 (GMT)
committerGitHub <noreply@github.com>2020-08-03 16:49:18 (GMT)
commit4660597b51b3d14ce6269d0ed865ab7e22c6ae1f (patch)
tree00ab23106abb1d0023e261685dc4f2077002aabd /Lib/test/test_genericpath.py
parentbb0424b122e3d222a558bd4177ce37befd3e0347 (diff)
downloadcpython-4660597b51b3d14ce6269d0ed865ab7e22c6ae1f.zip
cpython-4660597b51b3d14ce6269d0ed865ab7e22c6ae1f.tar.gz
cpython-4660597b51b3d14ce6269d0ed865ab7e22c6ae1f.tar.bz2
bpo-40275: Use new test.support helper submodules in tests (GH-21448)
Diffstat (limited to 'Lib/test/test_genericpath.py')
-rw-r--r--Lib/test/test_genericpath.py103
1 files changed, 52 insertions, 51 deletions
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index e7acbcd..1ff7f75 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -7,9 +7,10 @@ import os
import sys
import unittest
import warnings
-from test import support
+from test.support import os_helper
+from test.support import warnings_helper
from test.support.script_helper import assert_python_ok
-from test.support import FakePath
+from test.support.os_helper import FakePath
def create_file(filename, data=b'foo'):
@@ -97,8 +98,8 @@ class GenericTest:
self.assertNotEqual(s1[n:n+1], s2[n:n+1])
def test_getsize(self):
- filename = support.TESTFN
- self.addCleanup(support.unlink, filename)
+ filename = os_helper.TESTFN
+ self.addCleanup(os_helper.unlink, filename)
create_file(filename, b'Hello')
self.assertEqual(self.pathmodule.getsize(filename), 5)
@@ -108,8 +109,8 @@ class GenericTest:
self.assertEqual(self.pathmodule.getsize(filename), 12)
def test_filetime(self):
- filename = support.TESTFN
- self.addCleanup(support.unlink, filename)
+ filename = os_helper.TESTFN
+ self.addCleanup(os_helper.unlink, filename)
create_file(filename, b'foo')
@@ -126,9 +127,9 @@ class GenericTest:
)
def test_exists(self):
- filename = support.TESTFN
+ filename = os_helper.TESTFN
bfilename = os.fsencode(filename)
- self.addCleanup(support.unlink, filename)
+ self.addCleanup(os_helper.unlink, filename)
self.assertIs(self.pathmodule.exists(filename), False)
self.assertIs(self.pathmodule.exists(bfilename), False)
@@ -163,7 +164,7 @@ class GenericTest:
self.assertFalse(self.pathmodule.exists(r))
def test_isdir(self):
- filename = support.TESTFN
+ filename = os_helper.TESTFN
bfilename = os.fsencode(filename)
self.assertIs(self.pathmodule.isdir(filename), False)
self.assertIs(self.pathmodule.isdir(bfilename), False)
@@ -178,17 +179,17 @@ class GenericTest:
self.assertIs(self.pathmodule.isdir(filename), False)
self.assertIs(self.pathmodule.isdir(bfilename), False)
finally:
- support.unlink(filename)
+ os_helper.unlink(filename)
try:
os.mkdir(filename)
self.assertIs(self.pathmodule.isdir(filename), True)
self.assertIs(self.pathmodule.isdir(bfilename), True)
finally:
- support.rmdir(filename)
+ os_helper.rmdir(filename)
def test_isfile(self):
- filename = support.TESTFN
+ filename = os_helper.TESTFN
bfilename = os.fsencode(filename)
self.assertIs(self.pathmodule.isfile(filename), False)
self.assertIs(self.pathmodule.isfile(bfilename), False)
@@ -203,20 +204,20 @@ class GenericTest:
self.assertIs(self.pathmodule.isfile(filename), True)
self.assertIs(self.pathmodule.isfile(bfilename), True)
finally:
- support.unlink(filename)
+ os_helper.unlink(filename)
try:
os.mkdir(filename)
self.assertIs(self.pathmodule.isfile(filename), False)
self.assertIs(self.pathmodule.isfile(bfilename), False)
finally:
- support.rmdir(filename)
+ os_helper.rmdir(filename)
def test_samefile(self):
- file1 = support.TESTFN
- file2 = support.TESTFN + "2"
- self.addCleanup(support.unlink, file1)
- self.addCleanup(support.unlink, file2)
+ file1 = os_helper.TESTFN
+ file2 = os_helper.TESTFN + "2"
+ self.addCleanup(os_helper.unlink, file1)
+ self.addCleanup(os_helper.unlink, file2)
create_file(file1)
self.assertTrue(self.pathmodule.samefile(file1, file1))
@@ -227,10 +228,10 @@ class GenericTest:
self.assertRaises(TypeError, self.pathmodule.samefile)
def _test_samefile_on_link_func(self, func):
- test_fn1 = support.TESTFN
- test_fn2 = support.TESTFN + "2"
- self.addCleanup(support.unlink, test_fn1)
- self.addCleanup(support.unlink, test_fn2)
+ test_fn1 = os_helper.TESTFN
+ test_fn2 = os_helper.TESTFN + "2"
+ self.addCleanup(os_helper.unlink, test_fn1)
+ self.addCleanup(os_helper.unlink, test_fn2)
create_file(test_fn1)
@@ -241,7 +242,7 @@ class GenericTest:
create_file(test_fn2)
self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2))
- @support.skip_unless_symlink
+ @os_helper.skip_unless_symlink
def test_samefile_on_symlink(self):
self._test_samefile_on_link_func(os.symlink)
@@ -252,10 +253,10 @@ class GenericTest:
self.skipTest('os.link(): %s' % e)
def test_samestat(self):
- test_fn1 = support.TESTFN
- test_fn2 = support.TESTFN + "2"
- self.addCleanup(support.unlink, test_fn1)
- self.addCleanup(support.unlink, test_fn2)
+ test_fn1 = os_helper.TESTFN
+ test_fn2 = os_helper.TESTFN + "2"
+ self.addCleanup(os_helper.unlink, test_fn1)
+ self.addCleanup(os_helper.unlink, test_fn2)
create_file(test_fn1)
stat1 = os.stat(test_fn1)
@@ -268,10 +269,10 @@ class GenericTest:
self.assertRaises(TypeError, self.pathmodule.samestat)
def _test_samestat_on_link_func(self, func):
- test_fn1 = support.TESTFN + "1"
- test_fn2 = support.TESTFN + "2"
- self.addCleanup(support.unlink, test_fn1)
- self.addCleanup(support.unlink, test_fn2)
+ test_fn1 = os_helper.TESTFN + "1"
+ test_fn2 = os_helper.TESTFN + "2"
+ self.addCleanup(os_helper.unlink, test_fn1)
+ self.addCleanup(os_helper.unlink, test_fn2)
create_file(test_fn1)
func(test_fn1, test_fn2)
@@ -283,7 +284,7 @@ class GenericTest:
self.assertFalse(self.pathmodule.samestat(os.stat(test_fn1),
os.stat(test_fn2)))
- @support.skip_unless_symlink
+ @os_helper.skip_unless_symlink
def test_samestat_on_symlink(self):
self._test_samestat_on_link_func(os.symlink)
@@ -294,8 +295,8 @@ class GenericTest:
self.skipTest('os.link(): %s' % e)
def test_sameopenfile(self):
- filename = support.TESTFN
- self.addCleanup(support.unlink, filename)
+ filename = os_helper.TESTFN
+ self.addCleanup(os_helper.unlink, filename)
create_file(filename)
with open(filename, "rb", 0) as fp1:
@@ -374,7 +375,7 @@ class CommonTest(GenericTest):
def test_expandvars(self):
expandvars = self.pathmodule.expandvars
- with support.EnvironmentVarGuard() as env:
+ with os_helper.EnvironmentVarGuard() as env:
env.clear()
env["foo"] = "bar"
env["{foo"] = "baz1"
@@ -403,14 +404,14 @@ class CommonTest(GenericTest):
self.assertEqual(expandvars(b"$foo$foo"), b"barbar")
self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar")
- @unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII')
+ @unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
def test_expandvars_nonascii(self):
expandvars = self.pathmodule.expandvars
def check(value, expected):
self.assertEqual(expandvars(value), expected)
- with support.EnvironmentVarGuard() as env:
+ with os_helper.EnvironmentVarGuard() as env:
env.clear()
- nonascii = support.FS_NONASCII
+ nonascii = os_helper.FS_NONASCII
env['spam'] = nonascii
env[nonascii] = 'ham' + nonascii
check(nonascii, nonascii)
@@ -469,31 +470,31 @@ class CommonTest(GenericTest):
# FS encoding is probably ASCII
pass
else:
- with support.temp_cwd(unicwd):
+ with os_helper.temp_cwd(unicwd):
for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'):
self.assertIsInstance(abspath(path), str)
def test_nonascii_abspath(self):
- if (support.TESTFN_UNDECODABLE
+ if (os_helper.TESTFN_UNDECODABLE
# Mac OS X denies the creation of a directory with an invalid
# UTF-8 name. Windows allows creating a directory with an
# arbitrary bytes name, but fails to enter this directory
# (when the bytes name is used).
and sys.platform not in ('win32', 'darwin')):
- name = support.TESTFN_UNDECODABLE
- elif support.TESTFN_NONASCII:
- name = support.TESTFN_NONASCII
+ name = 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")
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
- with support.temp_cwd(name):
+ with os_helper.temp_cwd(name):
self.test_abspath()
def test_join_errors(self):
# Check join() raises friendly TypeErrors.
- with support.check_warnings(('', BytesWarning), quiet=True):
+ with warnings_helper.check_warnings(('', BytesWarning), quiet=True):
errmsg = "Can't mix strings and bytes in path components"
with self.assertRaisesRegex(TypeError, errmsg):
self.pathmodule.join(b'bytes', 'str')
@@ -513,8 +514,8 @@ class CommonTest(GenericTest):
def test_relpath_errors(self):
# Check relpath() raises friendly TypeErrors.
- with support.check_warnings(('', (BytesWarning, DeprecationWarning)),
- quiet=True):
+ with warnings_helper.check_warnings(
+ ('', (BytesWarning, DeprecationWarning)), quiet=True):
errmsg = "Can't mix strings and bytes in path components"
with self.assertRaisesRegex(TypeError, errmsg):
self.pathmodule.relpath(b'bytes', 'str')
@@ -534,9 +535,9 @@ class CommonTest(GenericTest):
class PathLikeTests(unittest.TestCase):
def setUp(self):
- self.file_name = support.TESTFN
- self.file_path = FakePath(support.TESTFN)
- self.addCleanup(support.unlink, self.file_name)
+ self.file_name = os_helper.TESTFN
+ self.file_path = FakePath(os_helper.TESTFN)
+ self.addCleanup(os_helper.unlink, self.file_name)
create_file(self.file_name, b"test_genericpath.PathLikeTests")
def assertPathEqual(self, func):