summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_difflib.py
diff options
context:
space:
mode:
authorTerry Reedy <tjreedy@udel.edu>2010-12-15 20:18:10 (GMT)
committerTerry Reedy <tjreedy@udel.edu>2010-12-15 20:18:10 (GMT)
commit17a59252e8505439decbdf80c73d2465288f65c7 (patch)
treea013b989af70181e83f9dde3f40bc09293ea3b76 /Lib/test/test_difflib.py
parent50ba19ee454e47b44cb0a9f00746d8ecdf0aa1b2 (diff)
downloadcpython-17a59252e8505439decbdf80c73d2465288f65c7.zip
cpython-17a59252e8505439decbdf80c73d2465288f65c7.tar.gz
cpython-17a59252e8505439decbdf80c73d2465288f65c7.tar.bz2
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Diffstat (limited to 'Lib/test/test_difflib.py')
-rw-r--r--Lib/test/test_difflib.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
index e72df26..a263ee6 100644
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -12,12 +12,14 @@ class TestWithAscii(unittest.TestCase):
self.assertEqual(list(sm.get_opcodes()),
[ ('insert', 0, 0, 0, 1),
('equal', 0, 100, 1, 101)])
+ self.assertEqual(sm.bpopular, set())
sm = difflib.SequenceMatcher(None, 'b' * 100, 'b' * 50 + 'a' + 'b' * 50)
self.assertAlmostEqual(sm.ratio(), 0.995, places=3)
self.assertEqual(list(sm.get_opcodes()),
[ ('equal', 0, 50, 0, 50),
('insert', 50, 50, 50, 51),
('equal', 50, 100, 51, 101)])
+ self.assertEqual(sm.bpopular, set())
def test_one_delete(self):
sm = difflib.SequenceMatcher(None, 'a' * 40 + 'c' + 'b' * 40, 'a' * 40 + 'b' * 40)
@@ -27,6 +29,19 @@ class TestWithAscii(unittest.TestCase):
('delete', 40, 41, 40, 40),
('equal', 41, 81, 40, 80)])
+ def test_bjunk(self):
+ sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ',
+ a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40)
+ self.assertEqual(sm.bjunk, set())
+
+ sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ',
+ a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40 + ' ' * 20)
+ self.assertEqual(sm.bjunk, {' '})
+
+ sm = difflib.SequenceMatcher(isjunk=lambda x: x in [' ', 'b'],
+ a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40 + ' ' * 20)
+ self.assertEqual(sm.bjunk, {' ', 'b'})
+
class TestAutojunk(unittest.TestCase):
"""Tests for the autojunk parameter added in 2.7"""
@@ -38,10 +53,12 @@ class TestAutojunk(unittest.TestCase):
sm = difflib.SequenceMatcher(None, seq1, seq2)
self.assertAlmostEqual(sm.ratio(), 0, places=3)
+ self.assertEqual(sm.bpopular, {'b'})
# Now turn the heuristic off
sm = difflib.SequenceMatcher(None, seq1, seq2, autojunk=False)
self.assertAlmostEqual(sm.ratio(), 0.9975, places=3)
+ self.assertEqual(sm.bpopular, set())
class TestSFbugs(unittest.TestCase):