mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Make use of TESTFN_ASCII in test_fileio (GH-101645)
testBytesOpen requires an ASCII filename, but TESTFN usually isn't ASCII. Automerge-Triggered-By: GH:zware
This commit is contained in:
parent
d54b8d8fbd
commit
6fd5eb640a
1 changed files with 6 additions and 7 deletions
|
@ -12,7 +12,9 @@ from functools import wraps
|
||||||
from test.support import (
|
from test.support import (
|
||||||
cpython_only, swap_attr, gc_collect, is_emscripten, is_wasi
|
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 test.support.warnings_helper import check_warnings
|
||||||
from collections import UserList
|
from collections import UserList
|
||||||
|
|
||||||
|
@ -431,18 +433,15 @@ class OtherFileTests:
|
||||||
|
|
||||||
def testBytesOpen(self):
|
def testBytesOpen(self):
|
||||||
# Opening a bytes filename
|
# Opening a bytes filename
|
||||||
try:
|
fn = TESTFN_ASCII.encode("ascii")
|
||||||
fn = TESTFN.encode("ascii")
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
self.skipTest('could not encode %r to ascii' % TESTFN)
|
|
||||||
f = self.FileIO(fn, "w")
|
f = self.FileIO(fn, "w")
|
||||||
try:
|
try:
|
||||||
f.write(b"abc")
|
f.write(b"abc")
|
||||||
f.close()
|
f.close()
|
||||||
with open(TESTFN, "rb") as f:
|
with open(TESTFN_ASCII, "rb") as f:
|
||||||
self.assertEqual(f.read(), b"abc")
|
self.assertEqual(f.read(), b"abc")
|
||||||
finally:
|
finally:
|
||||||
os.unlink(TESTFN)
|
os.unlink(TESTFN_ASCII)
|
||||||
|
|
||||||
@unittest.skipIf(sys.getfilesystemencoding() != 'utf-8',
|
@unittest.skipIf(sys.getfilesystemencoding() != 'utf-8',
|
||||||
"test only works for utf-8 filesystems")
|
"test only works for utf-8 filesystems")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue