U
    ZÊ¹jK  ã                   @   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 d dlmZ deiZ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%dZ&e 'd¡Z(e 'd¡Z)e 'd¡Z*e 'd¡Z+e 'd¡Z,e 'd¡Z-e 'd¡Z.e 'd¡Z/d d!„ Z0d"d#„ Z1e2ƒ d$fd%d&„Z3e2ƒ dfd'd(„Z4G d)d*„ d*ej5ƒZ6e6ƒ Z7d+d,„ Z8d-d.„ Z9d/d0„ Z:d1d2„ Z;d3d4„ Z<d5d6„ Z=d7d8„ Z>d9d:„ Z?d;d<„ Z@dS )=é    )ÚwalkÚsepÚpardir)ÚsplitÚjoinÚabspathÚexistsÚisfile)ÚglobN)Úraises©Ú_test_this_file_encodingr   ÚbinZexamplesz/File contains trailing whitespace: %s, line %s.z.File contains an implicit import: %s, line %s.z2File contains tabs instead of spaces: %s, line %s.z:File contains carriage returns at end of line: %s, line %sz+File contains string exception: %s, line %sz,File contains generic exception: %s, line %sz:File contains old-style raise statement: %s, line %s, "%s"z-File does not end with a newline: %s, line %sz/File ends with more than 1 newline: %s, line %sz6Function should start with 'test_' or '_': %s, line %sz.This is a duplicate test function: %s, line %sz3File contains assignments to self/cls: %s, line %s.z&File contains '.func is': %s, line %s.z+File contains bare expression: %s, line %s.z(^\s*(>>> )?(\.\.\. )?from .* import .*\*z9^\s*(>>> )?(\.\.\. )?raise(\s+(\'|\")|\s*(\(\s*)+(\'|\"))z=^\s*(>>> )?(\.\.\. )?raise(\s+Exception|\s*(\(\s*)+Exception)z1^\s*(>>> )?(\.\.\. )?raise((\s*\(\s*)|\s+)\w+\s*,z$^def\s+(?!(_|test))[^(]*\(\s*\)\s*:$z^def\s+test_.*:$z.*[/\\]test_.*\.py$z\.\s*func\s+isc                 C   s|   t | ƒt |  ¡ ƒ }| ||d … dkr6| d|… }n8| |d d… }| d|… |dt |ƒt | ¡ ƒ …  }| ¡ |k S )z{Returns True if there are tabs in the leading whitespace of a line,
    including the whitespace of docstring code samples.é   )z...z>>>N)ÚlenÚlstripÚ
expandtabs)ÚsÚnÚcheckZsmore© r   úd/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/testing/tests/test_code_quality.pyÚtab_in_leading7   s    (r   c                    sô   dd„ t  | ¡jD ƒ}g }|D ]Ð}|jD ]Ä}t|t jƒs:q(tdd„ |jD ƒƒrPq(|jdkr\q(|jjsfq(|jjd j	‰ t  
|¡D ]l}t|t jƒr~|jD ]T}t|t jƒrº|jˆ krº| |¡ q”t|t jƒr”t‡ fdd„|jD ƒƒr”| |¡ q”q~q(q|S )zœ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   s   g | ]}t |tjƒr|‘qS r   )Ú
isinstanceÚastÚClassDef)Ú.0r   r   r   r   Ú
<listcomp>H   s      z)find_self_assignments.<locals>.<listcomp>c                 s   s$   | ]}t |tjƒr|jd kV  qdS )ÚstaticmethodN©r   r   ÚNameÚid)r   Údr   r   r   Ú	<genexpr>O   s    ÿz(find_self_assignments.<locals>.<genexpr>Ú__new__r   c                 3   s$   | ]}t |tjƒr|jˆ kV  qd S ©Nr   )r   Úq©Z	first_argr   r   r#   ^   s    ÿ)r   ÚparseÚbodyr   ÚFunctionDefÚanyZdecorator_listÚnameÚargsÚargr   ÚAssignÚtargetsr    r!   ÚappendÚTupleÚelts)r   ÚtÚbadÚcr   ÚmÚar   r'   r   Úfind_self_assignmentsC   s2    
ÿ

ÿr9   z*.pyc                 C   s6   | sdS t | ƒD ] \}}}ttt||ƒƒ||ƒ qdS )zÔ
    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   Úcheck_filesr
   r   )Ú	base_pathÚ
file_checkÚ
exclusionsÚpatternÚrootÚdirsÚfilesr   r   r   Úcheck_directory_treee   s    rB   c                    s\   | sdS | D ]J‰ t ˆ ƒrtˆ ƒs"qt‡ fdd„|D ƒƒr:q|dksNt |ˆ ¡r|ˆ ƒ qdS )z—
    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 r%   r   )r   Úex©Úfnamer   r   r#   {   s     zcheck_files.<locals>.<genexpr>)r   r	   r+   ÚreÚmatch)rA   r<   r=   r>   r   rD   r   r:   q   s    r:   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú_VisitaÅ  return the line number corresponding to the
    line on which a bare expression appears if it is a binary op
    or a comparison that is not in a with block.

    EXAMPLES
    ========

    >>> import ast
    >>> class _Visit(ast.NodeVisitor):
    ...     def visit_Expr(self, node):
    ...         if isinstance(node.value, (ast.BinOp, ast.Compare)):
    ...             print(node.lineno)
    ...     def visit_With(self, node):
    ...         pass  # no checking there
    ...
    >>> code='''x = 1    # line 1
    ... for i in range(3):
    ...     x == 2       # <-- 3
    ... if x == 2:
    ...     x == 3       # <-- 5
    ...     x + 1        # <-- 6
    ...     x = 1
    ...     if x == 1:
    ...         print(1)
    ... while x != 1:
    ...     x == 1       # <-- 11
    ... with raises(TypeError):
    ...     c == 1
    ...     raise TypeError
    ... assert x == 1
    ... '''
    >>> _Visit().visit(ast.parse(code))
    3
    5
    6
    11
    c                 C   s.   t |jtjtjfƒr*d s*ttd|jf ƒ‚d S )NÚ )r   Úvaluer   ÚBinOpÚCompareÚAssertionErrorÚmessage_bare_exprÚlineno©ÚselfÚnoder   r   r   Ú
visit_Expr§   s    z_Visit.visit_Exprc                 C   s   d S r%   r   rP   r   r   r   Ú
visit_Withª   s    z_Visit.visit_WithN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rS   rT   r   r   r   r   rH   �   s   %rH   c              
   C   sŒ   t  | ¡}zt |¡ W nn tk
r† } zP|js4t‚|jd }| t dd¡d ¡sXt‚t	| 
dd¡d  d¡ƒ W Y ¢S d}~X Y nX dS )z]return None or else 0-based line number of code on which
    a bare expression appeared.
    r   ú:é   ú Ú.N)r   r(   ÚBareExprÚvisitrM   r-   Ú
startswithrN   r   ÚintÚrsplitÚrstrip)ÚcodeÚtreeÚmsgr   r   r   Úline_with_bare_expr±   s    


rf   c                     sú   ‡fdd„} ‡ fdd„‰dd„ dD ƒ}dt  d	t  d
t  dt  dt  h}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  dt  dt  dt  dt  dt  dt  h‰ t|| ƒ tt| d d!d"d#hd$ƒ tt| |ƒ tt| |ƒ d%S )&a€  
    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
      o there is no do-nothing expression like `a == b` or `x + 1`
    c              	      sH   t | dd��}ˆ | |ƒ W 5 Q R X t | dd��}t| |ƒ W 5 Q R X d S )NÚutf8)Úencoding)Úopenr   )rE   Ú	test_file)Útest_this_filer   r   ÚtestÏ   s    ztest_files.<locals>.testc           	         sÒ  d }|  ¡ }| d¡ tˆ kr"ˆ nˆ  td¡d }| d¡rDt|ƒ}|d k	rddsdttˆ |d f ƒ‚d }d}tƒ }t	|ƒD �]ð\}}t
 ˆ ¡�rt |¡r²ds²ttˆ |d f ƒ‚t |¡�r|d7 }| |dd …  d¡d  ¡ ¡ t|ƒ|k�rd�sttˆ |d f ƒ‚| d¡�r4d�s4ttˆ |d f ƒ‚| d	¡�rZd�sZttˆ |d f ƒ‚t|ƒ�r~d�s~ttˆ |d f ƒ‚t |¡�r¤d�s¤ttˆ |d f ƒ‚t |¡�rÊd�sÊttˆ |d f ƒ‚t |¡�rtt ‡ fd
d„ˆƒƒ�sd�stt!ˆ |d f ƒ‚t" |¡�r:t
 ˆ ¡�s:d�s:tt#ˆ |d f ƒ‚t$ |¡}|d k	rzdsztt%ˆ |d | &d¡f ƒ‚qz|d k	�rÎ|dk�r¨|dk�r¨d�sÎtt'ˆ |d f ƒ‚n&| d¡�sÎd�sÎtt(ˆ |d f ƒ‚d S )Nr   rZ   éÿÿÿÿZtest_Fr   ú()z 
z	
z
c                    s   | ˆ kS r%   r   )rC   rD   r   r   Ú<lambda>ö   ó    z4test_files.<locals>.test_this_file.<locals>.<lambda>é   Ú
))ÚreadÚseekr   ra   r_   rf   rM   rN   ÚsetÚ	enumerateÚtest_file_rerG   Útest_suite_def_reÚmessage_test_suite_defÚtest_ok_def_reÚaddr   Ústripr   Úmessage_duplicate_testÚendswithÚmessage_spaceÚmessage_carriager   Úmessage_tabsÚstr_raise_reÚsearchÚmessage_str_raiseÚgen_raise_reÚmessage_gen_raiseÚimplicit_test_reÚlistÚfilterÚmessage_implicitÚ
func_is_reÚmessage_func_isÚold_raise_reÚmessage_old_raiseÚgroupÚmessage_multi_eofÚmessage_eof)	rE   rj   Úidxrc   ÚpyÚlineÚtestsÚtest_setÚresult)Úimport_excluderD   r   rk   Õ   s`    


 
ÿ
  ÿ

z"test_files.<locals>.test_this_filec                 S   s   g | ]}t t|ƒ‘qS r   )r   ÚTOP_PATH)r   Úfiler   r   r   r   
  s     ztest_files.<locals>.<listcomp>)z	isympy.pyzbuild.pyzsetup.pyzL%(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevparser.pyzK%(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevlexer.pyzN%(sep)ssympy%(sep)sparsing%(sep)sautolev%(sep)s_antlr%(sep)sautolevlistener.pyzH%(sep)ssympy%(sep)sparsing%(sep)slatex%(sep)s_antlr%(sep)slatexparser.pyzG%(sep)ssympy%(sep)sparsing%(sep)slatex%(sep)s_antlr%(sep)slatexlexer.pyz%(sep)ssympy%(sep)s__init__.pyz%(sep)svector%(sep)s__init__.pyz"%(sep)smechanics%(sep)s__init__.pyz %(sep)squantum%(sep)s__init__.pyz%(sep)spolys%(sep)s__init__.pyz,%(sep)spolys%(sep)sdomains%(sep)s__init__.pyz#%(sep)sinteractive%(sep)ssession.pyz%(sep)sisympy.pyz%(sep)sbin%(sep)ssympy_time.pyz$%(sep)sbin%(sep)ssympy_time_cache.pyz&%(sep)sparsing%(sep)ssympy_tokenize.pyz'%(sep)splotting%(sep)spygletplot%(sep)sz)%(sep)sbin%(sep)stest_external_imports.pyz*%(sep)sbin%(sep)stest_submodule_imports.pyz"%(sep)sutilities%(sep)sruntests.pyz %(sep)sutilities%(sep)spytest.pyz"%(sep)sutilities%(sep)srandtest.pyz"%(sep)sutilities%(sep)stmpfiles.pyz)%(sep)sutilities%(sep)squality_unicode.pyú~z.pycz.shz.mjsÚ*N)Úsepdr:   rB   ÚBIN_PATHÚ
SYMPY_PATHÚEXAMPLES_PATH)rl   Ztop_level_filesÚexcluder   )r˜   rk   r   Ú
test_files¿   sB    5û
ã
r¢   c                 C   s   t  dd¡d |  S )Nr   é
   r[   )ÚrandomÚrandint)r6   r   r   r   Ú_with_space=  s    r¦   c                  C   s4  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}| D ]R}t  t|ƒ¡d ksŠt|ƒ‚t t|ƒ¡d ks¤t|ƒ‚t t|ƒ¡d kslt|ƒ‚ql|D ]}t  t|ƒ¡d k	sÄt|ƒ‚qÄ|D ]}t t|ƒ¡d k	sèt|ƒ‚qè|D ]"}t t|ƒ¡d k	�st|ƒ‚�qd S )%Nz#some text # raise Exception, 'text'z2raise ValueError('text') # raise Exception, 'text'zraise ValueError('text')zraise ValueErrorzraise ValueError('text') #,zB'"""This function will raise ValueError, except when it doesn't"""zraise (ValueError('text')zraise 'exception'zraise 'Exception'zraise "exception"zraise "Exception"zraise 'ValueError'z1raise Exception('text') # raise Exception, 'text'zraise Exception('text')zraise Exceptionzraise Exception('text') #,zraise Exception, 'text'z1raise Exception, 'text' # raise Exception('text')z1raise Exception, 'text' # raise Exception, 'text'z>>> raise Exception, 'text'z5>>> raise Exception, 'text' # raise Exception('text')z5>>> raise Exception, 'text' # raise Exception, 'text'zraise ValueError, 'text'z2raise ValueError, 'text' # raise Exception('text')z2raise ValueError, 'text' # raise Exception, 'text'z>>> raise ValueError, 'text'z6>>> raise ValueError, 'text' # raise Exception('text')z6>>> raise ValueError, 'text' # raise Exception, 'text'zraise(ValueError,zraise (ValueError,zraise( ValueError,zraise ( ValueError,zraise(ValueError ,zraise (ValueError ,zraise( ValueError ,zraise ( ValueError ,)r‚   rƒ   r¦   rM   r…   r�   )Úcandidates_okZstr_candidates_failZgen_candidates_failZold_candidates_failr6   r   r   r   Ú'test_raise_statement_regular_expressionB  st    ÷ûõìr¨   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}| D ]}t  t|ƒ¡d ks4t|ƒ‚q4|D ]}t  t|ƒ¡d k	sXt|ƒ‚qXd S )Nzfrom sympy import somethingz>>> from sympy import somethingz%from sympy.somewhere import somethingz)>>> from sympy.somewhere import somethingzimport sympyz>>> import sympyz import sympy.something.somethingz... import sympyz$... import sympy.something.somethingz... from sympy import somethingz)... from sympy.somewhere import somethingz>> from sympy import *z# from sympy import *zsome text # from sympy import *zfrom sympy import *z>>> from sympy import *zfrom sympy.somewhere import *z!>>> from sympy.somewhere import *z... from sympy import *z!... from sympy.somewhere import *)r‡   rƒ   r¦   rM   ©r§   Úcandidates_failr6   r   r   r   Ú(test_implicit_imports_regular_expression…  s4    òúr«   c                  C   s\   ddddg} ddddg}| D ]}t  |¡d kst|ƒ‚q|D ]}t  |¡d k	s<t|ƒ‚q<d S )	Nz    def foo():
zdef foo(arg):
zdef _foo():
zdef test_foo():
zdef foo():
zdef foo() :
zdef foo( ):
zdef  foo():
)rx   rƒ   rM   r©   r   r   r   Útest_test_suite_defs¤  s    üür¬   c                  C   sV   dddg} ddg}d}dd„ }| D ]}||ƒ|ks"t ‚q"|D ]}||ƒ|ks<t ‚q<d S )	Nzdef foo():
def foo():
zdef test():
def test_():
zdef test_():
def test__():
zdef test_():
def test_ ():
zdef test_1():
def  test_1():
©Nr   c                 S   sz   d}t ƒ }t|  ¡ ƒD ]^\}}t |¡r|d7 }| |dd …  d¡d  ¡ ¡ t|ƒ|krdt	d|d f f  S qdS )Nr   rZ   r   rn   Fr   r­   )
ru   rv   Ú
splitlinesrz   rG   r{   r   r|   r   r}   )rš   r•   r–   r’   r”   r   r   r   r   Â  s    
 z'test_test_duplicate_defs.<locals>.check)rM   )r§   rª   Úokr   r6   r   r   r   Útest_test_duplicate_defs·  s    ýþ
r°   c                  C   sT   dddddg} dddd	d
g}| D ]}t |ƒg ks t‚q |D ]}t |ƒg ks:t‚q:d S )Nz4class A(object):
    def foo(self, arg): arg = self
z9class A(object):
    def foo(self, arg): self.prop = arg
z?class A(object):
    def foo(self, arg): obj, obj2 = arg, self
zCclass A(object):
    @classmethod
    def bar(cls, arg): arg = cls
z2class A(object):
    def foo(var, arg): arg = var
z4class A(object):
    def foo(self, arg): self = arg
z>class A(object):
    def foo(self, arg): obj, self = arg, arg
zCclass A(object):
    def foo(self, arg):
        if arg: self = argzCclass A(object):
    @classmethod
    def foo(cls, arg): cls = arg
z2class A(object):
    def foo(var, arg): var = arg
)r9   rM   r©   r   r   r   Útest_find_self_assignmentsÒ  s     ûûr±   c                      s„   dg‰dg‰d‰ dg‰t t‡ ‡‡‡fdd„ƒ d‰ dg‰tˆ ˆˆˆƒ d‰ dg‰t t‡ ‡‡‡fdd„ƒ d‰ dg‰tˆ ˆˆˆƒ d S )NZfooÚbarÚabcu   Î±c                      s   t ˆ ˆˆˆƒS r%   r   r   ©rE   rj   Zunicode_strict_whitelistZunicode_whitelistr   r   ro   î  s
      ÿz,test_test_unicode_encoding.<locals>.<lambda>c                      s   t ˆ ˆˆˆƒS r%   r   r   r´   r   r   ro   ø  s
      ÿ)r   rM   r   r   r   r´   r   Útest_test_unicode_encodingè  s0       ÿ   ÿrµ   )AÚosr   r   r   Úos.pathr   r   r   r   r	   r
   rF   r¤   r   Zsympy.testing.pytestr   Zsympy.testing.quality_unicoder   r�   Ú__file__rŸ   rM   r™   rž   r    r   rŠ   r�   r€   r„   r†   rŽ   r‘   r�   ry   r}   Zmessage_self_assignmentsrŒ   rN   Úcompiler‡   r‚   r…   r�   rx   rz   rw   r‹   r   r9   ru   rB   r:   ÚNodeVisitorrH   r]   rf   r¢   r¦   r¨   r«   r¬   r°   r±   rµ   r   r   r   r   Ú<module>   sl   


ÿÿ




"-~C