
    jjd                     @   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        N/var/www/html/KUNJ/venv/lib/python3.13/site-packages/pyflakes/test/test_api.pywithStderrTor      s7     ::vUCJ$!&!
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    kk%+2rzz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    99JJJJKK	-/[[-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)	LoggingReporterK   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    vt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)TestIterSourceCodeb   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       dll#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\\2E2UC 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$     	ndll^<=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	ndll^<=	{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%ndll^<=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    
 	dllE23""5&15'*
dllE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   
 dllC0&#"HH./  	3"'',,t||S1372HH%& 8 '',,t||S1'32HH/0   '',,t||S1'32HH/0   ggll4<<5+s#rHH./ $ 77<<c2(C BHH23 ! GGLLs3	)S!RHH34 " 77<<c2(C BHH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*neW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     kkmD#&X{Aq:NO LLN		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    
 kkmD#&X{At1	3$LLN	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     kkmD#&YQ4@4s||~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     kkm &
 D#&X{As58}q7H!YYu-	/'2Y LLN		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     kkmD#&  o>5s||~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    
 kkmC&xb59wG9B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     
 ##%	2t$w11%nnW5G  % JIIdO %$ IIdOs3   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     kkmS)T2LLN#c)nbggi6H%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8E  + 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NS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   evaluate6CheckTests.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)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
 IIKv&*tY!!W,Z*ts''72   7C6A:$67	8 9: '&  	84C,,w6T 2Q 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ts''72FQJ'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3z     433s	   2
A c                 0   SnU R                  U5       n[        R                  S:  a  SnOSn[        (       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   z:1:z: z
def foo(bar=baz, bax):
N)r   r   r  r   r   )r   r  r  rZ   r  	last_lines         r   (test_nonDefaultFollowsDefaultSyntaxError3CheckTests.test_nonDefaultFollowsDefaultSyntaxError  s     v&*7*TEt!!W,vz*U2I  Cxr# 
  '&&s   A*B
Bc                     SnU R                  U5       nSnU R                  UU SU 3/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)
z                ^
zF:1:17: positional argument follows keyword argument
foo(bar=baz, bax)
Nr   )r   r  r  r#  s       r   &test_nonKeywordAfterKeywordSyntaxError1CheckTests.test_nonKeywordAfterKeywordSyntaxError  sV     v&*(I   
  '&&s	   8
Ac                     U R                  S5       nSn[        (       a  SnO[        R                  S:  a  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      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!!G+3&1*#56I 
\5	6N   ,.# 0//s   AA))
A7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     99;!MM ( )r"jHHZ# NN:6MEUA&#Z1D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   r4  s       r   test_pyflakesWarningCheckTests.test_pyflakesWarning-  sn    
 |,
 NN:6MEUA&'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_encodedFileUTF88  sZ     f+  vg 	 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_CRLFLineEndingsD  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)
Nr=  r?  s       r   test_misencodedFileUTF8"CheckTests.test_misencodedFileUTF8K  sj    
 f+  vg 	 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)rG  r;  rH  zutf-16)r         z: problem decoding source
z1:1: source code string cannot contain null bytes
N)r>  r   r   r   r  r   )r   r@  r  r  r  s        r   test_misencodedFileUTF16#CheckTests.test_misencodedFileUTF16Z  s    
 f+  vh 	 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_checkRecursivel  sO   
 ""$	#HHRWW\\'512GGLL%:EeT"b) #GGLL(3EeT"b-. #C&s+H%wi:HXq)s#l5$q'5&I"JK \%a,GHJK LM MM'" #" #" MM'"s=   A!F! 8E?
4F! >FBF! ?
F	F! 
FF! !F9c                     Sn[         R                  " 5       n[        U[        US5      nU R	                  US5        UR                  5       R                  S5      SS n/ SQ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   )z7<stdin>:1:5: Generator expression must be parenthesizedz,max(1 for i in range(10), key=lambda x: x+1)z    ^)r/   r0   r   r   ry   rA   split)r   r  r   r   errlinesexpected_errors         r   test_stdinReportsErrors"CheckTests.test_stdinReportsErrors  si     BkkmS%;"<<>''-cr2

 	2r    r'   N)r!   r"   r#   r$   r%   
contextlibcontextmanagerr   r   r   r   r   r   r  r  r  r$  r'  r-  r   r   platformr5  r8  rA  rD  rI  rN  rW  r]  r&   r'   r    r   r   r   5  s      
K<,K/:b92>$.2 CLLG#%=>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-    '')GGLL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     	ggooh&7&78ww||Kuj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   )rs  r8   r   r<  )dictr1   environpathseprq   r   rp   
executablero  extend
subprocessPopenPIPEcommunicater   waitr   )	r   pathsr4   rs  commandpr8   r   rvs	            r   runPyflakesIntegrationTests.runPyflakes  s     2::JJOOCHH5L>>4#9#9#;<u  (2
QA }}U\\'-BCVV  (2
QA }}VVVX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   rf  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   rS  r,   )	rr   rf  r   r  r   r   ry   r1   r2   )r   r   r  r  s       r   test_fileWithFlakes$IntegrationTests.test_fileWithFlakes  s    
 $##T*bHH+, +d//01 1 147L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  rf  r  r1   r2   ry   )r   r  	error_msgs      r   test_errors_ioIntegrationTests.test_errors_io  sT     d//015<<T=N=N=?ZZI	RA./r    c                 p   [        U R                  S5       nUR                  S5        SSS5        U R                  U R                  /5      n[        R
                  S:  a  SnOSnSR                  U R                  U[        R                  5      nU R                  USUS	45        g! , (       d  f       N= f)
r  r   s   importN)r   r*  z)Expected one or more names after 'import'r  z"{0}:1:7: {1}{2}import{2}      ^{2}r,   r   )
rr   rf  r   r  r   r  r  r1   r2   ry   )r   r   r  rQ   r  s        r   test_errors_syntax#IntegrationTests.test_errors_syntax  s     $##T*bHHY +d//01w&AG&G8??w

4	RA./ +*s   B''
B5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   rS  r,   N)r  r   r   ry   r1   r2   )r   r  r  s      r   test_readFromStdin#IntegrationTests.test_readFromStdin  sN     R':;	47LAz"**6A>?r    )rd   rf  r   )r!   r"   r#   r$   r%   re   rk   ro  r  r  r  r  r  r  r&   r'   r    r   rc  rc    s7    ?$B$4)	@	00&@r    rc  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!!!&&$/QVVBNNGMM266	7s,   ; 
*; 
8; 
BABBBr'   r   )r!   r"   r#   r$   r%   r  r&   r'   r    r   r  r     s    	8r    r  ) r%   r_  r/   r1   r   ri   ry  rb   pyflakes.checkerr   pyflakes.messagesr   pyflakes.reporterr   pyflakes.apir   r   r   r	   r
   pyflakes.test.harnessr   r   r   r   r)   rG   r_   r   r   rc  r  r'   r    r   <module>r     s     	 	 
    ! * &  3% %' ':N N.y" y"xT98 T9n`3 `3Fe@x e@P8 8r    