]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] Make use of TESTFN_ASCII in test_fileio (GH-101645) (#101650)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 8 Feb 2023 10:05:36 +0000 (02:05 -0800)
committerGitHub <noreply@github.com>
Wed, 8 Feb 2023 10:05:36 +0000 (11:05 +0100)
testBytesOpen requires an ASCII filename, but TESTFN usually isn't ASCII.
(cherry picked from commit 6fd5eb640af19b535f4f2ba27b1b61b8d17f02e9)

Co-authored-by: Zachary Ware <zach@python.org>
Lib/test/test_fileio.py

index c26cdc028cc890b35ea4b8e2c090ef58820f2462..5cc3d4bf9f5db0cd02cc2d758461524ea4b3a0a5 100644 (file)
@@ -12,7 +12,9 @@ from functools import wraps
 from test.support import (
     cpython_only, swap_attr, gc_collect, is_emscripten, is_wasi
 )
-from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd)
+from test.support.os_helper import (
+    TESTFN, TESTFN_ASCII, TESTFN_UNICODE, make_bad_fd,
+    )
 from test.support.warnings_helper import check_warnings
 from collections import UserList
 
@@ -431,18 +433,15 @@ class OtherFileTests:
 
     def testBytesOpen(self):
         # Opening a bytes filename
-        try:
-            fn = TESTFN.encode("ascii")
-        except UnicodeEncodeError:
-            self.skipTest('could not encode %r to ascii' % TESTFN)
+        fn = TESTFN_ASCII.encode("ascii")
         f = self.FileIO(fn, "w")
         try:
             f.write(b"abc")
             f.close()
-            with open(TESTFN, "rb") as f:
+            with open(TESTFN_ASCII, "rb") as f:
                 self.assertEqual(f.read(), b"abc")
         finally:
-            os.unlink(TESTFN)
+            os.unlink(TESTFN_ASCII)
 
     @unittest.skipIf(sys.getfilesystemencoding() != 'utf-8',
                      "test only works for utf-8 filesystems")