ó
¡¼™\c           @   s;  d  d l  m Z m Z m Z d  d l m Z m Z m Z m Z m	 Z	 d  d l
 m
 Z
 d  d l Z d  d l Z d  d l Z d  d l m Z i e d 6Z e e e e ƒ d e e ƒ ƒ Z e e ƒ sÉ t ‚ e e e e ƒ ƒ Z e e d ƒ Z e e d	 ƒ 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" d Z# e j$ d ƒ Z% e j$ d ƒ Z& e j$ d ƒ Z' e j$ d ƒ Z( e j$ d ƒ Z) e j$ d ƒ Z* e j$ d ƒ Z+ e j$ d ƒ Z, d „  Z- d  „  Z. e/ ƒ  d! d" „ Z0 e/ ƒ  d d# „ Z2 d$ „  Z3 d% „  Z4 d& „  Z5 d' „  Z6 d( „  Z7 d) „  Z8 d* „  Z9 d S(+   iÿÿÿÿ(   t   walkt   sept   pardir(   t   splitt   joint   abspatht   existst   isfile(   t   globN(   t   PY3R   i    t   bint   exampless/   File contains trailing whitespace: %s, line %s.s.   File contains an implicit import: %s, line %s.s2   File contains tabs instead of spaces: %s, line %s.s:   File contains carriage returns at end of line: %s, line %ss+   File contains string exception: %s, line %ss,   File contains generic exception: %s, line %ss:   File contains old-style raise statement: %s, line %s, "%s"s-   File does not end with a newline: %s, line %ss/   File ends with more than 1 newline: %s, line %ss6   Function should start with 'test_' or '_': %s, line %ss.   This is a duplicate test function: %s, line %ss3   File contains assignments to self/cls: %s, line %s.s&   File contains '.func is': %s, line %s.s(   ^\s*(>>> )?(\.\.\. )?from .* import .*\*s9   ^\s*(>>> )?(\.\.\. )?raise(\s+(\'|\")|\s*(\(\s*)+(\'|\"))s=   ^\s*(>>> )?(\.\.\. )?raise(\s+Exception|\s*(\(\s*)+Exception)s1   ^\s*(>>> )?(\.\.\. )?raise((\s*\(\s*)|\s+)\w+\s*,s$   ^def\s+(?!(_|test))[^(]*\(\s*\)\s*:$s   ^def\s+test_.*:$s   .*[/\\]test_.*\.py$s   \.\s*func\s+isc         C   s‡   t  |  ƒ t  |  j ƒ  ƒ } |  | | d !d k r@ |  |  } n6 |  | d } |  |  | t  | ƒ t  | j ƒ  ƒ  } | j ƒ  | k S(   s{   Returns True if there are tabs in the leading whitespace of a line,
    including the whitespace of docstring code samples.i   s   ...s   >>>(   s   ...s   >>>(   t   lent   lstript
   expandtabs(   t   st   nt   checkt   smore(    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   tab_in_leading4   s    (c            s¨  g  t  j |  ƒ j D] } t | t  j ƒ r | ^ q } g  } xd| D]\} xS| j D]H} t | t  j ƒ sr qT n  t d „  | j Dƒ ƒ r‘ qT n  | j d k r¦ qT n  | j	 j	 s¸ qT n  t
 rÔ | j	 j	 d j ‰  n | j	 j	 d j ‰  x² t  j | ƒ D]¡ } t | t  j ƒ r÷ x† | j D]x } t | t  j ƒ rP| j ˆ  k rP| j | ƒ qt | t  j ƒ rt ‡  f d †  | j Dƒ ƒ r| j | ƒ qqWq÷ q÷ WqT WqD W| S(   sœ   Returns a list of "bad" assignments: if there are instances
    of assigning to the first argument of the class method (except
    for staticmethod's).
    c         s   s0   |  ]& } t  | t j ƒ r | j d  k Vq d S(   t   staticmethodN(   t
   isinstancet   astt   Namet   id(   t   .0t   d(    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pys	   <genexpr>L   s   t   __new__i    c         3   s0   |  ]& } t  | t j ƒ r | j ˆ  k Vq d  S(   N(   R   R   R   R   (   R   t   q(   t	   first_arg(    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pys	   <genexpr>]   s    (   R   t   parset   bodyR   t   ClassDeft   FunctionDeft   anyt   decorator_listt   namet   argsR	   t   argR   R    t   Assignt   targetsR   t   appendt   Tuplet   elts(   R   R   t   tt   badt   ct   mt   a(    (   R   sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   find_self_assignments@   s2    7	!#s   *.pyc         C   sM   |  s
 d Sx< t  |  ƒ D]. \ } } } t t t | | ƒ ƒ | | ƒ q Wd S(   sÔ   
    Checks all files in the directory tree (with base_path as starting point)
    with the file_check function provided, skipping files that contain
    any of the strings in the set provided by exclusions.
    N(   R    t   check_filesR   R   (   t	   base_patht
   file_checkt
   exclusionst   patternt   roott   dirst   files(    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   check_directory_treed   s    c            sŒ   |  s
 d Sx{ |  D]s ‰  t  ˆ  ƒ s t ˆ  ƒ r7 q n  t ‡  f d †  | Dƒ ƒ rY q n  | d k sw t j | ˆ  ƒ r | ˆ  ƒ q q Wd S(   s—   
    Checks all files with the file_check function provided, skipping files
    that contain any of the strings in the set provided by exclusions.
    Nc         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   R   t   ex(   t   fname(    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pys	   <genexpr>z   s    (   R   R   R"   t   Nonet   ret   match(   R9   R4   R5   R6   (    (   R<   sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyR2   p   s    c             s5  ‡ f d †  }  ‡  f d †  ‰ g  d d d d g D] } t  t | ƒ ^ q1 } t d t d t d	 t d
 t d t g ƒ } t d t d t d t d t d t d t d t d t d t d t d t d t d t g ƒ ‰  t | |  ƒ t t |  t d d d g ƒ d ƒ t t |  | ƒ t t |  | ƒ d S(   s=  
    This test tests all files in sympy and checks that:
      o no lines contains a trailing whitespace
      o no lines end with 

      o no line uses tabs instead of spaces
      o that the file ends with a single newline
      o there are no general or string exceptions
      o there are no old style raise statements
      o name of arg-less test suite functions start with _ or test_
      o no duplicate function names that start with test_
      o no assignments to self variable in class methods
      o no lines contain ".func is" except in the test suite
    c            s¹   t  r4 t |  d d d ƒ } ˆ  |  | ƒ Wd  QXn t |  d ƒ  } ˆ  |  | ƒ Wd  QXt |  d ƒ  } | j ƒ  } Wd  QXt | ƒ } | rµ t sµ t t |  | d j f ƒ ‚ n  d  S(   Nt   rtt   encodingt   utf8i    (   R	   t   opent   readR1   t   Falset   AssertionErrort   message_self_assignmentst   lineno(   R<   t	   test_filet   sourcet   result(   t   test_this_file(    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   test   s    c            sN  d  } d } t ƒ  } x¶t | ƒ D]¨\ } } t j ˆ  ƒ rç t j | ƒ ro t so t t ˆ  | d f ƒ ‚ n  t	 j | ƒ rç | d 7} | j
 | d j d ƒ d j ƒ  ƒ t | ƒ | k rä t sá t t ˆ  | d f ƒ ‚ qä qç n  | j d ƒ s| j d ƒ r(t s(t t ˆ  | d f ƒ ‚ n  | j d ƒ rZt sZt t ˆ  | d f ƒ ‚ n  t | ƒ r‰t s‰t t ˆ  | d f ƒ ‚ n  t j | ƒ r»t s»t t ˆ  | d f ƒ ‚ n  t j | ƒ rít sít t ˆ  | d f ƒ ‚ n  t j | ƒ r>t t ‡  f d †  ˆ ƒ ƒ r>t s>t t ˆ  | d f ƒ ‚ n  t j | ƒ r€t j ˆ  ƒ r€t s€t t ˆ  | d f ƒ ‚ n  t j | ƒ } | d  k	 r" t sÊt t  ˆ  | d | j! d	 ƒ f ƒ ‚ q" q" W| d  k	 rJ| d
 k r| d k rt sGt t" ˆ  | d f ƒ ‚ qJ| j d
 ƒ sJt sGt t# ˆ  | d f ƒ ‚ qJn  d  S(   Ni    i   i   t   (s    
s   	
s   
c            s
   |  ˆ  k S(   N(    (   R;   (   R<   (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   <lambda>¶   t    i   s   
($   R=   t   sett	   enumeratet   test_file_reR?   t   test_suite_def_reRE   RF   t   message_test_suite_deft   test_ok_def_ret   addR   t   stripR   t   message_duplicate_testt   endswitht   message_spacet   message_carriageR   t   message_tabst   str_raise_ret   searcht   message_str_raiset   gen_raise_ret   message_gen_raiset   implicit_test_ret   listt   filtert   message_implicitt
   func_is_ret   message_func_ist   old_raise_ret   message_old_raiset   groupt   message_multi_eoft   message_eof(   R<   RI   t   linet   testst   test_sett   idxRK   (   t   import_exclude(   R<   sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyRL   ž   sH    	#
$)#######'#s	   isympy.pys   build.pys   setup.pys   setupegg.pysL   %(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevparser.pysK   %(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevlexer.pysN   %(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevlistener.pysH   %(sep)ssympy%(sep)sparsing%(sep)slatex%(sep)s_antlr%(sep)slatexparser.pysG   %(sep)ssympy%(sep)sparsing%(sep)slatex%(sep)s_antlr%(sep)slatexlexer.pys   %(sep)ssympy%(sep)s__init__.pys   %(sep)svector%(sep)s__init__.pys"   %(sep)smechanics%(sep)s__init__.pys    %(sep)squantum%(sep)s__init__.pys   %(sep)spolys%(sep)s__init__.pys,   %(sep)spolys%(sep)sdomains%(sep)s__init__.pys#   %(sep)sinteractive%(sep)ssession.pys   %(sep)sisympy.pys   %(sep)sbin%(sep)ssympy_time.pys$   %(sep)sbin%(sep)ssympy_time_cache.pys&   %(sep)sparsing%(sep)ssympy_tokenize.pys'   %(sep)splotting%(sep)spygletplot%(sep)ss)   %(sep)sbin%(sep)stest_external_imports.pyt   ~s   .pycs   .sht   *N(	   R   t   TOP_PATHRQ   t   sepdR2   R:   t   BIN_PATHt
   SYMPY_PATHt   EXAMPLES_PATH(   RM   t   filet   top_level_filest   exclude(    (   Rr   RL   sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt
   test_files€   s>    +""c         C   s   t  j d d ƒ d |  S(   Ni    i
   t    (   t   randomt   randint(   R.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   _with_spaceö   s    c          C   sÎ  d d d d d d d d g }  d d	 d
 d d g } d d d d d d d d d d d g } d d d d d d d d d d d d d d d d  d! d" d# d$ g } xƒ |  D]{ } t  j t | ƒ ƒ d  k sÐ t | ƒ ‚ t j t | ƒ ƒ d  k s÷ t | ƒ ‚ t j t | ƒ ƒ d  k s£ t | ƒ ‚ q£ Wx5 | D]- } t  j t | ƒ ƒ d  k	 s)t | ƒ ‚ q)Wx5 | D]- } t j t | ƒ ƒ d  k	 sat | ƒ ‚ qaWx5 | D]- } t j t | ƒ ƒ d  k	 s™t | ƒ ‚ q™Wd  S(%   Ns#   some text # raise Exception, 'text's2   raise ValueError('text') # raise Exception, 'text's   raise ValueError('text')s   raise ValueErrors   raise ValueError('text') #,sB   '"""This function will raise ValueError, except when it doesn't"""s   raise (ValueError('text')s   raise 'exception's   raise 'Exception's   raise "exception"s   raise "Exception"s   raise 'ValueError's1   raise Exception('text') # raise Exception, 'text's   raise Exception('text')s   raise Exceptions   raise Exception('text') #,s   raise Exception, 'text's1   raise Exception, 'text' # raise Exception('text')s1   raise Exception, 'text' # raise Exception, 'text's   >>> raise Exception, 'text's5   >>> raise Exception, 'text' # raise Exception('text')s5   >>> raise Exception, 'text' # raise Exception, 'text's   raise ValueError, 'text's2   raise ValueError, 'text' # raise Exception('text')s2   raise ValueError, 'text' # raise Exception, 'text's   >>> raise ValueError, 'text's6   >>> raise ValueError, 'text' # raise Exception('text')s6   >>> raise ValueError, 'text' # raise Exception, 'text's   raise(ValueError,s   raise (ValueError,s   raise( ValueError,s   raise ( ValueError,s   raise(ValueError ,s   raise (ValueError ,s   raise( ValueError ,s   raise ( ValueError ,(   R^   R_   R   R=   RF   Ra   Ri   (   t   candidates_okt   str_candidates_failt   gen_candidates_failt   old_candidates_failR.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt'   test_raise_statement_regular_expressionû   sl    				''+++c          C   s¼   d d d d d d d d d	 d
 d d d d g }  d d d d d d g } x5 |  D]- } t  j t | ƒ ƒ d  k sO t | ƒ ‚ qO Wx5 | D]- } t  j t | ƒ ƒ d  k	 s‡ t | ƒ ‚ q‡ Wd  S(   Ns   from sympy import somethings   >>> from sympy import somethings%   from sympy.somewhere import somethings)   >>> from sympy.somewhere import somethings   import sympys   >>> import sympys    import sympy.something.somethings   ... import sympys$   ... import sympy.something.somethings   ... from sympy import somethings)   ... from sympy.somewhere import somethings   >> from sympy import *s   # from sympy import *s   some text # from sympy import *s   from sympy import *s   >>> from sympy import *s   from sympy.somewhere import *s!   >>> from sympy.somewhere import *s   ... from sympy import *s!   ... from sympy.somewhere import *(   Rc   R_   R   R=   RF   (   R‚   t   candidates_failR.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt(   test_implicit_imports_regular_expression>  s0    		+c          C   sŒ   d d d d g }  d d d d g } x/ |  D]' } t  j | ƒ d  k s+ t | ƒ ‚ q+ Wx/ | D]' } t  j | ƒ d  k	 s] t | ƒ ‚ q] Wd  S(	   Ns       def foo():
s   def foo(arg):
s   def _foo():
s   def test_foo():
s   def foo():
s   def foo() :
s   def foo( ):
s   def  foo():
(   RT   R_   R=   RF   (   R‚   R‡   R.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   test_test_suite_defs]  s    		%c          C   s€   d d d g }  d d g } d } d „  } x& |  D] } | | ƒ | k s1 t ‚ q1 Wx& | D] } | | ƒ | k sZ t ‚ qZ Wd  S(	   Ns   def foo():
def foo():
s   def test():
def test_():
s   def test_():
def test__():
s   def test_():
def test_ ():
s   def test_1():
def  test_1():
R   c         S   s    d } t  ƒ  } xŠ t |  j ƒ  ƒ D]v \ } } t j | ƒ r" | d 7} | j | d j d ƒ d j ƒ  ƒ t | ƒ | k r˜ t	 t
 d | d f f Sq" q" Wd S(   Ni    i   i   RN   R   (   NR   (   RQ   RR   t
   splitlinesRV   R?   RW   R   RX   R   RE   RY   R=   (   Rz   Ro   Rp   Rq   Rn   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyR   {  s    	
$(   NR   (   R=   RF   (   R‚   R‡   t   okR   R.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   test_test_duplicate_defsp  s    			
c          C   s€   d d d d d g }  d d d d	 d
 g } x& |  D] } t  | ƒ g  k s1 t ‚ q1 Wx& | D] } t  | ƒ g  k sZ t ‚ qZ Wd  S(   Ns4   class A(object):
    def foo(self, arg): arg = self
s9   class A(object):
    def foo(self, arg): self.prop = arg
s?   class A(object):
    def foo(self, arg): obj, obj2 = arg, self
sC   class A(object):
    @classmethod
    def bar(cls, arg): arg = cls
s2   class A(object):
    def foo(var, arg): arg = var
s4   class A(object):
    def foo(self, arg): self = arg
s>   class A(object):
    def foo(self, arg): obj, self = arg, arg
sC   class A(object):
    def foo(self, arg):
        if arg: self = argsC   class A(object):
    @classmethod
    def foo(cls, arg): cls = arg
s2   class A(object):
    def foo(var, arg): var = arg
(   R1   RF   (   R‚   R‡   R.   (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   test_find_self_assignments‹  s    		(:   t   osR    R   R   t   os.pathR   R   R   R   R   R   R>   R   R   t   sympy.core.compatibilityR	   Rv   t   __file__Rx   RF   Ru   Rw   Ry   R[   Rf   R]   R\   R`   Rb   Rj   Rm   Rl   RU   RY   RG   Rh   t   compileRc   R^   Ra   Ri   RT   RV   RS   Rg   R   R1   RQ   R:   R=   R2   R}   R   R†   Rˆ   R‰   RŒ   R   (    (    (    sF   lib/python2.7/site-packages/sympy/utilities/tests/test_code_quality.pyt   <module>   s\   ("				$	v		C			