MCPcopy Index your code
hub / github.com/python/cpython / check_state_handling_decode

Method check_state_handling_decode

Lib/test/test_codecs.py:82–102  ·  view source on GitHub ↗
(self, encoding, u, s)

Source from the content-addressed store, hash-verified

80
81class MixInCheckStateHandling:
82 def check_state_handling_decode(self, encoding, u, s):
83 for i in range(len(s)+1):
84 d = codecs.getincrementaldecoder(encoding)()
85 part1 = d.decode(s[:i])
86 state = d.getstate()
87 self.assertIsInstance(state[1], int)
88 # Check that the condition stated in the documentation for
89 # IncrementalDecoder.getstate() holds
90 if not state[1]:
91 # reset decoder to the default state without anything buffered
92 d.setstate((state[0][:0], 0))
93 # Feeding the previous input may not produce any output
94 self.assertTrue(not d.decode(state[0]))
95 # The decoder must return to the same state
96 self.assertEqual(state, d.getstate())
97 # Create a new decoder and set it to the state
98 # we extracted from the old one
99 d = codecs.getincrementaldecoder(encoding)()
100 d.setstate(state)
101 part2 = d.decode(s[i:], True)
102 self.assertEqual(u, part1+part2)
103
104 def check_state_handling_encode(self, encoding, u, s):
105 for i in range(len(u)+1):

Callers 4

test_decoder_stateMethod · 0.80
test_decoder_stateMethod · 0.80
test_decoder_stateMethod · 0.80
test_decoder_stateMethod · 0.80

Calls 6

assertIsInstanceMethod · 0.80
assertTrueMethod · 0.80
decodeMethod · 0.45
getstateMethod · 0.45
setstateMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected