Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 1 | # |
| 2 | # This file is for everybody to add tests for bugs that aren't |
| 3 | # fixed yet. Please add a test case and appropriate bug description. |
| 4 | # |
| 5 | # When you fix one of the bugs, please move the test to the correct |
| 6 | # test_ module. |
| 7 | # |
| 8 | |
| 9 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 10 | from test import support |
Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 11 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 12 | # |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 13 | # One test case for outstanding bugs at the moment: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 14 | # |
Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 15 | |
Christian Heimes | 563e33b | 2007-11-08 13:12:43 +0000 | [diff] [blame] | 16 | # test_io |
| 17 | import io |
| 18 | class TextIOWrapperTest(unittest.TestCase): |
| 19 | |
| 20 | def setUp(self): |
| 21 | self.testdata = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n" |
| 22 | self.normalized = b"AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ASCII") |
| 23 | |
| 24 | def tearDown(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 25 | support.unlink(support.TESTFN) |
Christian Heimes | 563e33b | 2007-11-08 13:12:43 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | def test_issue1395_1(self): |
| 29 | txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII") |
| 30 | |
| 31 | # read one char at a time |
| 32 | reads = "" |
| 33 | while True: |
| 34 | c = txt.read(1) |
| 35 | if not c: |
| 36 | break |
| 37 | reads += c |
| 38 | self.assertEquals(reads, self.normalized) |
| 39 | |
| 40 | def test_issue1395_2(self): |
| 41 | txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII") |
| 42 | txt._CHUNK_SIZE = 4 |
| 43 | |
| 44 | reads = "" |
| 45 | while True: |
| 46 | c = txt.read(4) |
| 47 | if not c: |
| 48 | break |
| 49 | reads += c |
| 50 | self.assertEquals(reads, self.normalized) |
| 51 | |
| 52 | def test_issue1395_3(self): |
| 53 | txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII") |
| 54 | txt._CHUNK_SIZE = 4 |
| 55 | |
| 56 | reads = txt.read(4) |
| 57 | reads += txt.read(4) |
| 58 | reads += txt.readline() |
| 59 | reads += txt.readline() |
| 60 | reads += txt.readline() |
| 61 | self.assertEquals(reads, self.normalized) |
| 62 | |
| 63 | def test_issue1395_4(self): |
| 64 | txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII") |
| 65 | txt._CHUNK_SIZE = 4 |
| 66 | |
| 67 | reads = txt.read(4) |
| 68 | reads += txt.read() |
| 69 | self.assertEquals(reads, self.normalized) |
| 70 | |
| 71 | def test_issue1395_5(self): |
| 72 | txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII") |
| 73 | txt._CHUNK_SIZE = 4 |
| 74 | |
| 75 | reads = txt.read(4) |
| 76 | pos = txt.tell() |
| 77 | txt.seek(0) |
| 78 | txt.seek(pos) |
| 79 | self.assertEquals(txt.read(4), "BBB\n") |
| 80 | |
| 81 | |
Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 82 | |
| 83 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 84 | support.run_unittest( |
Christian Heimes | 563e33b | 2007-11-08 13:12:43 +0000 | [diff] [blame] | 85 | TextIOWrapperTest) |
Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 86 | |
| 87 | if __name__ == "__main__": |
| 88 | test_main() |