File tree Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -498,21 +498,31 @@ def _compare_eq_cls(
498
498
499
499
500
500
def _notin_text (term : str , text : str , verbose : int = 0 ) -> List [str ]:
501
+ from wcwidth import wcwidth
502
+
501
503
index = text .find (term )
502
504
head = text [:index ]
503
505
tail = text [index + len (term ) :]
504
506
correct_text = head + tail
505
- diff = _diff_text ( correct_text , text , verbose )
507
+
506
508
newdiff = ["%s is contained here:" % saferepr (term , maxsize = 42 )]
507
- for line in diff :
508
- if line .startswith ("Skipping" ):
509
- continue
510
- if line .startswith ("- " ):
511
- continue
512
- if line .startswith ("+ " ):
513
- newdiff .append (" " + line [2 :])
514
- else :
515
- newdiff .append (line )
509
+ if any (
510
+ wcwidth (ch ) <= 0
511
+ for ch in [ch for lines in [term , correct_text ] for ch in lines ]
512
+ ):
513
+ newdiff = [
514
+ "NOTE: Strings contain non-printable characters. Escaping them using repr()."
515
+ ] + newdiff
516
+ text = repr (text )
517
+ indent = " " * (index + 1 )
518
+ marker = "+" * (len (repr (term )) - 2 )
519
+ else :
520
+ indent = " " * index
521
+ marker = "+" * len (term )
522
+ newdiff += [
523
+ " " + text ,
524
+ "? " + indent + marker ,
525
+ ]
516
526
return newdiff
517
527
518
528
Original file line number Diff line number Diff line change @@ -1200,6 +1200,16 @@ def test_reprcompare_notin() -> None:
1200
1200
]
1201
1201
1202
1202
1203
+ def test_reprcompare_notin_newline () -> None :
1204
+ assert callop ("not in" , "foo\n " , "aaafoo\n bbb" ) == [
1205
+ r"'foo\n' not in 'aaafoo\nbbb'" ,
1206
+ r"NOTE: Strings contain non-printable characters. Escaping them using repr()." ,
1207
+ r"'foo\n' is contained here:" ,
1208
+ r" 'aaafoo\nbbb'" ,
1209
+ r"? +++++" ,
1210
+ ]
1211
+
1212
+
1203
1213
def test_reprcompare_whitespaces ():
1204
1214
config = mock_config ()
1205
1215
detail = plugin .pytest_assertrepr_compare (config , "==" , "\r \n " , "\n " )
You can’t perform that action at this time.
0 commit comments