ó
    ÞÅŸgžg  ã                   ó@  • S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJrJrJrJrJr  SSKJrJr  S r " S	 S
5      r " S S5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z)
Tests for L{pyflakes.scripts.pyflakes}.
é    N)ÚPYPY)ÚUnusedImport)ÚReporter)ÚmainÚcheckÚ	checkPathÚcheckRecursiveÚiterSourceCode)ÚTestCaseÚskipIfc                 ó‚   • [         R                  U sn[         l         U" U0 UD6U[         l        $ ! U[         l        f = f)z7
Call C{f} with C{sys.stderr} redirected to C{stderr}.
)ÚsysÚstderr)r   ÚfÚargsÚkwargsÚouters        ÚW/var/www/blue/EV-Temp_rev04/venv/lib/python3.13/site-packages/pyflakes/test/test_api.pyÚwithStderrTor      s7   € ô Ÿ:™: vÐ€UŒCŒJðÙ�$Ð!˜&Ñ!àŒ�
ø�UŒ�
ús   ž1 ±>c                   ó"   • \ rS rSrSrSS jrSrg)ÚNodeé%   z
Mock an AST node.
c                 ó   • Xl         X l        g ©N)ÚlinenoÚ
col_offset)Úselfr   r   s      r   Ú__init__ÚNode.__init__)   s   € ØŒØ$�ó    )r   r   N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__© r    r   r   r   %   s   † ñ÷%r    r   c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚSysStreamCapturingé.   zwContext manager capturing sys.stdin, sys.stdout and sys.stderr.

The file handles are replaced with a StringIO object.
c                 óf   • [         R                  " U=(       d    S[        R                  S9U l        g )NÚ ©Únewline)ÚioÚStringIOÚosÚlinesepÚ_stdin)r   Ústdins     r   r   ÚSysStreamCapturing.__init__4   s   € Ü—k’k %§+¨2´r·z±zÑBˆ�r    c                 óv  • [         R                  U l        [         R                  U l        [         R
                  U l        U R                  [         l        [        R                  " [        R                  S9=[         l        U l        [        R                  " [        R                  S9=[         l        U l        U $ )Nr-   )r   r4   Ú_orig_stdinÚstdoutÚ_orig_stdoutr   Ú_orig_stderrr3   r/   r0   r1   r2   Ú_stdout_stringioÚ_stderr_stringio©r   s    r   Ú	__enter__ÚSysStreamCapturing.__enter__7   sn   € ÜŸ9™9ˆÔÜŸJ™JˆÔÜŸJ™JˆÔà—K‘KŒŒ	Ü-/¯[ª[ÄÇÁÑ-LÐLŒŒ
�TÔ*Ü-/¯[ª[ÄÇÁÑ-LÐLŒŒ
�TÔ*àˆr    c                 óþ   • U R                   R                  5       U l        U R                  R                  5       U l        U R
                  [        l        U R                  [        l	        U R                  [        l        g r   )r;   ÚgetvalueÚoutputr<   Úerrorr7   r   r4   r9   r8   r:   r   )r   r   s     r   Ú__exit__ÚSysStreamCapturing.__exit__B   sU   € Ø×+Ñ+×4Ñ4Ó6ˆŒØ×*Ñ*×3Ñ3Ó5ˆŒ
à×$Ñ$ŒŒ	Ø×&Ñ&ŒŒ
Ø×&Ñ&Œ�
r    )r:   r7   r9   r<   r3   r;   rC   rB   N)	r!   r"   r#   r$   r%   r   r>   rD   r&   r'   r    r   r)   r)   .   s   † ñò
Cò	õ'r    r)   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚLoggingReporteréK   zC
Implementation of Reporter that just appends any error to a list.
c                 ó   • Xl         g)zP
Construct a C{LoggingReporter}.

@param log: A list to append log messages to.
N©Úlog)r   rK   s     r   r   ÚLoggingReporter.__init__P   s	   € ð �r    c                 óP   • U R                   R                  S[        U5      45        g )NÚflake)rK   ÚappendÚstr)r   Úmessages     r   rN   ÚLoggingReporter.flakeX   s   € Ø�‰�‰˜¤# g£,Ð/Õ0r    c                 ó>   • U R                   R                  SX45        g )NÚunexpectedError©rK   rO   )r   ÚfilenamerQ   s      r   rT   ÚLoggingReporter.unexpectedError[   s   € Ø�‰�‰Ð*¨HÐ>Õ?r    c                 óB   • U R                   R                  SXX4U45        g )NÚsyntaxErrorrU   )r   rV   Úmsgr   ÚoffsetÚlines         r   rY   ÚLoggingReporter.syntaxError^   s   € Ø�‰�‰˜¨°vÀtÐLÕMr    rJ   N)
r!   r"   r#   r$   r%   r   rN   rT   rY   r&   r'   r    r   rG   rG   K   s   † ñòò1ò@õNr    rG   c                   óT   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)ÚTestIterSourceCodeéb   z
Tests for L{iterSourceCode}.
c                 ó8   • [         R                  " 5       U l        g r   )ÚtempfileÚmkdtempÚtempdirr=   s    r   ÚsetUpÚTestIterSourceCode.setUpg   s   € Ü×'Ò'Ó)ˆ�r    c                 óD   • [         R                  " U R                  5        g r   ©ÚshutilÚrmtreerd   r=   s    r   ÚtearDownÚTestIterSourceCode.tearDownj   ó   € Ü�Š�d—l‘lÕ#r    c                 ó¢   • U(       d   e[         R                  R                  " U R                  /UQ76 n[	        US5      R                  5         U$ )NÚa)r1   ÚpathÚjoinrd   ÚopenÚclose)r   ÚpartsÚfpaths      r   ÚmakeEmptyFileÚ TestIterSourceCode.makeEmptyFilem   s<   € ÞˆˆuÜ—‘—’˜TŸ\™\Ð2¨EÒ2ˆÜˆU�CÓ×ÑÔ Øˆr    c                 ób   • U R                  [        [        U R                  /5      5      / 5        g)z2
There are no Python files in an empty directory.
N)ÚassertEqualÚlistr
   rd   r=   s    r   Útest_emptyDirectoryÚ&TestIterSourceCode.test_emptyDirectorys   s$   € ð 	×Ñœœn¨d¯l©l¨^Ó<Ó=¸rÕBr    c                 ó†   • U R                  S5      nU R                  [        [        U R                  /5      5      U/5        g)zL
If the directory contains one Python file, C{iterSourceCode} will find
it.
úfoo.pyN©rv   ry   rz   r
   rd   )r   Ú	childpaths     r   Útest_singleFileÚ"TestIterSourceCode.test_singleFiley   s6   € ð
 ×&Ñ& xÓ0ˆ	Ø×Ñœœn¨d¯l©l¨^Ó<Ó=À	¸{ÕKr    c                 ó„   • U R                  S5        U R                  [        [        U R                  /5      5      / 5        g)z:
Files that are not Python source files are not included.
zfoo.pycNr   r=   s    r   Útest_onlyPythonSourceÚ(TestIterSourceCode.test_onlyPythonSource�   s2   € ð 	×Ñ˜9Ô%Ø×Ñœœn¨d¯l©l¨^Ó<Ó=¸rÕBr    c                 óþ  • [         R                  " [         R                  R                  U R                  S5      5        U R                  SS5      nU R                  SS5        [         R                  " [         R                  R                  U R                  S5      5        U R                  SS5      nU R                  S5      nU R                  [        [        U R                  /5      5      [        XU/5      5        g)zS
If the Python files are hidden deep down in child directories, we will
find them.
Úfooúa.pyza.py~Úbarúb.pyzc.pyN)	r1   Úmkdirrp   rq   rd   rv   ry   Úsortedr
   )r   ÚapathÚbpathÚcpaths       r   Útest_recursesÚ TestIterSourceCode.test_recursesˆ   s´   € ô
 	�Š”—‘—‘˜dŸl™l¨EÓ2Ô3Ø×"Ñ" 5¨&Ó1ˆØ×Ñ˜5 'Ô*Ü
�Š”—‘—‘˜dŸl™l¨EÓ2Ô3Ø×"Ñ" 5¨&Ó1ˆØ×"Ñ" 6Ó*ˆØ×ÑÜ”> 4§<¡< .Ó1Ó2Ü�E %Ð(Ó)õ	+r    c                 ó¸  • [         R                  R                  U R                  S5      n[	        US5       nUR                  S5        SSS5        U R                  S5        [	        [         R                  R                  U R                  S5      S5       nUR                  S5        SSS5        [         R                  R                  U R                  S5      n[	        US5       nUR                  S	5        SSS5        [         R                  R                  U R                  S
5      n[	        US5       nUR                  S5        SSS5        [         R                  R                  U R                  S5      n[	        US5       nUR                  S5        SSS5        [         R                  R                  U R                  S5      n[	        US5       nUR                  S5        SSS5        [         R                  R                  U R                  S5      n[	        US5       nUR                  S5        SSS5        [         R                  R                  U R                  S5      n[	        US5       nUR                  S5        SSS5        U R                  [        [        U R                  /5      5      [        XXEUU/5      5        g! , (       d  f       GN‹= f! , (       d  f       GN>= f! , (       d  f       GN = f! , (       d  f       GNÂ= f! , (       d  f       GN„= f! , (       d  f       GNF= f! , (       d  f       GN= f! , (       d  f       NÉ= f)zL
Find Python files that don't end with `.py`, but contain a Python
shebang.
ro   Úwz#!/usr/bin/env python
NÚbÚczhello
world
Úez#!/usr/bin/env python3
r   z#!/usr/bin/env pythonw
Úgz#!/usr/bin/python3 -u
Úiz#!/usr/local/bin/python3d
Újz#! /usr/bin/env python3.8m
Úlz#!/bin/sh
#!/usr/bin/python
)
r1   rp   rq   rd   rr   Úwriterv   ry   rŒ   r
   )	r   ÚpythonÚfdÚpython3ÚpythonwÚpython3argsÚpython3dÚ	python38mÚnotfirsts	            r   Útest_shebangÚTestIterSourceCode.test_shebang—   sN  € ô
 —‘—‘˜dŸl™l¨CÓ0ˆÜ�&˜#Ô "Ø�H‰HÐ.Ô/÷ ð 	×Ñ˜3Ôä”"—'‘'—,‘,˜tŸ|™|¨SÓ1°3Ô7¸2Ø�H‰HÐ%Ô&÷ 8ô —'‘'—,‘,˜tŸ|™|¨SÓ1ˆÜ�'˜3Ô 2Ø�H‰HÐ/Ô0÷  ô —'‘'—,‘,˜tŸ|™|¨SÓ1ˆÜ�'˜3Ô 2Ø�H‰HÐ/Ô0÷  ô —g‘g—l‘l 4§<¡<°Ó5ˆÜ�+˜sÔ# rØ�H‰HÐ.Ô/÷ $ô —7‘7—<‘< §¡¨cÓ2ˆÜ�(˜CÔ  BØ�H‰HÐ2Ô3÷ !ô —G‘G—L‘L §¡¨sÓ3ˆ	Ü�)˜SÔ! RØ�H‰HÐ3Ô4÷ "ô —7‘7—<‘< §¡¨cÓ2ˆÜ�(˜CÔ  BØ�H‰HÐ5Ô6÷ !ð 	×ÑÜ”> 4§<¡< .Ó1Ó2ÜØ °xØðó õ	÷C Öú÷
 8Ö7ú÷  Öú÷  Öú÷ $Ö#ú÷ !Ö ú÷ "Ö!ú÷
 !Õ ús_   ·KÂKÃ&K1Ä6LÆLÇL'È&L9É6MË
KË
K.Ë1
L Ì
LÌ
L$Ì'
L6Ì9
MÍ
Mc                 óª  • [         R                  R                  U R                  S5      n[         R                  R                  U R                  S5      n[         R                  " U5        U R                  SS5      n[         R                  " U5        U R                  SS5      nU R                  [        [        X/5      5      [        X4/5      5        g)zZ
L{iterSourceCode} can be given multiple directories.  It will recurse
into each of them.
r‡   r‰   rˆ   rŠ   N)	r1   rp   rq   rd   r‹   rv   ry   rŒ   r
   )r   ÚfoopathÚbarpathr�   rŽ   s        r   Útest_multipleDirectoriesÚ+TestIterSourceCode.test_multipleDirectoriesÅ   s˜   € ô
 —'‘'—,‘,˜tŸ|™|¨UÓ3ˆÜ—'‘'—,‘,˜tŸ|™|¨UÓ3ˆÜ
�Š�ÔØ×"Ñ" 5¨&Ó1ˆÜ
�Š�ÔØ×"Ñ" 5¨&Ó1ˆØ×ÑÜ”> 7Ð"4Ó5Ó6Ü�E�>Ó"õ	$r    c                 ór   • U R                  S5      nU R                  [        [        U/5      5      U/5        g)zs
If one of the paths given to L{iterSourceCode} is not a directory but
a file, it will include that in its output.
ze.pyN)rv   ry   rz   r
   )r   Úepaths     r   Útest_explicitFilesÚ%TestIterSourceCode.test_explicitFilesÔ   s5   € ð
 ×"Ñ" 6Ó*ˆØ×Ñœœn¨e¨WÓ5Ó6Ø˜õ	"r    )rd   N)r!   r"   r#   r$   r%   re   rk   rv   r{   r�   r„   r�   r¤   r©   r­   r&   r'   r    r   r_   r_   b   s=   † ñò*ò$òòCòLòCò+ò,ò\$õ"r    r_   c                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ÚTestReporteréÞ   z
Tests for L{Reporter}.
c                 ó°   • [         R                  " 5       n[        SU5      nUR                  SSSSS5        U R	                  SUR                  5       5        g)zã
C{syntaxError} reports that there was a syntax error in the source
file.  It reports to the error stream and includes the filename, line
number, error message, actual line of source and a caret pointing to
where the error is.
Nr~   ú	a problemé   é   úbad line of sourcez2foo.py:3:8: a problem
bad line of source
       ^
©r/   r0   r   rY   ry   rA   ©r   ÚerrÚreporters      r   Útest_syntaxErrorÚTestReporter.test_syntaxErrorã   sP   € ô �kŠk‹mˆÜ˜D #Ó&ˆØ×Ñ˜X {°A°qÐ:NÔOØ×Ñðð �L‰L‹Nõ		r    c                 ó°   • [         R                  " 5       n[        SU5      nUR                  SSSSS5        U R	                  SUR                  5       5        g)za
C{syntaxError} doesn't include a caret pointing to the error if
C{offset} is passed as C{None}.
Nr~   r³   r´   r¶   z'foo.py:3: a problem
bad line of source
r·   r¸   s      r   Útest_syntaxErrorNoOffsetÚ%TestReporter.test_syntaxErrorNoOffsetó   sP   € ô
 �kŠk‹mˆÜ˜D #Ó&ˆØ×Ñ˜X {°A°tØ1ô	3à×Ñð$à�L‰L‹Nõ	r    c                 ó°   • [         R                  " 5       n[        SU5      nUR                  SSSSS5        U R	                  SUR                  5       5        g)z”
C{syntaxError} doesn't include text or nonsensical offsets if C{text} is C{None}.

This typically happens when reporting syntax errors from stdin.
Nú<stdin>r³   r   z<stdin>:1:1: a problem
r·   r¸   s      r   Útest_syntaxErrorNoTextÚ#TestReporter.test_syntaxErrorNoText  sH   € ô �kŠk‹mˆÜ˜D #Ó&ˆØ×Ñ˜Y¨°Q¸¸4Ô@Ø×ÑÐ4°s·|±|³~ÕFr    c           	      ó  • [         R                  " 5       nSS/n[        SU5      nUR                  SSS[	        US   5      S-   S	R                  U5      5        U R                  S
US   -   S	-   S-   S-   UR                  5       5        g)z˜
If there's a multi-line syntax error, then we only report the last
line.  The offset is adjusted so that it is relative to the start of
the last line.
r¶   zmore bad lines of sourceNr~   r³   r´   r   é   Ú
zfoo.py:3:25: a problem
éÿÿÿÿz                        ú^
)r/   r0   r   rY   Úlenrq   ry   rA   )r   r¹   Úlinesrº   s       r   Útest_multiLineSyntaxErrorÚ&TestReporter.test_multiLineSyntaxError  s™   € ô �kŠk‹mˆà Ø&ð
ˆô ˜D #Ó&ˆØ×Ñ˜X {°A´s¸5À¹8³}ÀqÑ7HØ!ŸY™Y uÓ-ô	/à×ÑØ'Ø�2‰YñØñàñàñð �L‰L‹Nõ		r    c                 óª   • [         R                  " 5       n[        SU5      nUR                  SS5        U R	                  SUR                  5       5        g)z?
C{unexpectedError} reports an error processing a source file.
Nz	source.pyzerror messagezsource.py: error message
)r/   r0   r   rT   ry   rA   r¸   s      r   Útest_unexpectedErrorÚ!TestReporter.test_unexpectedError   sB   € ô �kŠk‹mˆÜ˜D #Ó&ˆØ× Ñ  ¨oÔ>Ø×ÑÐ5°s·|±|³~ÕFr    c                 óÚ   • [         R                  " 5       n[        US5      n[        S[	        S5      S5      nUR                  U5        U R                  UR                  5       U S35        g)zl
C{flake} reports a code warning from Pyflakes.  It is exactly the
str() of a L{pyflakes.messages.Message}.
Nr~   é*   r‰   rÆ   )r/   r0   r   r   r   rN   ry   rA   )r   Úoutrº   rQ   s       r   Ú
test_flakeÚTestReporter.test_flake)  sU   € ô
 �kŠk‹mˆÜ˜C Ó&ˆÜ˜x¬¨b«°5Ó9ˆØ�‰�wÔØ×Ñ˜Ÿ™›¨G¨9°B¨Õ8r    r'   N)r!   r"   r#   r$   r%   r»   r¾   rÂ   rË   rÎ   rÓ   r&   r'   r    r   r°   r°   Þ   s'   † ñòò ò	Gòò(Gõ	9r    r°   c                   óà   • \ rS rSrSr\R                  S 5       rS rS r	S r
S rS rS	 rS
 rS rS rS rS r\" \R*                  S:H  S5      S 5       rS rS rS rS rS rS rS rSrg)Ú
CheckTestsi5  zD
Tests for L{check} and L{checkPath} which check a file for flakes.
c              #   ón  #   • [         R                  " 5       u  p# [        R                  " US5       n[	        US5      (       d  UR                  S5      nUR                  U5        SSS5        Uv •  [        R                  " U5        g! , (       d  f       N)= f! [        R                  " U5        f = f7f)zF
Make a temporary file containing C{content} and return a path to it.
ÚwbÚdecodeÚasciiN)rb   Úmkstempr1   ÚfdopenÚhasattrÚencoder›   Úremove)r   Úcontentr�   Únamer   s        r   ÚmakeTempFileÚCheckTests.makeTempFile:  s€   é € ô
 ×#Ò#Ó%‰ˆð	Ü—’˜2˜tÔ$¨Ü˜w¨×1Ñ1Ø%Ÿn™n¨WÓ5�GØ—‘˜Ô ÷ %ð ŠJä�IŠI�d�O÷ %Õ$ûô �IŠI�d�Oüs3   ‚B5›B ²4B	Á&B Á2B5Â	
BÂB ÂB2Â2B5c                 óÆ   • [         R                  " 5       n[        U[        U5      nU R	                  XCR                  5       4[        U5      SR                  U5      45        g)z’
Assert that C{path} causes errors.

@param path: A path to a file to check.
@param errorList: A list of errors expected to be printed to stderr.
r,   N)r/   r0   r   r   ry   rA   rÉ   rq   )r   rp   Ú	errorListr¹   Úcounts        r   ÚassertHasErrorsÚCheckTests.assertHasErrorsI  sL   € ô �kŠk‹mˆÜ˜S¤)¨TÓ2ˆØ×ÑØ—L‘L“NÐ#¤c¨)£n°b·g±g¸iÓ6HÐ%Iõ	Kr    c                 ó8   • / n[        U5      n[        X5      nXB4$ )aa  
Get any warnings or errors reported by pyflakes for the file at C{path}.

@param path: The path to a Python file on disk that pyflakes will check.
@return: C{(count, log)}, where C{count} is the number of warnings or
    errors generated, and log is a list of those warnings, presented
    as structured data.  See L{LoggingReporter} for more details.
)rG   r   )r   rp   rK   rº   ræ   s        r   Ú	getErrorsÚCheckTests.getErrorsU  s%   € ð ˆÜ" 3Ó'ˆÜ˜$Ó)ˆØˆzÐr    c                 óP   • SSK Jn  U R                  UR                  [        5        g )Nr   )Úpyflakes)Úpyflakes.scriptsrí   ÚassertIsr   )r   Úscript_pyflakess     r   Útest_legacyScriptÚCheckTests.test_legacyScriptc  s   € Ý@Ø�‰�o×/Ñ/´Õ;r    c                 ó~   • U R                  S5       nU R                  U/ 5        SSS5        g! , (       d  f       g= f)z‡
Source which doesn't end with a newline shouldn't cause any
exception to be raised nor an error indicator to be returned by
L{check}.
zdef foo():
	pass
	N©râ   rç   )r   ÚfNames     r   Útest_missingTrailingNewlineÚ&CheckTests.test_missingTrailingNewlineg  s1   € ð ×ÑÐ7Ô8¸EØ× Ñ  ¨Ô+÷ 9×8Ö8úó   ’.®
<c                 ót   • U R                  S5      u  pU R                  US5        U R                  US/5        g)z*
L{checkPath} handles non-existing files.
Úextremoé   )rT   rú   zNo such file or directoryN)rê   ry   )r   ræ   Úerrorss      r   Útest_checkPathNonExistingÚ$CheckTests.test_checkPathNonExistingp  s<   € ð Ÿ™ yÓ1‰ˆØ×Ñ˜ Ô"Ø×ÑØØHÐIõ	Kr    c                 ó0  • SnS n U" U5        U R                  5         U R                  U5       n[        (       a  SnO[        R                  S:¼  a  SnOS	n[        (       d  [        R                  S:¼  a  S
nOSnU R                  USXFUSUS-
  -  4-  /5        SSS5        g! [         aV  n[        (       dA  [        R                  S:  a-  U R                  UR                  R                  S5      S:„  5         SnANàSnAff = f! , (       d  f       g= f)z¯
Source which includes a syntax error which results in the raised
L{SyntaxError.text} containing multiple lines of source are reported
with only the last line of that source.
zCdef foo():
    '''

def bar():
    pass

def baz():
    '''quux'''
c                 ó   • [        U 5        g r   )Úexec)Úsources    r   ÚevaluateÚ6CheckTests.test_multilineSyntaxError.<locals>.evaluate�  s	   € Ü��Lr    ©r´   é
   rÆ   rû   Nz=end of file (EOF) while scanning triple-quoted string literalz>unterminated triple-quoted string literal (detected at line 8)zinvalid syntaxé   rµ   z%s:8:%d: %s
    '''quux'''
%s^
Ú )
ÚfailÚSyntaxErrorr   r   Úversion_infoÚ
assertTrueÚtextræ   râ   rç   )r   r  r  r–   Ú
sourcePathrQ   Úcolumns          r   Útest_multilineSyntaxErrorÚ$CheckTests.test_multilineSyntaxErrorz  sý   € ð	ˆò	ð	Ù�VÔð
 �I‰IŒKà×Ñ˜vÔ&¨*ßŠtØY‘Ü×!Ñ! WÓ,ØZ‘à*�çŠt”s×'Ñ'¨7Ó2Ø‘à�Ø× Ñ Øðð ˜7 C¨6°A©:Ñ$6Ð7ñ	8ð 9ô:÷ 'Ð&øô ó 	8ß’4œC×,Ñ,¨wÓ6Ø—‘ §¡§¡¨TÓ 2°QÑ 6Ô7ÿøð	8ú÷ 'Õ&ús$   ‡B$ °A+DÂ$
DÂ.AC?Ã?DÄ
Dc                 óH  • U R                  S5       n[        (       a  SnO[        R                  S:¼  a  SnOSn[        (       d  [        R                  S:¼  a  SnOSnSUS	-
  -  nS
R	                  XX$5      nU R                  X/5        SSS5        g! , (       d  f       g= f)ú{
The error reported for source files which end prematurely causing a
syntax error reflects the cause for the syntax error.
zdef foo(zparenthesis is never closedr  z'(' was never closedzunexpected EOF while parsingrµ   é	   r  rû   z{}:1:{}: {}
def foo(
{}^
N)râ   r   r   r  Úformatrç   )r   r  rZ   r  ÚspacesÚexpecteds         r   Útest_eofSyntaxErrorÚCheckTests.test_eofSyntaxError«  s“   € ð
 ×Ñ˜zÔ*¨jßŠtØ3‘Ü×!Ñ! WÓ,Ø,‘à4�çŠt”s×'Ñ'¨7Ó2Ø‘à�à˜F Q™JÑ'ˆFØ5×<Ñ<Ø CóˆHð × Ñ  ¨ZÔ8÷% +×*Ö*ús   ’A8BÂ
B!c                 ó†   • U R                  S5       nU R                  UU S3/5        SSS5        g! , (       d  f       g= f)r  zif True:
	foo =z$:2:7: invalid syntax
	foo =
	     ^
Nrô   ©r   r  s     r   Útest_eofSyntaxErrorWithTabÚ%CheckTests.test_eofSyntaxErrorWithTabÄ  sF   € ð
 ×ÑÐ2Ô3°zØ× Ñ Øà€ð ðð ô÷ 4×3Ö3ús	   ’2²
A c                 ó¢  • SnU R                  U5       n[        R                  S:¼  a  SnOSn[        (       a  [        R                  S:¼  a  SnO>[        (       a  SnO0[        R                  S:¼  a  SnO[        R                  S:¼  a  S	nOS
nSUS-
  -  S-   nU R	                  UU SU SU SU 3/5        SSS5        g! , (       d  f       g= f)z®
Source which has a non-default argument following a default argument
should include the line number of the syntax error.  However these
exceptions do not include an offset.
z def foo(bar=baz, bax):
    pass
©r´   r  z<parameter without a default follows parameter with a defaultz-non-default argument follows default argument©r´   r  é   rµ   r  é   r  r  rû   rÈ   z:1:z: z
def foo(bar=baz, bax):
N)râ   r   r  r   rç   )r   r  r  rZ   r  Ú	last_lines         r   Ú(test_nonDefaultFollowsDefaultSyntaxErrorÚ3CheckTests.test_nonDefaultFollowsDefaultSyntaxErrorÒ  sÔ   € ðˆð ×Ñ˜vÔ&¨*Ü×Ñ 7Ó*ØT‘àE�çŠtœ×(Ñ(¨FÓ2Ø‘ß’Ø‘Ü×!Ñ! WÓ,Ø‘Ü×!Ñ! VÓ+Ø‘à�Ø˜v¨™zÑ*¨UÑ2ˆIØ× Ñ Øà€ˆC�ˆx�r˜#˜ð à
€ðð ô÷# '×&Ö&ús   ”B#C Ã 
Cc           
      ó  • SnU R                  U5       n[        R                  S:¼  a  SnO[        (       d  SnOSnSUS-
  -  S-   nS	U-  nS
nU R	                  USR                  X%Xd5      /5        SSS5        g! , (       d  f       g= f)zª
Source which has a non-keyword argument after a keyword argument should
include the line number of the syntax error.  However these exceptions
do not include an offset.
zfoo(bar=baz, bax)
r   é   é   é   r  rû   rÈ   z%d:z,positional argument follows keyword argumentz{}:1:{} {}
foo(bar=baz, bax)
{}N)râ   r   r  r   rç   r  )r   r  r  r  r#  Ú	columnstrrQ   s          r   Ú&test_nonKeywordAfterKeywordSyntaxErrorÚ1CheckTests.test_nonKeywordAfterKeywordSyntaxErrorõ  s“   € ðˆð ×Ñ˜vÔ&¨*Ü×Ñ 6Ó)Ø‘ß’TØ‘à�Ø˜v¨™zÑ*¨UÑ2ˆIØ ™ˆIàDˆGà× Ñ Øð÷ �fˆZ GÓ7ð9ô:÷ '×&Ö&ús   ”AA:Á:
Bc                 óL  • U R                  S5       nSn[        (       a  [        R                  S:¼  a  SnO1[        (       a  SnO#S[        R                  s=::  a  S:  a  O  OSnOSnSS	US-
  -  -  nS
XX$4-  nU R	                  X/5        SSS5        g! , (       d  f       g= f)z9
The invalid escape syntax raises ValueError in Python 2
zfoo = '\xyz'rû   r   rÅ   é   r  r)  z%s^
r  zy%s:1:%d: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-%d: truncated \xXX escape
foo = '\xyz'
%sN)râ   r   r   r  rç   )r   r  Úposition_endr  r#  Údecoding_errors         r   Útest_invalidEscapeÚCheckTests.test_invalidEscape  s¢   € ð
 ×Ñ˜Ô/°:ØˆLßŠtœ×(Ñ(¨FÓ2Ø‘ß’Ø‘Øœ3×+Ñ+Õ5¨gÖ5Ø‘à�à 3¨&°1©*Ñ#5Ñ6ˆIðð 
˜\Ð5ñ	6ˆNð × Ñ ØÐ,ô.÷' 0×/Ö/ús   ’A:BÂ
B#Úwin32zunsupported on Windowsc                 óR  • [         R                  " 5       S:X  a  U R                  S5        U R                  S5       n[         R                  " US5        U R                  U5      u  p#U R                  US5        U R                  USUS4/5        SSS5        g! , (       d  f       g= f)zI
If the source file is not readable, this is reported on standard
error.
r   z8root user can access all files regardless of permissionsr,   rû   rT   zPermission deniedN)r1   ÚgetuidÚskipTestrâ   Úchmodrê   ry   ©r   r  ræ   rü   s       r   Útest_permissionDeniedÚ CheckTests.test_permissionDenied,  s�   € ô �9Š9‹;˜!ÓØ�M‰Mð (ô )à×Ñ˜rÔ" jÜ�HŠH�Z Ô#Ø ŸN™N¨:Ó6‰MˆEØ×Ñ˜U AÔ&Ø×ÑØØ# ZÐ1DÐEÐFôH÷	 #×"Ö"ús   ¼ABÂ
B&c                 ó  • U R                  S5       nU R                  U5      u  p#U R                  US5        U R                  US[        [	        U[        S5      S5      5      4/5        SSS5        g! , (       d  f       g= f)zK
If the source file has a pyflakes warning, this is reported as a
'flake'.
z
import foorû   rN   r‡   N)râ   rê   ry   rP   r   r   r8  s       r   Útest_pyflakesWarningÚCheckTests.test_pyflakesWarning=  sn   € ð
 ×Ñ˜|Ô,°
Ø ŸN™N¨:Ó6‰MˆEØ×Ñ˜U AÔ&Ø×ÑØ˜'¤3¤|°JÄÀQÃÈÓ'OÓ#PÐQÐRôT÷ -×,Ö,ús   ’AA3Á3
Bc                 ó¼   • [        S5      nSU-  R                  S5      nU R                  U5       nU R                  U/ 5        SSS5        g! , (       d  f       g= f)zE
If source file declares the correct encoding, no error is reported.
é&  z# coding: utf-8
x = "%s"
úutf-8N©ÚchrrÞ   râ   rç   ©r   ÚSNOWMANr  r  s       r   Útest_encodedFileUTF8ÚCheckTests.test_encodedFileUTF8H  sZ   € ô �f“+ˆðð ñ÷ ‰v�g‹ð 	ð ×Ñ˜vÔ&¨*Ø× Ñ  ¨RÔ0÷ '×&Ö&ús   ±AÁ
Ac                 ó~   • U R                  S5       nU R                  U/ 5        SSS5        g! , (       d  f       g= f)zG
Source files with Windows CR LF line endings are parsed successfully.
zx = 42
Nrô   r  s     r   Útest_CRLFLineEndingsÚCheckTests.test_CRLFLineEndingsT  s0   € ð ×Ñ˜|Ô,°
Ø× Ñ  ¨RÔ0÷ -×,Ö,úrø   c                 óÄ   • [        S5      nSU-  R                  S5      nU R                  U5       nU R                  UU S3/5        SSS5        g! , (       d  f       g= f)úV
If a source file contains bytes which cannot be decoded, this is
reported on stderr.
r?  ú# coding: ascii
x = "%s"
r@  zU:1:1: 'ascii' codec can't decode byte 0xe2 in position 21: ordinal not in range(128)
NrA  rC  s       r   Útest_misencodedFileUTF8Ú"CheckTests.test_misencodedFileUTF8[  sj   € ô
 �f“+ˆðð ñ÷ ‰v�g‹ð 	ð ×Ñ˜vÔ&¨*Ø× Ñ ØØ�<ÐuÐvÐwôy÷ '×&Ö&ús   ±AÁ
Ac                 óú   • [        S5      nSU-  R                  S5      nU R                  U5       n[        R                  S:  a  U S3nOU S3nU R                  X4/5        SSS5        g! , (       d  f       g= f)rK  r?  rL  zutf-16)r´   é   é   z: problem decoding source
z1:1: source code string cannot contain null bytes
N)rB  rÞ   râ   r   r  rç   )r   rD  r  r  r  s        r   Útest_misencodedFileUTF16Ú#CheckTests.test_misencodedFileUTF16j  sƒ   € ô
 �f“+ˆðð ñ÷ ‰v�hÓð 	ð ×Ñ˜vÔ&¨*Ü×Ñ *Ó,Ø(˜\Ð)DÐE‘à(˜\Ð)[Ð\�à× Ñ  ¨ZÔ8÷ '×&Ö&ús   ±2A,Á,
A:c                 óx  • [         R                  " 5       n [        R                  " [        R                  R                  US5      5        [        R                  R                  USS5      n[        US5       nUR                  S5        SSS5        [        R                  R                  US5      n[        US5       nUR                  S5        SSS5        / n[        U5      n[        U/U5      nU R                  US5        U R                  [        U5      [        S	[        [        U[        S
5      S5      5      4S	[        [        U[        S
5      S5      5      4/5      5        [        R                   " U5        g! , (       d  f       Nû= f! , (       d  f       NÆ= f! [        R                   " U5        f = f)z^
L{checkRecursive} descends into each directory, finding Python files
and reporting problems.
r‡   zbar.pyrØ   s   import baz
Nzbaz.pys   import contrabandé   rN   rû   ÚbazÚ
contraband)rb   rc   r1   r‹   rp   rq   rr   r›   rG   r	   ry   rŒ   rP   r   r   ri   rj   )r   rd   Úfile1r�   Úfile2rK   rº   Úwarningss           r   Útest_checkRecursiveÚCheckTests.test_checkRecursive|  sO  € ô
 ×"Ò"Ó$ˆð	#Ü�HŠH”R—W‘W—\‘\ '¨5Ó1Ô2Ü—G‘G—L‘L ¨%°Ó:ˆEÜ�e˜TÔ" bØ—‘˜Ô)÷ #ä—G‘G—L‘L ¨(Ó3ˆEÜ�e˜TÔ" bØ—‘Ð-Ô.÷ #àˆCÜ& sÓ+ˆHÜ% w i°Ó:ˆHØ×Ñ˜X qÔ)Ø×ÑÜ�s“Ü˜¤#¤l°5¼$¸q»'À5Ó&IÓ"JÐKØ Üœ\¨%´°a³¸,ÓGÓHðJðKó LôMô �MŠM˜'Õ"÷ #Õ"ú÷ #Õ"ûô �MŠM˜'Õ"ús=   —A!F! Á8E?Â
4F! Â>FÃBF! Å?
FÆ	F! Æ
FÆF! Æ!F9c                 ó8  • Sn[         R                  " 5       n[        U[        US5      nU R	                  US5        UR                  5       R                  S5      SS n[        R                  S:¼  a  / SQnO[        (       a  / S	QnOS
/nU R	                  XE5        g)z+
L{check} reports syntax errors from stdin
z-max(1 for i in range(10), key=lambda x: x+1)
rÁ   rû   rÆ   NrÇ   r   )ú7<stdin>:1:5: Generator expression must be parenthesizedú,max(1 for i in range(10), key=lambda x: x+1)z    ^)zL<stdin>:1:4: Generator expression must be parenthesized if not sole argumentr_  z   ^r^  )
r/   r0   r   r   ry   rA   Úsplitr   r  r   )r   r  r¹   ræ   ÚerrlinesÚexpected_errors         r   Útest_stdinReportsErrorsÚ"CheckTests.test_stdinReportsErrors–  s’   € ð BˆÜ�kŠk‹mˆÜ˜S¤%¨°Ó;ˆØ×Ñ˜ Ô"Ø—<‘<“>×'Ñ'¨Ó-¨c¨rÐ2ˆä×Ñ˜vÓ%ò‰N÷
 ŠTò‰Nð JðˆNð 	×Ñ˜Õ2r    r'   N)r!   r"   r#   r$   r%   Ú
contextlibÚcontextmanagerrâ   rç   rê   rñ   rö   rý   r  r  r  r$  r+  r1  r   r   Úplatformr9  r<  rE  rH  rM  rR  r[  rc  r&   r'   r    r   rÖ   rÖ   5  s¨   † ñð ×Ññó ðò
Kòò<ò,òKò/:òb9ò2ò!òF:ò8.ñ6 ˆC�L‰L˜GÑ#Ð%=Ó>ñHó ?ðHò 	Tò
1ò1òyò9ò$#õ43r    rÖ   c                   óR   • \ rS rSrSrS rS rS rSS jrS r	S	 r
S
 rS rS rSrg)ÚIntegrationTestsi´  z>
Tests of the pyflakes script that actually spawn the script.
c                 ó–   • [         R                  " 5       U l        [        R                  R                  U R                  S5      U l        g )NÚtemp)rb   rc   rd   r1   rp   rq   Útempfilepathr=   s    r   re   ÚIntegrationTests.setUp¸  s-   € Ü×'Ò'Ó)ˆŒÜŸG™GŸL™L¨¯©°vÓ>ˆÕr    c                 óD   • [         R                  " U R                  5        g r   rh   r=   s    r   rk   ÚIntegrationTests.tearDown¼  rm   r    c                 ó    • SSK n[        R                  R                  UR                  5      n[        R                  R                  USSS5      $ )z)
Return the path to the pyflakes binary.
r   Nz..Úbinrí   )rí   r1   rp   ÚdirnameÚ__file__rq   )r   rí   Úpackage_dirs      r   ÚgetPyflakesBinaryÚ"IntegrationTests.getPyflakesBinary¿  s8   € ó 	Ü—g‘g—o‘o h×&7Ñ&7Ó8ˆÜ�w‰w�|‰|˜K¨¨u°jÓAÐAr    Nc                 óÀ  • [        [        R                  5      n[        R                  R	                  [
        R                  5      US'   [
        R                  U R                  5       /nUR                  U5        U(       ad  [        R                  " XC[        R                  [        R                  [        R                  S9nUR                  UR                  S5      5      u  pgOD[        R                  " XC[        R                  [        R                  S9nUR                  5       u  pgUR                  5       nUR!                  S5      nUR!                  S5      nXgU4$ )zÙ
Launch a subprocess running C{pyflakes}.

@param paths: Command-line arguments to pass to pyflakes.
@param stdin: Text to use as stdin.
@return: C{(returncode, stdout, stderr)} of the completed pyflakes
    process.
Ú
PYTHONPATH)Úenvr4   r8   r   rÚ   )ry  r8   r   r@  )Údictr1   ÚenvironÚpathseprq   r   rp   Ú
executableru  ÚextendÚ
subprocessÚPopenÚPIPEÚcommunicaterÞ   ÚwaitrÙ   )	r   Úpathsr4   ry  ÚcommandÚpr8   r   Úrvs	            r   ÚrunPyflakesÚIntegrationTests.runPyflakesÇ  sõ   € ô ”2—:‘:ÓˆÜŸJ™JŸO™O¬C¯H©HÓ5ˆˆLÑÜ—>‘> 4×#9Ñ#9Ó#;Ð<ˆØ�‰�uÔÞÜ× Ò  ¼¿¹Ü(2¯©Ä
ÇÁñQˆAà Ÿ}™}¨U¯\©\¸'Ó-BÓCÑˆV�Vä× Ò  Ü(2¯©Ä
ÇÁñQˆAà Ÿ}™}›ÑˆVØ�V‰V‹XˆØ—‘˜wÓ'ˆØ—‘˜wÓ'ˆØ Ð#Ð#r    c                 ó¨   • [        U R                  S5      R                  5         U R                  U R                  /5      nU R	                  US5        g)zx
When a Python source file is all good, the return code is zero and no
messages are printed to either stdout or stderr.
ro   )r,   r,   r   N)rr   rl  rs   rˆ  ry   )r   Úds     r   Útest_goodFileÚIntegrationTests.test_goodFileá  sF   € ô
 	ˆT×Ñ Ó$×*Ñ*Ô,Ø×Ñ˜d×/Ñ/Ð0Ó1ˆØ×Ñ˜˜KÕ(r    c                 óJ  • [        U R                  S5       nUR                  S5        SSS5        U R                  U R                  /5      n[	        U R                  [        S5      S5      nU R                  X# [        R                   3SS45        g! , (       d  f       Nq= f)zm
When a Python source file has warnings, the return code is non-zero
and the warnings are printed to stdout.
rØ   s   import contraband
Nrû   rW  r,   )	rr   rl  r›   rˆ  r   r   ry   r1   r2   )r   r�   r‹  r  s       r   Útest_fileWithFlakesÚ$IntegrationTests.test_fileWithFlakesê  s„   € ô
 �$×#Ñ# TÔ*¨bØ�H‰HÐ+Ô,÷ +à×Ñ˜d×/Ñ/Ð0Ó1ˆÜ × 1Ñ 1´4¸³7¸LÓIˆØ×Ñ˜˜z¬"¯*©*¨Ð6¸¸AÐ>Õ?÷	 +Õ*ús   —BÂ
B"c                 óº   • U R                  U R                  /5      nSR                  U R                  [        R                  5      nU R                  USUS45        g)úš
When pyflakes finds errors with the files it's given, (if they don't
exist, say), then the return code is non-zero and the errors are
printed to stderr.
z{}: No such file or directory{}r,   rû   N)rˆ  rl  r  r1   r2   ry   )r   r‹  Ú	error_msgs      r   Útest_errors_ioÚIntegrationTests.test_errors_ioõ  sT   € ð ×Ñ˜d×/Ñ/Ð0Ó1ˆØ5×<Ñ<¸T×=NÑ=NÜ=?¿Z¹ZóIˆ	à×Ñ˜˜R ¨AÐ.Õ/r    c                 ó<  • [        U R                  S5       nUR                  S5        SSS5        U R                  U R                  /5      nSR	                  U R                  [
        R                  5      nU R                  USUS45        g! , (       d  f       Nj= f)r’  rØ   s   importNz-{0}:1:7: invalid syntax{1}import{1}      ^{1}r,   rû   )rr   rl  r›   rˆ  r  r1   r2   ry   )r   r�   r‹  r“  s       r   Útest_errors_syntaxÚ#IntegrationTests.test_errors_syntax   s   € ô �$×#Ñ# TÔ*¨bØ�H‰H�YÔ÷ +à×Ñ˜d×/Ñ/Ð0Ó1ˆØC×JÑJØ×ÑœrŸz™zó+ˆ	à×Ñ˜˜R ¨AÐ.Õ/÷ +Õ*ús   —BÂ
Bc                 óœ   • U R                  / SS9n[        S[        S5      S5      nU R                  X [        R
                   3SS45        g)zE
If no arguments are passed to C{pyflakes} then it reads from stdin.
zimport contraband)r4   rÁ   rû   rW  r,   N)rˆ  r   r   ry   r1   r2   )r   r‹  r  s      r   Útest_readFromStdinÚ#IntegrationTests.test_readFromStdin  sN   € ð ×Ñ˜RÐ':ÐÐ;ˆÜ 	¬4°«7°LÓAˆØ×Ñ˜˜z¬"¯*©*¨Ð6¸¸AÐ>Õ?r    )rd   rl  r   )r!   r"   r#   r$   r%   re   rk   ru  rˆ  rŒ  r�  r”  r—  rš  r&   r'   r    r   ri  ri  ´  s7   † ñò?ò$òBô$ò4)ò	@ò	0ò0õ@r    ri  c                   ó"   • \ rS rSrSrSS jrSrg)ÚTestMaini  z&
Tests of the pyflakes main function.
Nc                 ó@  •  [        U5       n[        US9  S S S 5        [        S5      e! , (       d  f       N= f! [         aX  nU R	                  UR
                  [        5        [        UR
                  5      nWR                  UR                  U4s S nA$ S nAff = f)N)r   zSystemExit not raised)
r)   r   ÚRuntimeErrorÚ
SystemExitÚassertIsInstanceÚcodeÚboolÚintrB   rC   )r   r„  r4   Úcapturer–   r‡  s         r   rˆ  ÚTestMain.runPyflakes  sz   € ð	8Ü# EÔ*¨gÜ˜%Ò ÷ +ô Ð6Ó7Ð7÷ +Õ*ûäó 	7Ø×!Ñ! !§&¡&¬$Ô/Ü�Q—V‘V“ˆBØ—N‘N G§M¡M°2Ð6Õ6ûð	7ús,   ‚; �
*—; ª
8´; »
BÁABÂBÂBr'   r   )r!   r"   r#   r$   r%   rˆ  r&   r'   r    r   r�  r�    s   † ñ÷	8r    r�  ) r%   re  r/   r1   r   ri   r  rb   Úpyflakes.checkerr   Úpyflakes.messagesr   Úpyflakes.reporterr   Úpyflakes.apir   r   r   r	   r
   Úpyflakes.test.harnessr   r   r   r   r)   rG   r_   r°   rÖ   ri  r�  r'   r    r   Ú<module>r¬     s©   ðñó Û 	Û 	Û 
Û Û Û å !Ý *Ý &÷õ ÷ 3ò÷%ñ %÷'ñ '÷:Nñ Nô.y"˜ô y"ôxT9�8ô T9ôn|3�ô |3ô~_@�xô _@ôD8Ðõ 8r    