blob: 9e4784ce16eecf1085988a5c598beeacead85b27 [file] [log] [blame]
Tim Peters1a572962006-03-01 06:19:04 +00001#
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
9import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +000010from test import support
Tim Peters1a572962006-03-01 06:19:04 +000011
Thomas Wouters89f507f2006-12-13 04:49:30 +000012#
Guido van Rossumd8faa362007-04-27 19:54:29 +000013# One test case for outstanding bugs at the moment:
Thomas Wouters89f507f2006-12-13 04:49:30 +000014#
Tim Peters1a572962006-03-01 06:19:04 +000015
Christian Heimes563e33b2007-11-08 13:12:43 +000016# test_io
17import io
18class 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 Petersonee8712c2008-05-20 21:35:26 +000025 support.unlink(support.TESTFN)
Christian Heimes563e33b2007-11-08 13:12:43 +000026
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 Peters1a572962006-03-01 06:19:04 +000082
83def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000084 support.run_unittest(
Christian Heimes563e33b2007-11-08 13:12:43 +000085 TextIOWrapperTest)
Tim Peters1a572962006-03-01 06:19:04 +000086
87if __name__ == "__main__":
88 test_main()