@@ -29,6 +29,16 @@ def test_one_delete(self):
29
29
('delete' , 40 , 41 , 40 , 40 ),
30
30
('equal' , 41 , 81 , 40 , 80 )])
31
31
32
+ def test_opcode_caching (self ):
33
+ sm = difflib .SequenceMatcher (None , 'b' * 100 , 'a' + 'b' * 100 )
34
+ opcode = sm .get_opcodes ()
35
+ self .assertEqual (opcode ,
36
+ [ ('insert' , 0 , 0 , 0 , 1 ),
37
+ ('equal' , 0 , 100 , 1 , 101 )])
38
+ # Implementation detail: opcodes are cached;
39
+ # `get_opcodes()` returns the same object
40
+ self .assertIs (opcode , sm .get_opcodes ())
41
+
32
42
def test_bjunk (self ):
33
43
sm = difflib .SequenceMatcher (isjunk = lambda x : x == ' ' ,
34
44
a = 'a' * 40 + 'b' * 40 , b = 'a' * 44 + 'b' * 40 )
@@ -273,6 +283,15 @@ def test_make_file_usascii_charset_with_nonascii_input(self):
273
283
self .assertIn ('ımplıcıt' , output )
274
284
275
285
286
+ def test_one_insert (self ):
287
+ m = difflib .Differ ().compare ('b' * 2 , 'a' + 'b' * 2 )
288
+ self .assertEqual (list (m ), ['+ a' , ' b' , ' b' ])
289
+
290
+ def test_one_delete (self ):
291
+ m = difflib .Differ ().compare ('a' + 'b' * 2 , 'b' * 2 )
292
+ self .assertEqual (list (m ), ['- a' , ' b' , ' b' ])
293
+
294
+
276
295
class TestOutputFormat (unittest .TestCase ):
277
296
def test_tab_delimiter (self ):
278
297
args = ['one' , 'two' , 'Original' , 'Current' ,
@@ -547,6 +566,26 @@ def test_longest_match_with_popular_chars(self):
547
566
self .assertFalse (self .longer_match_exists (a , b , match .size ))
548
567
549
568
569
+ class TestCloseMatches (unittest .TestCase ):
570
+ # Happy paths are tested in the doctests of `difflib.get_close_matches`.
571
+
572
+ def test_invalid_inputs (self ):
573
+ self .assertRaises (ValueError , difflib .get_close_matches , "spam" , ['egg' ], n = 0 )
574
+ self .assertRaises (ValueError , difflib .get_close_matches , "spam" , ['egg' ], n = - 1 )
575
+ self .assertRaises (ValueError , difflib .get_close_matches , "spam" , ['egg' ], cutoff = 1.1 )
576
+ self .assertRaises (ValueError , difflib .get_close_matches , "spam" , ['egg' ], cutoff = - 0.1 )
577
+
578
+
579
+ class TestRestore (unittest .TestCase ):
580
+ # Happy paths are tested in the doctests of `difflib.restore`.
581
+
582
+ def test_invalid_input (self ):
583
+ with self .assertRaises (ValueError ):
584
+ '' .join (difflib .restore ([], 0 ))
585
+ with self .assertRaises (ValueError ):
586
+ '' .join (difflib .restore ([], 3 ))
587
+
588
+
550
589
def setUpModule ():
551
590
difflib .HtmlDiff ._default_prefix = 0
552
591
0 commit comments