blob: 9c75bfca9cff9e11e6c231fe09725ebde7edff4f [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
10from test import test_support
11
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
Guido van Rossumd8faa362007-04-27 19:54:29 +000016class TestDifflibLongestMatch(unittest.TestCase):
17 # From Patch #1678339:
18 # The find_longest_match method in the difflib's SequenceMatcher has a bug.
19
20 # The bug is in turn caused by a problem with creating a b2j mapping which
21 # should contain a list of indices for each of the list elements in b.
22 # However, when the b2j mapping is being created (this is being done in
23 # __chain_b method in the SequenceMatcher) the mapping becomes broken. The
24 # cause of this is that for the frequently used elements the list of indices
25 # is removed and the element is being enlisted in the populardict mapping.
26
27 # The test case tries to match two strings like:
28 # abbbbbb.... and ...bbbbbbc
29
30 # The number of b is equal and the find_longest_match should have returned
31 # the proper amount. However, in case the number of "b"s is large enough, the
32 # method reports that the length of the longest common substring is 0. It
33 # simply can't find it.
34
35 # A bug was raised some time ago on this matter. It's ID is 1528074.
36
37 def test_find_longest_match(self):
38 import difflib
39 for i in (190, 200, 210):
40 text1 = "a" + "b"*i
41 text2 = "b"*i + "c"
42 m = difflib.SequenceMatcher(None, text1, text2)
43 (aptr, bptr, l) = m.find_longest_match(0, len(text1), 0, len(text2))
44 self.assertEquals(i, l)
45 self.assertEquals(aptr, 1)
46 self.assertEquals(bptr, 0)
47
Christian Heimes563e33b2007-11-08 13:12:43 +000048# test_io
49import io
50class TextIOWrapperTest(unittest.TestCase):
51
52 def setUp(self):
53 self.testdata = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
54 self.normalized = b"AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ASCII")
55
56 def tearDown(self):
57 test_support.unlink(test_support.TESTFN)
58
59
60 def test_issue1395_1(self):
61 txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
62
63 # read one char at a time
64 reads = ""
65 while True:
66 c = txt.read(1)
67 if not c:
68 break
69 reads += c
70 self.assertEquals(reads, self.normalized)
71
72 def test_issue1395_2(self):
73 txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
74 txt._CHUNK_SIZE = 4
75
76 reads = ""
77 while True:
78 c = txt.read(4)
79 if not c:
80 break
81 reads += c
82 self.assertEquals(reads, self.normalized)
83
84 def test_issue1395_3(self):
85 txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
86 txt._CHUNK_SIZE = 4
87
88 reads = txt.read(4)
89 reads += txt.read(4)
90 reads += txt.readline()
91 reads += txt.readline()
92 reads += txt.readline()
93 self.assertEquals(reads, self.normalized)
94
95 def test_issue1395_4(self):
96 txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
97 txt._CHUNK_SIZE = 4
98
99 reads = txt.read(4)
100 reads += txt.read()
101 self.assertEquals(reads, self.normalized)
102
103 def test_issue1395_5(self):
104 txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
105 txt._CHUNK_SIZE = 4
106
107 reads = txt.read(4)
108 pos = txt.tell()
109 txt.seek(0)
110 txt.seek(pos)
111 self.assertEquals(txt.read(4), "BBB\n")
112
113
Tim Peters1a572962006-03-01 06:19:04 +0000114
115def test_main():
Christian Heimes563e33b2007-11-08 13:12:43 +0000116 test_support.run_unittest(
117 TestDifflibLongestMatch,
118 TextIOWrapperTest)
Tim Peters1a572962006-03-01 06:19:04 +0000119
120if __name__ == "__main__":
121 test_main()