
    gg                     @   d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZmZ ddlmZmZ d Z G d	 d
      Z G d d      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)z)
Tests for L{pyflakes.scripts.pyflakes}.
    N)PYPY)UnusedImport)Reporter)maincheck	checkPathcheckRecursiveiterSourceCode)TestCaseskipIfc                     t         j                  | c}t         _        	  ||i ||t         _        S # |t         _        w xY w)z?
    Call C{f} with C{sys.stderr} redirected to C{stderr}.
    )sysstderr)r   fargskwargsouters        Y/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/pyflakes/test/test_api.pywithStderrTor      s7     ::vUCJ$!&!
U
s   1 >c                       e Zd ZdZddZy)Nodez
    Mock an AST node.
    c                      || _         || _        y N)lineno
col_offset)selfr   r   s      r   __init__zNode.__init__)   s    $    N)r   )__name__
__module____qualname____doc__r    r   r   r   r   %   s    %r   r   c                   "    e Zd ZdZd Zd Zd Zy)SysStreamCapturingzContext manager capturing sys.stdin, sys.stdout and sys.stderr.

    The file handles are replaced with a StringIO object.
    c                 `    t        j                  |xs dt        j                        | _        y )N newline)ioStringIOoslinesep_stdin)r   stdins     r   r   zSysStreamCapturing.__init__4   s    kk%+2rzzBr   c                 ~   t         j                  | _        t         j                  | _        t         j
                  | _        | j                  t         _        t        j                  t        j                        xt         _        | _        t        j                  t        j                        xt         _        | _        | S )Nr(   )r   r/   _orig_stdinstdout_orig_stdoutr   _orig_stderrr.   r*   r+   r,   r-   _stdout_stringio_stderr_stringior   s    r   	__enter__zSysStreamCapturing.__enter__7   sn    99JJJJKK	-/[[-LL
T*-/[[-LL
T*r   c                     | j                   j                         | _        | j                  j                         | _        | j
                  t        _        | j                  t        _	        | j                  t        _        y r   )r5   getvalueoutputr6   errorr1   r   r/   r3   r2   r4   r   )r   r   s     r   __exit__zSysStreamCapturing.__exit__B   sU    ++446**335
$$	&&
&&
r   N)r   r    r!   r"   r   r8   r=   r#   r   r   r%   r%   .   s    
C	'r   r%   c                   (    e Zd ZdZd Zd Zd Zd Zy)LoggingReporterzK
    Implementation of Reporter that just appends any error to a list.
    c                     || _         y)zh
        Construct a C{LoggingReporter}.

        @param log: A list to append log messages to.
        N)log)r   rA   s     r   r   zLoggingReporter.__init__P   s     r   c                 P    | j                   j                  dt        |      f       y )Nflake)rA   appendstr)r   messages     r   rC   zLoggingReporter.flakeX   s    #g,/0r   c                 @    | j                   j                  d||f       y )NunexpectedErrorrA   rD   )r   filenamerF   s      r   rH   zLoggingReporter.unexpectedError[   s    *Hg>?r   c                 F    | j                   j                  d|||||f       y )NsyntaxErrorrI   )r   rJ   msgr   offsetlines         r   rL   zLoggingReporter.syntaxError^   s    #vvtLMr   N)r   r    r!   r"   r   rC   rH   rL   r#   r   r   r?   r?   K   s    1@Nr   r?   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)TestIterSourceCodez&
    Tests for L{iterSourceCode}.
    c                 6    t        j                         | _        y r   )tempfilemkdtemptempdirr7   s    r   setUpzTestIterSourceCode.setUpg   s    '')r   c                 B    t        j                  | j                         y r   shutilrmtreerU   r7   s    r   tearDownzTestIterSourceCode.tearDownj       dll#r   c                     |sJ t        j                  j                  | j                  g| }t	        |d      j                          |S )Na)r,   pathjoinrU   openclose)r   partsfpaths      r   makeEmptyFilez TestIterSourceCode.makeEmptyFilem   s<    uT\\2E2UC r   c                 b    | j                  t        t        | j                  g            g        y)zB
        There are no Python files in an empty directory.
        N)assertEquallistr
   rU   r7   s    r   test_emptyDirectoryz&TestIterSourceCode.test_emptyDirectorys   s$     	ndll^<=rBr   c                     | j                  d      }| j                  t        t        | j                  g            |g       y)zd
        If the directory contains one Python file, C{iterSourceCode} will find
        it.
        foo.pyNre   rg   rh   r
   rU   )r   	childpaths     r   test_singleFilez"TestIterSourceCode.test_singleFiley   s6    
 &&x0	ndll^<=	{Kr   c                     | j                  d       | j                  t        t        | j                  g            g        y)zJ
        Files that are not Python source files are not included.
        zfoo.pycNrl   r7   s    r   test_onlyPythonSourcez(TestIterSourceCode.test_onlyPythonSource   s2     	9%ndll^<=rBr   c                    t        j                  t         j                  j                  | j                  d             | j                  dd      }| j                  dd       t        j                  t         j                  j                  | j                  d             | j                  dd      }| j                  d      }| j                  t        t        | j                  g            t        |||g             y)zk
        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)	r,   mkdirr_   r`   rU   re   rg   sortedr
   )r   apathbpathcpaths       r   test_recursesz TestIterSourceCode.test_recurses   s    
 	dllE23""5&15'*
dllE23""5&1""6*>4<<.12E5%()	+r   c                 j   t         j                  j                  | j                  d      }t	        |d      5 }|j                  d       ddd       | j                  d       t	        t         j                  j                  | j                  d      d      5 }|j                  d       ddd       t         j                  j                  | j                  d      }t	        |d      5 }|j                  d	       ddd       t         j                  j                  | j                  d
      }t	        |d      5 }|j                  d       ddd       t         j                  j                  | j                  d      }t	        |d      5 }|j                  d       ddd       t         j                  j                  | j                  d      }t	        |d      5 }|j                  d       ddd       t         j                  j                  | j                  d      }t	        |d      5 }|j                  d       ddd       t         j                  j                  | j                  d      }t	        |d      5 }|j                  d       ddd       | j                  t        t        | j                  g            t        ||||||g             y# 1 sw Y   xY w# 1 sw Y   6xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   mxY w# 1 sw Y   *xY w# 1 sw Y   xY w# 1 sw Y   xY w)zd
        Find Python files that don't end with `.py`, but contain a Python
        shebang.
        r^   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
)
r,   r_   r`   rU   ra   writere   rg   rw   r
   )	r   pythonfdpython3pythonwpython3argspython3d	python38mnotfirsts	            r   test_shebangzTestIterSourceCode.test_shebang   s   
 dllC0&# 	0"HH./	0 	3"'',,t||S137 	'2HH%&	' '',,t||S1'3 	12HH/0	1 '',,t||S1'3 	12HH/0	1 ggll4<<5+s# 	0rHH./	0 77<<c2(C  	4BHH23	4 GGLLs3	)S! 	5RHH34	5 77<<c2(C  	7BHH56	7 	>4<<.12+x 	C	0 	0
	' 	'	1 	1	1 	1	0 	0	4 	4	5 	5
	7 	7s_   KK&K)6K6LL&L6L)KK&)K36L LLL&)L2c                    t         j                  j                  | j                  d      }t         j                  j                  | j                  d      }t        j                  |       | j                  dd      }t        j                  |       | j                  dd      }| j                  t        t        ||g            t        ||g             y)zr
        L{iterSourceCode} can be given multiple directories.  It will recurse
        into each of them.
        rr   rt   rs   ru   N)	r,   r_   r`   rU   rv   re   rg   rw   r
   )r   foopathbarpathrx   ry   s        r   test_multipleDirectoriesz+TestIterSourceCode.test_multipleDirectories   s    
 '',,t||U3'',,t||U3
""5&1
""5&1>7G"456E5>"	$r   c                 r    | j                  d      }| j                  t        t        |g            |g       y)z
        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)re   rg   rh   r
   )r   epaths     r   test_explicitFilesz%TestIterSourceCode.test_explicitFiles   s5    
 ""6*neW56	"r   N)r   r    r!   r"   rV   r[   re   ri   rn   rp   r{   r   r   r   r#   r   r   rQ   rQ   b   s=    *$CLC+,\$"r   rQ   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestReporterz 
    Tests for L{Reporter}.
    c                     t        j                         }t        d|      }|j                  ddddd       | j	                  d|j                                y)a  
        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.
        Nrk   	a problem      bad line of sourcez2foo.py:3:8: a problem
bad line of source
       ^
r*   r+   r   rL   rg   r:   r   errreporters      r   test_syntaxErrorzTestReporter.test_syntaxError   sP     kkmD#&X{Aq:NO LLN		r   c                     t        j                         }t        d|      }|j                  ddddd       | j	                  d|j                                y)zy
        C{syntaxError} doesn't include a caret pointing to the error if
        C{offset} is passed as C{None}.
        Nrk   r   r   r   z'foo.py:3: a problem
bad line of source
r   r   s      r   test_syntaxErrorNoOffsetz%TestReporter.test_syntaxErrorNoOffset   sP    
 kkmD#&X{At1	3$LLN	r   c                     t        j                         }t        d|      }|j                  ddddd       | j	                  d|j                                y)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_syntaxErrorNoTextz#TestReporter.test_syntaxErrorNoText  sH     kkmD#&YQ4@4s||~Fr   c           	         t        j                         }ddg}t        d|      }|j                  dddt	        |d         dz   d	j                  |             | j                  d
|d   z   d	z   dz   dz   |j                                y)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 sourceNrk   r   r   r      
zfoo.py:3:25: a problem
z                        ^
)r*   r+   r   rL   lenr`   rg   r:   )r   r   linesr   s       r   test_multiLineSyntaxErrorz&TestReporter.test_multiLineSyntaxError  s     kkm &
 D#&X{As58}q7H!YYu-	/'2Y LLN		r   c                     t        j                         }t        d|      }|j                  dd       | j	                  d|j                                y)zO
        C{unexpectedError} reports an error processing a source file.
        Nz	source.pyzerror messagezsource.py: error message
)r*   r+   r   rH   rg   r:   r   s      r   test_unexpectedErrorz!TestReporter.test_unexpectedError   sB     kkmD#&  o>5s||~Fr   c                     t        j                         }t        |d      }t        dt	        d      d      }|j                  |       | j                  |j                         | d       y)z
        C{flake} reports a code warning from Pyflakes.  It is exactly the
        str() of a L{pyflakes.messages.Message}.
        Nrk   *   rt   r   )r*   r+   r   r   r   rC   rg   r:   )r   outr   rF   s       r   
test_flakezTestReporter.test_flake)  sU    
 kkmC&xb59wG9B8r   N)
r   r    r!   r"   r   r   r   r   r   r   r#   r   r   r   r      s'     	G(G	9r   r   c                       e Zd ZdZej
                  d        Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Z eej(                  dk(  d      d        Zd Zd Zd Zd Zd Zd Zd Zy)
CheckTestszL
    Tests for L{check} and L{checkPath} which check a file for flakes.
    c              #   T  K   t        j                         \  }}	 t        j                  |d      5 }t	        |d      s|j                  d      }|j                  |       ddd       | t        j                  |       y# 1 sw Y   #xY w# t        j                  |       w xY ww)zV
        Make a temporary file containing C{content} and return a path to it.
        wbdecodeasciiN)rS   mkstempr,   fdopenhasattrencoder   remove)r   contentr   namer   s        r   makeTempFilezCheckTests.makeTempFile:  s     
 ##%D	2t$ !w1%nnW5G ! JIIdO! ! IIdOs3   B(B /B B ,B(BB B%%B(c                     t        j                         }t        |t        |      }| j	                  ||j                         ft        |      dj                  |      f       y)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*   r+   r   r   rg   r:   r   r`   )r   r_   	errorListr   counts        r   assertHasErrorszCheckTests.assertHasErrorsI  sN     kkmS)T2CLLN#c)nbggi6H%I	Kr   c                 <    g }t        |      }t        ||      }||fS )a  
        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.
        )r?   r   )r   r_   rA   r   r   s        r   	getErrorszCheckTests.getErrorsU  s)     "3'$)czr   c                 P    ddl m} | j                  |j                  t               y )Nr   )pyflakes)pyflakes.scriptsr   assertIsr   )r   script_pyflakess     r   test_legacyScriptzCheckTests.test_legacyScriptc  s    @o//;r   c                 t    | j                  d      5 }| j                  |g        ddd       y# 1 sw Y   yxY w)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_missingTrailingNewlinez&CheckTests.test_missingTrailingNewlineg  s:     78 	,E  +	, 	, 	,   .7c                 v    | j                  d      \  }}| j                  |d       | j                  |dg       y)z:
        L{checkPath} handles non-existing files.
        extremo   )rH   r   zNo such file or directoryN)r   rg   )r   r   errorss      r   test_checkPathNonExistingz$CheckTests.test_checkPathNonExistingp  s>     y1v"HI	Kr   c                    d}d }	  ||       | j                          | j                  |      5 }t        rd}nt        j                  dk\  rd}nd	}t        st        j                  dk\  rd
}nd}| j                  |d|||d|dz
  z  fz  g       ddd       y# t        $ rP}t        s@t        j                  dk  r-| j                  |j                  j                  d      dkD         Y d}~d}~ww xY w# 1 sw Y   yxY w)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                     t        |        y r   )exec)sources    r   evaluatez6CheckTests.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   
sourcePathrF   columns          r   test_multilineSyntaxErrorz$CheckTests.test_multilineSyntaxErrorz  s   			V
 IIKv& 	:*Y!!W,Z*s''72   67C6A:$67	8 9:	: 	:  	8C,,w6T 2Q 67	8	: 	:s$   B A C5	C2"AC--C25C>c                 ,   | j                  d      5 }t        rd}nt        j                  dk\  rd}nd}t        st        j                  dk\  rd}nd}d|d	z
  z  }d
j	                  ||||      }| j                  ||g       ddd       y# 1 sw Y   yxY w)
        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   rM   r   spacesexpecteds         r   test_eofSyntaxErrorzCheckTests.test_eofSyntaxError  s    
 z* 	9j3!!W,,4s''72FQJ'F5<<FCH   hZ8%	9 	9 	9s   A/B

Bc                 |    | j                  d      5 }| j                  || dg       ddd       y# 1 sw Y   yxY w)r   zif True:
	foo =z$:2:7: invalid syntax
	foo =
	     ^
Nr   r   r   s     r   test_eofSyntaxErrorWithTabz%CheckTests.test_eofSyntaxErrorWithTab  sO    
 23 	z    	 	 	s   2;c                 |   d}| j                  |      5 }t        j                  dk\  rd}nd}t        rt        j                  dk\  rd}n7t        rd}n.t        j                  dk\  rd}nt        j                  dk\  rd	}nd
}d|dz
  z  dz   }| j	                  || d| d| d| g       ddd       y# 1 sw Y   yxY w)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   rM   r   	last_lines         r   (test_nonDefaultFollowsDefaultSyntaxErrorz3CheckTests.test_nonDefaultFollowsDefaultSyntaxError  s     v& 	*7*TE((F2!!W,!!V+vz*U2I  Cxr# 
 #	 	 	s   BB22B;c           
         d}| j                  |      5 }t        j                  dk\  rd}nt        sd}nd}d|dz
  z  dz   }d	|z  }d
}| j	                  |dj                  ||||      g       ddd       y# 1 sw Y   yxY w)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   	columnstrrF   s          r   &test_nonKeywordAfterKeywordSyntaxErrorz1CheckTests.test_nonKeywordAfterKeywordSyntaxError  s     v& 	:*6)vz*U2IIDG   fZGY79:	: 	: 	:s   AA66A?c                 .   | j                  d      5 }d}t        rt        j                  dk\  rd}n*t        rd}n!dt        j                  cxk  rdk  rn nd}nd}dd	|dz
  z  z  }d
||||fz  }| j	                  ||g       ddd       y# 1 sw Y   yxY w)zI
        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_invalidEscapezCheckTests.test_invalidEscape  s    
 / 	.:L((F23++5g53&1*#56I 
V\95	6N   ^,.'	. 	. 	.s   A0BBwin32zunsupported on Windowsc                 D   t        j                         dk(  r| j                  d       | j                  d      5 }t        j                  |d       | j                  |      \  }}| j                  |d       | j                  |d|dfg       ddd       y# 1 sw Y   yxY w)za
        If the source file is not readable, this is reported on standard
        error.
        r   z8root user can access all files regardless of permissionsr'   r   rH   zPermission deniedN)r,   getuidskipTestr   chmodr   rg   r   r   r   r   s       r   test_permissionDeniedz CheckTests.test_permissionDenied,  s     99;!MM ( )r" 	HjHHZ# NN:6ME6UA&#Z1DEFH		H 	H 	Hs   ABBc                     | j                  d      5 }| j                  |      \  }}| j                  |d       | j                  |dt        t	        |t        d      d            fg       ddd       y# 1 sw Y   yxY w)zc
        If the source file has a pyflakes warning, this is reported as a
        'flake'.
        z
import foor   rC   rr   N)r   r   rg   rE   r   r   r  s       r   test_pyflakesWarningzCheckTests.test_pyflakesWarning=  s}    
 |, 	T
 NN:6ME6UA&'3|JQ'O#PQRT	T 	T 	Ts   AA44A=c                     t        d      }d|z  j                  d      }| j                  |      5 }| j                  |g        ddd       y# 1 sw Y   yxY w)zU
        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_encodedFileUTF8zCheckTests.test_encodedFileUTF8H  sc     f+  vg 	 v& 	1*  R0	1 	1 	1s   AAc                 t    | j                  d      5 }| j                  |g        ddd       y# 1 sw Y   yxY w)zW
        Source files with Windows CR LF line endings are parsed successfully.
        zx = 42
Nr   r   s     r   test_CRLFLineEndingszCheckTests.test_CRLFLineEndingsT  s9     |, 	1
  R0	1 	1 	1r   c                     t        d      }d|z  j                  d      }| j                  |      5 }| j                  || dg       ddd       y# 1 sw Y   yxY w)n
        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_misencodedFileUTF8z"CheckTests.test_misencodedFileUTF8[  sw    
 f+  vg 	 v& 	y*  <uvwy	y 	y 	ys   AAc                     t        d      }d|z  j                  d      }| j                  |      5 }t        j                  dk  r| d}n| d}| j                  ||g       ddd       y# 1 sw Y   yxY w)r  r  r  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_misencodedFileUTF16z#CheckTests.test_misencodedFileUTF16j  s    
 f+  vh 	 v& 	9**,(\)DE(\)[\  hZ8	9 	9 	9s   2A,,A5c                 \   t        j                         }	 t        j                  t        j                  j                  |d             t        j                  j                  |dd      }t        |d      5 }|j                  d       ddd       t        j                  j                  |d      }t        |d      5 }|j                  d       ddd       g }t        |      }t        |g|      }| j                  |d       | j                  t        |      t        d	t        t        |t        d
      d            fd	t        t        |t        d
      d            fg             t        j                   |       y# 1 sw Y   xY w# 1 sw Y   xY w# t        j                   |       w xY w)zv
        L{checkRecursive} descends into each directory, finding Python files
        and reporting problems.
        rr   zbar.pyr   s   import baz
Nzbaz.pys   import contraband   rC   r   baz
contraband)rS   rT   r,   rv   r_   r`   ra   r   r?   r	   rg   rw   rE   r   r   rY   rZ   )r   rU   file1r   file2rA   r   warningss           r   test_checkRecursivezCheckTests.test_checkRecursive|  s]   
 ""$	#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 6E<4F <FBF <FF FF F+c                 ,   d}t        j                         }t        |t        |d      }| j	                  |d       |j                         j                  d      dd }t        j                  dk\  rg d}nt        rg d	}nd
g}| j	                  ||       y)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*   r+   r   r   rg   r:   splitr   r   r   )r   r   r   r   errlinesexpected_errors         r   test_stdinReportsErrorsz"CheckTests.test_stdinReportsErrors  s     BkkmS%;"<<>''-cr2v%N
 N JN 	>2r   N)r   r    r!   r"   
contextlibcontextmanagerr   r   r   r   r   r   r   r   r   r   r   r  r   r   platformr  r  r  r  r  r   r(  r/  r#   r   r   r   r   5  s      
K<,K/:b92!F:8.6 CLLG#%=>H ?H 	T
11y9$#43r   r   c                   H    e Zd ZdZd Zd Zd ZddZd Zd Z	d	 Z
d
 Zd Zy)IntegrationTestszF
    Tests of the pyflakes script that actually spawn the script.
    c                     t        j                         | _        t        j                  j                  | j                  d      | _        y )Ntemp)rS   rT   rU   r,   r_   r`   tempfilepathr7   s    r   rV   zIntegrationTests.setUp  s-    '')GGLLv>r   c                 B    t        j                  | j                         y r   rX   r7   s    r   r[   zIntegrationTests.tearDown  r\   r   c                     ddl }t        j                  j                  |j                        }t        j                  j                  |ddd      S )z9
        Return the path to the pyflakes binary.
        r   Nz..binr   )r   r,   r_   dirname__file__r`   )r   r   package_dirs      r   getPyflakesBinaryz"IntegrationTests.getPyflakesBinary  s8     	ggooh&7&78ww||KujAAr   Nc                    t        t        j                        }t        j                  j	                  t
        j                        |d<   t
        j                  | j                         g}|j                  |       |rht        j                  ||t        j                  t        j                  t        j                        }|j                  |j                  d            \  }}nHt        j                  ||t        j                  t        j                        }|j                         \  }}|j                         }|j!                  d      }|j!                  d      }|||fS )a	  
        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)envr/   r2   r   r   )rA  r2   r   r  )dictr,   environpathsepr`   r   r_   
executabler>  extend
subprocessPopenPIPEcommunicater   waitr   )	r   pathsr/   rA  commandpr2   r   rvs	            r   runPyflakeszIntegrationTests.runPyflakes  s     2::JJOOCHH5L>>4#9#9#;<u  c(2
QA }}U\\'-BCVV  c(2
QA }}VVVVXw'w'##r   c                     t        | j                  d      j                          | j                  | j                  g      }| j	                  |d       y)z
        When a Python source file is all good, the return code is zero and no
        messages are printed to either stdout or stderr.
        r^   )r'   r'   r   N)ra   r7  rb   rP  rg   )r   ds     r   test_goodFilezIntegrationTests.test_goodFile  sF    
 	T$**,d//01K(r   c                 B   t        | j                  d      5 }|j                  d       ddd       | j                  | j                  g      }t	        | j                  t        d      d      }| j                  || t        j                   ddf       y# 1 sw Y   mxY w)z
        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   r$  r'   )	ra   r7  r   rP  r   r   rg   r,   r-   )r   r   rR  r   s       r   test_fileWithFlakesz$IntegrationTests.test_fileWithFlakes  s    
 $##T* 	-bHH+,	-d//01 1 147LIz"**6A>?		- 	-s   BBc                     | j                  | j                  g      }dj                  | j                  t        j                        }| j                  |d|df       y)
        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)rP  r7  r   r,   r-   rg   )r   rR  	error_msgs      r   test_errors_iozIntegrationTests.test_errors_io  sT     d//015<<T=N=N=?ZZI	RA./r   c                 2   t        | j                  d      5 }|j                  d       ddd       | j                  | j                  g      }dj	                  | j                  t
        j                        }| j                  |d|df       y# 1 sw Y   exY w)rW  r   s   importNz-{0}:1:7: invalid syntax{1}import{1}      ^{1}r'   r   )ra   r7  r   rP  r   r,   r-   rg   )r   r   rR  rX  s       r   test_errors_syntaxz#IntegrationTests.test_errors_syntax   s     $##T* 	 bHHY	 d//01CJJrzz+	RA./	  	 s   BBc                     | j                  g d      }t        dt        d      d      }| j                  || t        j
                   ddf       y)zU
        If no arguments are passed to C{pyflakes} then it reads from stdin.
        zimport contraband)r/   r   r   r$  r'   N)rP  r   r   rg   r,   r-   )r   rR  r   s      r   test_readFromStdinz#IntegrationTests.test_readFromStdin  sP     R':;	47LAz"**6A>?r   r   )r   r    r!   r"   rV   r[   r>  rP  rS  rU  rY  r[  r]  r#   r   r   r4  r4    s7    ?$B$4)	@	00@r   r4  c                       e Zd ZdZddZy)TestMainz.
    Tests of the pyflakes main function.
    Nc                 :   	 t        |      5 }t        |       d d d        t        d      # 1 sw Y   xY w# t        $ rX}| j	                  |j
                  t               t        |j
                        }j                  |j                  |fcY d }~S d }~ww xY w)N)r   zSystemExit not raised)
r%   r   RuntimeError
SystemExitassertIsInstancecodeboolintr;   r<   )r   rL  r/   capturer   rO  s         r   rP  zTestMain.runPyflakes  s    	8#E* !g% ! 677! ! 	7!!!&&$/QVVBNNGMM266	7s,   9 -9 69 	BABBBr   )r   r    r!   r"   rP  r#   r   r   r_  r_    s    	8r   r_  ) r"   r0  r*   r,   r   rY   rG  rS   pyflakes.checkerr   pyflakes.messagesr   pyflakes.reporterr   pyflakes.apir   r   r   r	   r
   pyflakes.test.harnessr   r   r   r   r%   r?   rQ   r   r   r4  r_  r#   r   r   <module>rm     s     	 	 
    ! * &  3% %' ':N N.y" y"xT98 T9n|3 |3~_@x _@D8 8r   