U _@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\П) assertEqualencodeselfr1/usr/lib64/python3.8/test/test_source_encoding.py test_pep263 sz"MiscSourceEncodingTest.test_pep263cCs.tddd}i}t||||dddS)Ns # coding: utf-8 u = 'ó' dummyexecuócompilerr r cdrrrtest_compilestrings  z)MiscSourceEncodingTest.test_compilestringc CsTztdddWn6tk rF}z||jddW5d}~XYn X|dS)Ns# coding: cp932 print 'N'rr u print '年')r SyntaxErrorr textrstripZfail)r vrrrtest_issue2301s &z%MiscSourceEncodingTest.test_issue2301cCs.tddd}i}t||||dddS)Nu# coding=latin-1 Æ = 'Æ'rrÆrrrrrtest_issue4626&s  z%MiscSourceEncodingTest.test_issue4626cCsjtddd}i}t||||d|d|t|dt|d|t|dt|ddS)Nua, b = '𐄏', '\U0001010F'rrab)rrr lenasciirrrrtest_issue3297,s   z%MiscSourceEncodingTest.test_issue3297cCs |ttd|ttddS)Ns s ) assertRaisesrevalr rrrtest_issue78204sz%MiscSourceEncodingTest.test_issue7820cCsRtjtjtjtjtdgtj d}| d}| |j d| d|dS)Nzcoding20731.py)stderrrs SyntaxError) subprocessPopensys executableospathjoindirname__file__PIPE communicater returncodeZ assertNotIn)r suberrrrr 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 -*- BOMs# -*- coding: fake -*- )rZassertRaisesRegexrr rrrtest_error_messageHs&   z)MiscSourceEncodingTest.test_error_messagecCsd}||dS)NZ bad_codingverify_bad_moduler module_namerrrtest_bad_codingYsz&MiscSourceEncodingTest.test_bad_codingcCsd}||dS)NZ bad_coding2r>r@rrrtest_bad_coding2]sz'MiscSourceEncodingTest.test_bad_coding2c Csd|ttd|tjt}tj||d}t|d}| }W5QRX|tt ||ddS)Nztest..pyrbr) r(r __import__r1r2r4r5r3openreadr)r rAr2filenamefpbytesrrrr?as   z(MiscSourceEncodingTest.verify_bad_modulecCs"i}td|||dddS)Ns# coding: cp949 a = "" r#uぇ)rr )r rrrrtest_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)NrDwcp1252)encodingrro __pycache__z# -*- coding: cp1252 -*- z'''A short string z''' z'A very long string %s' AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)rrrGr/r2insertr1curdirrrwrite importlibinvalidate_cachesrF)r rIfrrrtest_file_parseos$      z&MiscSourceEncodingTest.test_file_parsec CsXdd}|t}t|ddW5QRXd}|j|jjd||jjdddS)Nu# coding: ascii ☃r zrzN'ascii' codec can't decode byte 0xe2 in position 16: ordinal not in range(128)r)msg)r r(rrZ assertTrue exceptionargs startswith)r inputrexpectedrrrtest_error_from_strings   z-MiscSourceEncodingTest.test_error_from_stringN)__name__ __module__ __qualname__rrr r"r'r*r;r=rBrCr?rLrXr_rrrrr s    rc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)AbstractSourceEncodingTestcCsd}||ddS)Nsprint(ascii("ä")) '\xe4'check_script_outputr srcrrrtest_default_codingsz.AbstractSourceEncodingTest.test_default_codingcCsd}||ddS)Ns&#coding:iso8859-15 print(ascii("ä")) '\xc3\u20ac'rergrrrtest_first_coding_linesz1AbstractSourceEncodingTest.test_first_coding_linecCsd}||ddS)Ns(# #coding:iso8859-15 print(ascii("ä")) rjrergrrrtest_second_coding_linesz2AbstractSourceEncodingTest.test_second_coding_linecCsd}||ddS)Ns*# # #coding:iso8859-15 print(ascii("ä")) rdrergrrrtest_third_coding_linesz1AbstractSourceEncodingTest.test_third_coding_linecCsd}||ddS)Ns5#coding:iso8859-15 #coding:latin1 print(ascii("ä")) rjrergrrrtest_double_coding_linesz2AbstractSourceEncodingTest.test_double_coding_linecCsd}||ddS)Ns4#coding:iso8859-15 coding:latin1 print(ascii("ä")) rjrergrrrtest_double_coding_same_linesz7AbstractSourceEncodingTest.test_double_coding_same_linecCsd}||ddS)Ns)#coding:iso-8859-15 print(ascii("ä")) rjrergrrrtest_first_non_utf8_coding_linesz:AbstractSourceEncodingTest.test_first_non_utf8_coding_linecCsd}||ddS)Ns* #coding:iso-8859-15 print(ascii("ä")) rjrergrrr test_second_non_utf8_coding_linesz;AbstractSourceEncodingTest.test_second_non_utf8_coding_linecCsd}||ddS)Nsprint(ascii("ä")) rdrergrrr test_utf8_bomsz(AbstractSourceEncodingTest.test_utf8_bomcCsd}||ddS)Ns$#coding:utf-8 print(ascii("ä")) rdrergrrr"test_utf8_bom_and_utf8_coding_linesz=AbstractSourceEncodingTest.test_utf8_bom_and_utf8_coding_lineN) r`rarbrirkrlrmrnrorprqrrrsrrrrrcsrcc@seZdZddZdS)BytesSourceEncodingTestc Cs<t}t|W5QRX|d}|||dS)Nlatin1)rrgetvaluer r r)r rhr^stdoutoutrrrrfsz+BytesSourceEncodingTest.check_script_outputNr`rarbrfrrrrrtsrtc@seZdZddZdS)FileSourceEncodingTestc Csbt>}tj|d}t|d}||W5QRXt|}W5QRX| |j |dS)Nztest.pywb) tempfileTemporaryDirectoryr1r2r3rGrTrZassert_python_okr rxr)r rhr^ZtmpdfnrJresrrrrfs   z*FileSourceEncodingTest.check_script_outputNryrrrrrzsrz__main__)ZunittestZ test.supportrrrrrrrUr1r/r-r|ZTestCaserrcrtrzr`mainrrrrs :