bpo-41069: Make TESTFN and the CWD for tests containing non-ascii characters. (GH-21035)
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 7833421..0f235d1 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -328,8 +328,15 @@
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 @@
# 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 @@
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