MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_partial

Method check_partial

Lib/test/test_codecs.py:115–156  ·  view source on GitHub ↗
(self, input, partialresults)

Source from the content-addressed store, hash-verified

113
114class ReadTest(MixInCheckStateHandling):
115 def check_partial(self, input, partialresults):
116 # get a StreamReader for the encoding and feed the bytestring version
117 # of input to the reader byte by byte. Read everything available from
118 # the StreamReader and check that the results equal the appropriate
119 # entries from partialresults.
120 q = Queue(b"")
121 r = codecs.getreader(self.encoding)(q)
122 result = ""
123 for (c, partialresult) in zip(input.encode(self.encoding), partialresults, strict=True):
124 q.write(bytes([c]))
125 result += r.read()
126 self.assertEqual(result, partialresult)
127 # check that there's nothing left in the buffers
128 self.assertEqual(r.read(), "")
129 self.assertEqual(r.bytebuffer, b"")
130
131 # do the check again, this time using an incremental decoder
132 d = codecs.getincrementaldecoder(self.encoding)()
133 result = ""
134 for (c, partialresult) in zip(input.encode(self.encoding), partialresults, strict=True):
135 result += d.decode(bytes([c]))
136 self.assertEqual(result, partialresult)
137 # check that there's nothing left in the buffers
138 self.assertEqual(d.decode(b"", True), "")
139 self.assertEqual(d.buffer, b"")
140
141 # Check whether the reset method works properly
142 d.reset()
143 result = ""
144 for (c, partialresult) in zip(input.encode(self.encoding), partialresults, strict=True):
145 result += d.decode(bytes([c]))
146 self.assertEqual(result, partialresult)
147 # check that there's nothing left in the buffers
148 self.assertEqual(d.decode(b"", True), "")
149 self.assertEqual(d.buffer, b"")
150
151 # check iterdecode()
152 encoded = input.encode(self.encoding)
153 self.assertEqual(
154 input,
155 "".join(codecs.iterdecode([bytes([c]) for c in encoded], self.encoding))
156 )
157
158 def test_readline(self):
159 def getreader(input):

Callers 11

test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80
test_partialMethod · 0.80

Calls 9

writeMethod · 0.95
getreaderMethod · 0.80
QueueClass · 0.70
encodeMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45
decodeMethod · 0.45
resetMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected