Skip to content

Commit ce1e701

Browse files
gh-154863: Check the encoded bytes in the shift state flush test
The test decoded the output back and checked the ASCII in the result, so it tested the decoder too. The ASCII is written to the output as is, so checking it there tests only the encoder. Comparing with the same text without the character also detects a character encoded as nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5918085 commit ce1e701

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Lib/test/test_codecs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,9 +3835,9 @@ def test_encode_shift_state_flush(self):
38353835
# ISO-2022-CN-EXT). That must not be read as a substituted character:
38363836
# doing so discarded the whole output, ASCII included.
38373837
#
3838-
# Only the ASCII around the character is checked, not a full round-trip.
3839-
# An iconv that cannot represent the character either rejects it or
3840-
# substitutes for it silently, as macOS does for ISO-2022-CN.
3838+
# Only the ASCII around the character is checked, in the encoded bytes:
3839+
# it is written there as is. An iconv that cannot represent the
3840+
# character rejects it or substitutes for it silently.
38413841
tested = False
38423842
for enc, text in _ICONV_SHIFT_STATE:
38433843
if not iconv_encoding_available(enc):
@@ -3848,10 +3848,10 @@ def test_encode_shift_state_flush(self):
38483848
except UnicodeEncodeError:
38493849
continue
38503850
tested = True
3851-
self.assertNotEqual(data, b'')
3852-
decoded = codecs.iconv_decode(enc, data, 'strict', True)[0]
3853-
self.assertStartsWith(decoded, 'ABC')
3854-
self.assertEndsWith(decoded, 'DEF')
3851+
self.assertIn(b'ABC', data)
3852+
self.assertIn(b'DEF', data)
3853+
# Something was written for the character itself.
3854+
self.assertNotEqual(data, codecs.iconv_encode(enc, 'ABCDEF')[0])
38553855
if not tested:
38563856
self.skipTest('no shift-state iconv encoding is available')
38573857

0 commit comments

Comments
 (0)