@@ -295,7 +295,7 @@ def test_close_matches_aligned(self):
295
295
296
296
class TestOutputFormat (unittest .TestCase ):
297
297
def test_tab_delimiter (self ):
298
- args = ['one' , 'two' , 'Original' , 'Current' ,
298
+ args = [[ 'one' ], [ 'two' ] , 'Original' , 'Current' ,
299
299
'2005-01-26 23:30:50' , '2010-04-02 10:20:52' ]
300
300
ud = difflib .unified_diff (* args , lineterm = '' )
301
301
self .assertEqual (list (ud )[0 :2 ], [
@@ -307,7 +307,7 @@ def test_tab_delimiter(self):
307
307
"--- Current\t 2010-04-02 10:20:52" ])
308
308
309
309
def test_no_trailing_tab_on_empty_filedate (self ):
310
- args = ['one' , 'two' , 'Original' , 'Current' ]
310
+ args = [[ 'one' ], [ 'two' ] , 'Original' , 'Current' ]
311
311
ud = difflib .unified_diff (* args , lineterm = '' )
312
312
self .assertEqual (list (ud )[0 :2 ], ["--- Original" , "+++ Current" ])
313
313
@@ -447,6 +447,28 @@ def assertDiff(expect, actual):
447
447
lineterm = b'' )
448
448
assertDiff (expect , actual )
449
449
450
+
451
+ class TestInputTypes (unittest .TestCase ):
452
+ def _assert_type_error (self , msg , generator , * args ):
453
+ with self .assertRaises (TypeError ) as ctx :
454
+ list (generator (* args ))
455
+ self .assertEqual (msg , str (ctx .exception ))
456
+
457
+ def test_input_type_checks (self ):
458
+ unified = difflib .unified_diff
459
+ context = difflib .context_diff
460
+
461
+ expect = "input must be a sequence of strings, not str"
462
+ self ._assert_type_error (expect , unified , 'a' , ['b' ])
463
+ self ._assert_type_error (expect , context , 'a' , ['b' ])
464
+
465
+ self ._assert_type_error (expect , unified , ['a' ], 'b' )
466
+ self ._assert_type_error (expect , context , ['a' ], 'b' )
467
+
468
+ expect = "lines to compare must be str, not NoneType (None)"
469
+ self ._assert_type_error (expect , unified , ['a' ], [None ])
470
+ self ._assert_type_error (expect , context , ['a' ], [None ])
471
+
450
472
def test_mixed_types_content (self ):
451
473
# type of input content must be consistent: all str or all bytes
452
474
a = [b'hello' ]
@@ -495,10 +517,6 @@ def test_mixed_types_dates(self):
495
517
b = ['bar\n ' ]
496
518
list (difflib .unified_diff (a , b , 'a' , 'b' , datea , dateb ))
497
519
498
- def _assert_type_error (self , msg , generator , * args ):
499
- with self .assertRaises (TypeError ) as ctx :
500
- list (generator (* args ))
501
- self .assertEqual (msg , str (ctx .exception ))
502
520
503
521
class TestJunkAPIs (unittest .TestCase ):
504
522
def test_is_line_junk_true (self ):
0 commit comments