@@ -18,7 +18,7 @@ def test_has_todo(tmpdir):
18
18
# noinspection SpellCheckingInspection
19
19
f .write_text ('TODO: ¥eßűs, ∂éñ∂ þħïs!' , encoding = 'utf-8' )
20
20
assert no_todos .main ((str (f ),)) == 1
21
- assert mocked_print .call_args_list [0 ].args [0 ] \
21
+ assert mocked_print .call_args_list [- 1 ].args [0 ] \
22
22
.endswith ('todo.txt: contains TODO' )
23
23
24
24
@@ -42,7 +42,7 @@ def test_has_todo_but_excepted(tmpdir):
42
42
# noinspection SpellCheckingInspection
43
43
f .write_text ('TODO: ฿űþ ñ∅™ þħïs!' , encoding = 'utf-8' )
44
44
assert no_todos .main (('-e' , 'todo.txt' , str (f ))) == 0
45
- assert mocked_print .call_args_list [0 ].args [0 ] \
45
+ assert mocked_print .call_args_list [- 1 ].args [0 ] \
46
46
.endswith ('todo.txt: contains TODO, but is on the exception list' )
47
47
48
48
@@ -64,3 +64,27 @@ def test_complex_case(tmpdir):
64
64
# noinspection SpellCheckingInspection
65
65
f3 .write_text ('TODO: ¥eßűs, ∂éñ∂ þħïs!-3' , encoding = 'utf-8' )
66
66
assert no_todos .main (('-e' , 'todo_2.txt' , str (f1 ), str (f2 ), str (f3 ))) == 2
67
+
68
+
69
+ def test_non_utf_8 (tmpdir ):
70
+ with patch ('builtins.print' ) as mocked_print :
71
+ f1 = tmpdir .join ('todo_utf8_bom.txt' )
72
+ # noinspection SpellCheckingInspection
73
+ f1 .write_text ('TODO: ¥eßűs, ∂éñ∂ þħïs!-1' , encoding = 'utf-8-sig' )
74
+ assert no_todos .main ((str (f1 ),)) == 1
75
+ for a in mocked_print .call_args_list :
76
+ assert not a .args [0 ].endswith (
77
+ 'todo_utf8_bom.txt: cannot be read as UTF-8, trying UTF-16'
78
+ )
79
+ f2 = tmpdir .join ('todo_utf16.txt' )
80
+ # noinspection SpellCheckingInspection
81
+ f2 .write_text ('TODO: ¥eßűs, ∂éñ∂ þħïs!-1' , encoding = 'utf-16' )
82
+ assert no_todos .main ((str (f1 ),str (f2 ))) == 2
83
+ assert mocked_print .call_args_list [- 2 ].args [0 ] \
84
+ .endswith ('todo_utf16.txt: cannot be read as UTF-8, trying UTF-16' )
85
+ f3 = tmpdir .join ('todo_greek.txt' )
86
+ # noinspection SpellCheckingInspection
87
+ f3 .write_text ('TODO: Υeσΰς, δέηδ ΤΞΪΣ!-1' , encoding = 'ISO-8859-7' )
88
+ assert no_todos .main ((str (f1 ),str (f2 ),str (f3 ))) == 2
89
+ assert mocked_print .call_args_list [- 1 ].args [0 ] \
90
+ .endswith ('todo_greek.txt: cannot be read as UTF-16, skipping it' )
0 commit comments