[3.9] bpo-41069: Make TESTFN and the CWD for tests containing non-ascii characters. (GH-21035). (GH-21156)

(cherry picked from commit 700cfa8c90)
This commit is contained in:
Serhiy Storchaka 2020-06-25 20:39:12 +03:00 committed by GitHub
parent ad7a66731f
commit f925407a19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 108 additions and 76 deletions

View file

@ -328,8 +328,15 @@ class TestGzip(BaseTest):
cmByte = fRead.read(1)
self.assertEqual(cmByte, b'\x08') # deflate
try:
expectedname = self.filename.encode('Latin-1') + b'\x00'
expectedflags = b'\x08' # only the FNAME flag is set
except UnicodeEncodeError:
expectedname = b''
expectedflags = b'\x00'
flagsByte = fRead.read(1)
self.assertEqual(flagsByte, b'\x08') # only the FNAME flag is set
self.assertEqual(flagsByte, expectedflags)
mtimeBytes = fRead.read(4)
self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
@ -344,9 +351,8 @@ class TestGzip(BaseTest):
# RFC 1952 specifies that this is the name of the input file, if any.
# However, the gzip module defaults to storing the name of the output
# file in this field.
expected = self.filename.encode('Latin-1') + b'\x00'
nameBytes = fRead.read(len(expected))
self.assertEqual(nameBytes, expected)
nameBytes = fRead.read(len(expectedname))
self.assertEqual(nameBytes, expectedname)
# Since no other flags were set, the header ends here.
# Rather than process the compressed data, let's seek to the trailer.
@ -358,6 +364,10 @@ class TestGzip(BaseTest):
isizeBytes = fRead.read(4)
self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
def test_metadata_ascii_name(self):
self.filename = support.TESTFN_ASCII
self.test_metadata()
def test_compresslevel_metadata(self):
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
# specifically, discussion of XFL in section 2.3.1