diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/support.py | 2 | ||||
-rw-r--r-- | Lib/test/test_bisect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_genericpath.py | 12 | ||||
-rw-r--r-- | Lib/test/test_os.py | 83 |
4 files changed, 56 insertions, 43 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 1717c06..93b94d9 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -654,7 +654,7 @@ TESTFN_UNDECODABLE = None for name in (b'abc\xff', b'\xe7w\xf0'): try: os.fsdecode(name) - except UnicodeDecodeErorr: + except UnicodeDecodeError: TESTFN_UNDECODABLE = name break diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py index 2ac3a68..f95ed63 100644 --- a/Lib/test/test_bisect.py +++ b/Lib/test/test_bisect.py @@ -239,7 +239,7 @@ class TestInsort(unittest.TestCase): else: f = self.module.insort_right f(insorted, digit) - self.assertEqual(sorted(insorted), insorted) + self.assertEqual(sorted(insorted), insorted) def test_backcompatibility(self): self.assertEqual(self.module.insort, self.module.insort_right) diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index 3eadd58..600ffc0 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -311,14 +311,10 @@ class CommonTest(GenericTest): @unittest.skipIf(sys.platform == 'darwin', "Mac OS X denies the creation of a directory with an invalid utf8 name") def test_nonascii_abspath(self): - name = b'\xe7w\xf0' - if sys.platform == 'win32': - try: - os.fsdecode(name) - except UnicodeDecodeError: - self.skipTest("the filename %a is not decodable " - "from the ANSI code page %s" - % (name, sys.getfilesystemencoding())) + if support.TESTFN_UNDECODABLE: + name = support.TESTFN_UNDECODABLE + else: + name = b'a\xffb\xe7w\xf0' # Test non-ASCII, non-UTF8 bytes in the path. with warnings.catch_warnings(): diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index a4cf60f..9cf4070 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -2051,65 +2051,82 @@ class OSErrorTests(unittest.TestCase): class Str(str): pass - self.filenames = [] + self.bytes_filenames = [] + self.unicode_filenames = [] if support.TESTFN_UNENCODABLE is not None: decoded = support.TESTFN_UNENCODABLE else: decoded = support.TESTFN - self.filenames.append(decoded) - self.filenames.append(Str(decoded)) + self.unicode_filenames.append(decoded) + self.unicode_filenames.append(Str(decoded)) if support.TESTFN_UNDECODABLE is not None: encoded = support.TESTFN_UNDECODABLE else: encoded = os.fsencode(support.TESTFN) - self.filenames.append(encoded) - self.filenames.append(memoryview(encoded)) + self.bytes_filenames.append(encoded) + self.bytes_filenames.append(memoryview(encoded)) + + self.filenames = self.bytes_filenames + self.unicode_filenames def test_oserror_filename(self): funcs = [ - (os.chdir,), - (os.chmod, 0o777), - (os.lchown, 0, 0), - (os.listdir,), - (os.lstat,), - (os.open, os.O_RDONLY), - (os.rename, "dst"), - (os.replace, "dst"), - (os.rmdir,), - (os.stat,), - (os.truncate, 0), - (os.unlink,), + (self.filenames, os.chdir,), + (self.filenames, os.chmod, 0o777), + (self.filenames, os.listdir,), + (self.filenames, os.lstat,), + (self.filenames, os.open, os.O_RDONLY), + (self.filenames, os.rmdir,), + (self.filenames, os.stat,), + (self.filenames, os.unlink,), ] - if hasattr(os, "chown"): - funcs.append((os.chown, 0, 0)) if sys.platform == "win32": funcs.extend(( - (os._getfullpathname,), - (os._isdir,), + (self.bytes_filenames, os.rename, b"dst"), + (self.bytes_filenames, os.replace, b"dst"), + (self.unicode_filenames, os.rename, "dst"), + (self.unicode_filenames, os.replace, "dst"), + )) + else: + funcs.extend(( + (self.filenames, os.rename, "dst"), + (self.filenames, os.replace, "dst"), )) + if hasattr(os, "chown"): + funcs.append((self.filenames, os.chown, 0, 0)) + if hasattr(os, "lchown"): + funcs.append((self.filenames, os.lchown, 0, 0)) + if hasattr(os, "truncate"): + funcs.append((self.filenames, os.truncate, 0)) if hasattr(os, "chflags"): funcs.extend(( - (os.chflags, 0), - (os.lchflags, 0), + (self.filenames, os.chflags, 0), + (self.filenames, os.lchflags, 0), )) if hasattr(os, "chroot"): - funcs.append((os.chroot,)) + funcs.append((self.filenames, os.chroot,)) if hasattr(os, "link"): - funcs.append((os.link, "dst")) + if sys.platform == "win32": + funcs.append((self.bytes_filenames, os.link, b"dst")) + funcs.append((self.unicode_filenames, os.link, "dst")) + else: + funcs.append((self.filenames, os.link, "dst")) if hasattr(os, "listxattr"): funcs.extend(( - (os.listxattr,), - (os.getxattr, "user.test"), - (os.setxattr, "user.test", b'user'), - (os.removexattr, "user.test"), + (self.filenames, os.listxattr,), + (self.filenames, os.getxattr, "user.test"), + (self.filenames, os.setxattr, "user.test", b'user'), + (self.filenames, os.removexattr, "user.test"), )) if hasattr(os, "lchmod"): - funcs.append((os.lchmod, 0o777)) + funcs.append((self.filenames, os.lchmod, 0o777)) if hasattr(os, "readlink"): - funcs.append((os.readlink,)) + if sys.platform == "win32": + funcs.append((self.unicode_filenames, os.readlink,)) + else: + funcs.append((self.filenames, os.readlink,)) - for func, *func_args in funcs: - for name in self.filenames: + for filenames, func, *func_args in funcs: + for name in filenames: try: func(name, *func_args) except OSError as err: |