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