U _c@sddlZddlmZmZmZmZmZmZddlZddl Z ddl Z ddl Z ddl Z Gdddej ZGdddZGdddeej ZGd d d eej Zed kredS) N)TESTFNunlinkunloadrmtree script_helpercaptured_stdoutc@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)MiscSourceEncodingTestcCs(|ddd|ddddS)Nu Питонutf-8s Питонu\Пs\П) assertEqualencodeselfr 1/usr/lib64/python3.8/test/test_source_encoding.py test_pep263 sz"MiscSourceEncodingTest.test_pep263cCs.tddd}i}t||||dddS)Ns # coding: utf-8 u = 'ó' dummyexecZuuócompilerr r cdr r rtest_compilestrings  z)MiscSourceEncodingTest.test_compilestringc CsTztdddWn6tk rF}z||jddW5d}~XYn X|dS)Ns# coding: cp932 print 'N'rrZ u print '年')r SyntaxErrorr ZtextrstripZfail)r Zvr r rtest_issue2301s &z%MiscSourceEncodingTest.test_issue2301cCs.tddd}i}t||||dddS)Nu# coding=latin-1 Æ = 'Æ'rruÆrrr r rtest_issue4626&s  z%MiscSourceEncodingTest.test_issue4626cCsjtddd}i}t||||d|d|t|dt|d|t|dt|ddS)Nua, b = '𐄏', '\U0001010F'rraZb)rrr ZlenZasciirr r rtest_issue3297,s   z%MiscSourceEncodingTest.test_issue3297cCs |ttd|ttddS)Ns s ) assertRaisesrZevalr r r rtest_issue78204sz%MiscSourceEncodingTest.test_issue7820cCsRtjtjtjtjtdgtj d}| d}| |j d| d|dS)Nzcoding20731.py)Zstderrirs SyntaxError) subprocessZPopensysZ executableospathjoindirname__file__ZPIPEZ communicater Z returncodeZ assertNotIn)r ZsubZerrr r r test_20731?s z!MiscSourceEncodingTest.test_20731c Cstdddtdddtddd|tdtdddW5QRX|tdtd ddW5QRX|td td ddW5QRX|tdtd ddW5QRX|td td ddW5QRXdS) Ns# -*- coding: iso-8859-15 -*- rrs s# -*- coding: utf-8 -*- Zfakes# -*- coding: fake -*- z iso-8859-15s!# -*- coding: iso-8859-15 -*- ZBOMs# -*- coding: fake -*- )rZassertRaisesRegexrr r r rtest_error_messageHs&   z)MiscSourceEncodingTest.test_error_messagecCd}||dS)NZ bad_codingverify_bad_moduler module_namer r rtest_bad_codingYz&MiscSourceEncodingTest.test_bad_codingcCr))NZ bad_coding2r*r,r r rtest_bad_coding2]r/z'MiscSourceEncodingTest.test_bad_coding2c Csd|ttd|tjt}tj||d}t|d}| }W5QRX|tt ||ddS)Nztest..pyZrbr) rr __import__r"r#r%r&r$openZreadr)r r-r#filenamefpZbytesr r rr+as   z(MiscSourceEncodingTest.verify_bad_modulecCs"i}td|||dddS)Ns# coding: cp949 a = "" ruぇ)rr )r rr r rtest_exec_valid_codingjs z-MiscSourceEncodingTest.test_exec_valid_codingc Cstttd}t|ddd}tjdtjzP|2| d | d | d | d d W5QRXt t tW5tjd=t|t|dt|dttt dXdS)Nr1ZwZcp1252)ZencodingrrZoZ __pycache__z# -*- coding: cp1252 -*- z'''A short string z''' z'A very long string %s' AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)rrr3r!r#Zinsertr"Zcurdirrrwrite importlibZinvalidate_cachesr2)r r4Zfr r rtest_file_parseos$      z&MiscSourceEncodingTest.test_file_parsec CsXdd}|t}t|ddW5QRXd}|j|jjd||jjdddS)Nu# coding: ascii ☃rzrzN'ascii' codec can't decode byte 0xe2 in position 16: ordinal not in range(128)r)Zmsg)r rrrZ assertTrueZ exceptionZargsZ startswith)r Zinputrexpectedr r rtest_error_from_strings   z-MiscSourceEncodingTest.test_error_from_stringN)__name__ __module__ __qualname__rrrrrrr'r(r.r0r+r6r9r;r r r rr s    rc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)AbstractSourceEncodingTestcCd}||ddS)Nsprint(ascii("ä")) '\xe4'check_script_outputr srcr r rtest_default_codingr/z.AbstractSourceEncodingTest.test_default_codingcCr@)Ns&#coding:iso8859-15 print(ascii("ä")) '\xc3\u20ac'rBrDr r rtest_first_coding_linez1AbstractSourceEncodingTest.test_first_coding_linecCr@)Ns(# #coding:iso8859-15 print(ascii("ä")) rGrBrDr r rtest_second_coding_linez2AbstractSourceEncodingTest.test_second_coding_linecCr@)Ns*# # #coding:iso8859-15 print(ascii("ä")) rArBrDr r rtest_third_coding_linesz1AbstractSourceEncodingTest.test_third_coding_linecCr@)Ns5#coding:iso8859-15 #coding:latin1 print(ascii("ä")) rGrBrDr r rtest_double_coding_linesz2AbstractSourceEncodingTest.test_double_coding_linecCr@)Ns4#coding:iso8859-15 coding:latin1 print(ascii("ä")) rGrBrDr r rtest_double_coding_same_linerIz7AbstractSourceEncodingTest.test_double_coding_same_linecCr@)Ns)#coding:iso-8859-15 print(ascii("ä")) rGrBrDr r rtest_first_non_utf8_coding_linerIz:AbstractSourceEncodingTest.test_first_non_utf8_coding_linecCr@)Ns* #coding:iso-8859-15 print(ascii("ä")) rGrBrDr r r test_second_non_utf8_coding_linerKz;AbstractSourceEncodingTest.test_second_non_utf8_coding_linecCr@)Nsprint(ascii("ä")) rArBrDr r r test_utf8_bomr/z(AbstractSourceEncodingTest.test_utf8_bomcCr@)Ns$#coding:utf-8 print(ascii("ä")) rArBrDr r r"test_utf8_bom_and_utf8_coding_linerIz=AbstractSourceEncodingTest.test_utf8_bom_and_utf8_coding_lineN) r<r=r>rFrHrJrLrMrNrOrPrQrRr r r rr?sr?c@eZdZddZdS)BytesSourceEncodingTestc Cs<t}t|W5QRX|d}|||dS)NZlatin1)rrZgetvaluer r r)r rEr:Zstdoutoutr r rrCsz+BytesSourceEncodingTest.check_script_outputNr<r=r>rCr r r rrTrTc@rS)FileSourceEncodingTestc Csbt>}tj|d}t|d}||W5QRXt|}W5QRX| |j |dS)Nztest.pyZwb) tempfileZTemporaryDirectoryr"r#r$r3r7rZassert_python_okr rUr)r rEr:ZtmpdZfnr5Zresr r rrCs   z*FileSourceEncodingTest.check_script_outputNrVr r r rrXrWrXZ__main__)ZunittestZ test.supportrrrrrrr8r"r!r rYZTestCaserr?rTrXr<Zmainr r r rZs :