(self, input, partialresults)
| 113 | |
| 114 | class 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): |
no test coverage detected