@@ -267,6 +267,17 @@ def test_second_non_utf8_coding_line(self):
267267 b'print(ascii("\xc3 \xa4 "))\n ' )
268268 self .check_script_output (src , br"'\xc3\u20ac'" )
269269
270+ def test_first_utf8_coding_line_error (self ):
271+ src = (b'#coding:ascii \xc3 \xa4 \n '
272+ b'raise RuntimeError\n ' )
273+ self .check_script_error (src , br"'ascii' codec can't decode byte" )
274+
275+ def test_second_utf8_coding_line_error (self ):
276+ src = (b'#!/usr/bin/python\n '
277+ b'#coding:ascii \xc3 \xa4 \n '
278+ b'raise RuntimeError\n ' )
279+ self .check_script_error (src , br"'ascii' codec can't decode byte" )
280+
270281 def test_utf8_bom (self ):
271282 src = (b'\xef \xbb \xbf print(ascii("\xc3 \xa4 "))\n ' )
272283 self .check_script_output (src , br"'\xe4'" )
@@ -282,7 +293,57 @@ def test_utf8_bom_and_utf8_coding_line(self):
282293 b'print(ascii("\xc3 \xa4 "))\n ' )
283294 self .check_script_output (src , br"'\xe4'" )
284295
285- def test_utf8_non_utf8_comment_line_error (self ):
296+ def test_non_utf8_shebang (self ):
297+ src = (b'#!/home/\xa4 /bin/python\n '
298+ b'#coding:iso-8859-15\n '
299+ b'print(ascii("\xc3 \xa4 "))\n ' )
300+ self .check_script_output (src , br"'\xc3\u20ac'" )
301+
302+ def test_utf8_shebang_error (self ):
303+ src = (b'#!/home/\xc3 \xa4 /bin/python\n '
304+ b'#coding:ascii\n '
305+ b'raise RuntimeError\n ' )
306+ self .check_script_error (src , br"'ascii' codec can't decode byte" )
307+
308+ def test_non_utf8_shebang_error (self ):
309+ src = (b'#!/home/\xa4 /bin/python\n '
310+ b'raise RuntimeError\n ' )
311+ self .check_script_error (src , br"Non-UTF-8 code starting with .* on line 1" )
312+
313+ def test_non_utf8_second_line_error (self ):
314+ src = (b'#\n '
315+ b'#\xa4 \n '
316+ b'raise RuntimeError\n ' )
317+ self .check_script_error (src ,
318+ br"Non-UTF-8 code starting with .* on line 2" )
319+
320+ def test_non_utf8_third_line_error (self ):
321+ src = (b'#\n '
322+ b'#\n '
323+ b'#\xa4 \n '
324+ b'raise RuntimeError\n ' )
325+ self .check_script_error (src ,
326+ br"Non-UTF-8 code starting with .* on line 3" )
327+
328+ def test_utf8_bom_non_utf8_third_line_error (self ):
329+ src = (b'\xef \xbb \xbf #\n '
330+ b'#\n '
331+ b'#\xa4 \n '
332+ b'raise RuntimeError\n ' )
333+ self .check_script_error (src ,
334+ br"Non-UTF-8 code starting with .* on line 3|"
335+ br"'utf-8' codec can't decode byte" )
336+
337+ def test_utf_8_non_utf8_third_line_error (self ):
338+ src = (b'#coding: utf-8\n '
339+ b'#\n '
340+ b'#\xa4 \n '
341+ b'raise RuntimeError\n ' )
342+ self .check_script_error (src ,
343+ br"Non-UTF-8 code starting with .* on line 3|"
344+ br"'utf-8' codec can't decode byte" )
345+
346+ def test_utf8_non_utf8_third_line_error (self ):
286347 src = (b'#coding: utf8\n '
287348 b'#\n '
288349 b'#\xa4 \n '
0 commit comments