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