From c01fc9d30a2a23c8f9f2bcdd85e0c87acfc57e72 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 23 Aug 2022 15:28:44 -0700 Subject: [PATCH] [3.11] gh-96189: Fix test_invalid_utf8 on a number of build bots (GH-96190) (#96218) Co-authored-by: Michael Droettboom --- Lib/test/test_source_encoding.py | 76 ++++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py index e1b0de2adef..8d7b573c7e9 100644 --- a/Lib/test/test_source_encoding.py +++ b/Lib/test/test_source_encoding.py @@ -239,50 +239,50 @@ class UTF8ValidatorTest(unittest.TestCase): # it's an otherwise valid Python source file. template = b'"%s"\n' - with tempfile.TemporaryDirectory() as tmpd: - fn = os.path.join(tmpd, 'test.py') + fn = TESTFN + self.addCleanup(unlink, fn) - def check(content): - with open(fn, 'wb') as fp: - fp.write(template % content) - script_helper.assert_python_failure(fn) + def check(content): + with open(fn, 'wb') as fp: + fp.write(template % content) + script_helper.assert_python_failure(fn) - # continuation bytes in a sequence of 2, 3, or 4 bytes - continuation_bytes = [bytes([x]) for x in range(0x80, 0xC0)] - # start bytes of a 2-byte sequence equivalent to code points < 0x7F - invalid_2B_seq_start_bytes = [bytes([x]) for x in range(0xC0, 0xC2)] - # start bytes of a 4-byte sequence equivalent to code points > 0x10FFFF - invalid_4B_seq_start_bytes = [bytes([x]) for x in range(0xF5, 0xF8)] - invalid_start_bytes = ( - continuation_bytes + invalid_2B_seq_start_bytes + - invalid_4B_seq_start_bytes + [bytes([x]) for x in range(0xF7, 0x100)] - ) + # continuation bytes in a sequence of 2, 3, or 4 bytes + continuation_bytes = [bytes([x]) for x in range(0x80, 0xC0)] + # start bytes of a 2-byte sequence equivalent to code points < 0x7F + invalid_2B_seq_start_bytes = [bytes([x]) for x in range(0xC0, 0xC2)] + # start bytes of a 4-byte sequence equivalent to code points > 0x10FFFF + invalid_4B_seq_start_bytes = [bytes([x]) for x in range(0xF5, 0xF8)] + invalid_start_bytes = ( + continuation_bytes + invalid_2B_seq_start_bytes + + invalid_4B_seq_start_bytes + [bytes([x]) for x in range(0xF7, 0x100)] + ) - for byte in invalid_start_bytes: - check(byte) + for byte in invalid_start_bytes: + check(byte) - for sb in invalid_2B_seq_start_bytes: - for cb in continuation_bytes: - check(sb + cb) + for sb in invalid_2B_seq_start_bytes: + for cb in continuation_bytes: + check(sb + cb) - for sb in invalid_4B_seq_start_bytes: - for cb1 in continuation_bytes[:3]: - for cb3 in continuation_bytes[:3]: - check(sb+cb1+b'\x80'+cb3) + for sb in invalid_4B_seq_start_bytes: + for cb1 in continuation_bytes[:3]: + for cb3 in continuation_bytes[:3]: + check(sb+cb1+b'\x80'+cb3) - for cb in [bytes([x]) for x in range(0x80, 0xA0)]: - check(b'\xE0'+cb+b'\x80') - check(b'\xE0'+cb+b'\xBF') - # surrogates - for cb in [bytes([x]) for x in range(0xA0, 0xC0)]: - check(b'\xED'+cb+b'\x80') - check(b'\xED'+cb+b'\xBF') - for cb in [bytes([x]) for x in range(0x80, 0x90)]: - check(b'\xF0'+cb+b'\x80\x80') - check(b'\xF0'+cb+b'\xBF\xBF') - for cb in [bytes([x]) for x in range(0x90, 0xC0)]: - check(b'\xF4'+cb+b'\x80\x80') - check(b'\xF4'+cb+b'\xBF\xBF') + for cb in [bytes([x]) for x in range(0x80, 0xA0)]: + check(b'\xE0'+cb+b'\x80') + check(b'\xE0'+cb+b'\xBF') + # surrogates + for cb in [bytes([x]) for x in range(0xA0, 0xC0)]: + check(b'\xED'+cb+b'\x80') + check(b'\xED'+cb+b'\xBF') + for cb in [bytes([x]) for x in range(0x80, 0x90)]: + check(b'\xF0'+cb+b'\x80\x80') + check(b'\xF0'+cb+b'\xBF\xBF') + for cb in [bytes([x]) for x in range(0x90, 0xC0)]: + check(b'\xF4'+cb+b'\x80\x80') + check(b'\xF4'+cb+b'\xBF\xBF') class BytesSourceEncodingTest(AbstractSourceEncodingTest, unittest.TestCase):