mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Fix GzipFile's handling of filenames given as bytes objects.
Add relevant tests for GzipFile, and also for BZ2File and LZMAFile.
This commit is contained in:
commit
10c8791978
5 changed files with 59 additions and 4 deletions
|
@ -522,6 +522,21 @@ class BZ2FileTest(BaseTest):
|
|||
with BZ2File(self.filename) as bz2f:
|
||||
self.assertEqual(bz2f.read(), data1 + data2)
|
||||
|
||||
def testOpenBytesFilename(self):
|
||||
str_filename = self.filename
|
||||
try:
|
||||
bytes_filename = str_filename.encode("ascii")
|
||||
except UnicodeEncodeError:
|
||||
self.skipTest("Temporary file name needs to be ASCII")
|
||||
with BZ2File(bytes_filename, "wb") as f:
|
||||
f.write(self.DATA)
|
||||
with BZ2File(bytes_filename, "rb") as f:
|
||||
self.assertEqual(f.read(), self.DATA)
|
||||
# Sanity check that we are actually operating on the right file.
|
||||
with BZ2File(str_filename, "rb") as f:
|
||||
self.assertEqual(f.read(), self.DATA)
|
||||
|
||||
|
||||
# Tests for a BZ2File wrapping another file object:
|
||||
|
||||
def testReadBytesIO(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue