| 1142 | self.assertEqual(got, unistring) |
| 1143 | |
| 1144 | def test_stream_bare(self): |
| 1145 | unistring = "ABC\u00A1\u2200XYZ" |
| 1146 | bytestring = b"ABC\xC2\xA1\xE2\x88\x80XYZ" |
| 1147 | |
| 1148 | reader = codecs.getreader("utf-8-sig") |
| 1149 | for sizehint in [None] + list(range(1, 11)) + \ |
| 1150 | [64, 128, 256, 512, 1024]: |
| 1151 | istream = reader(io.BytesIO(bytestring)) |
| 1152 | ostream = io.StringIO() |
| 1153 | while 1: |
| 1154 | if sizehint is not None: |
| 1155 | data = istream.read(sizehint) |
| 1156 | else: |
| 1157 | data = istream.read() |
| 1158 | |
| 1159 | if not data: |
| 1160 | break |
| 1161 | ostream.write(data) |
| 1162 | |
| 1163 | got = ostream.getvalue() |
| 1164 | self.assertEqual(got, unistring) |
| 1165 | |
| 1166 | |
| 1167 | class EscapeDecodeTest(unittest.TestCase): |