
    gK                     $   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J  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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! Z0 e1            d"fd#Z2 e1            dfd$Z3 G d% d&ej4                  Z5 e5            Z6d' Z7d( Z8d) Z9d* Z:d+ Z;d, Z<d- Z=d. Z>d/ Z?dS )0    )walkseppardir)splitjoinabspathexistsisfile)globN)raises_test_this_file_encodingr   bin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                 l   t          |           t          |                                           z
  }| ||dz            dvr| d|         }nQ| |dz   d         }| d|         |dt          |          t          |                                          z
           z   }|                                |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checksmores       a/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/testing/tests/test_code_quality.pytab_in_leadingr   7   s     	AQXXZZ AQq1uW:''"1"!a%&&	"1"?s5zzC,?,???@@  ""e+,,    c                    d t          j        |           j        D             }g }|D ]>}|j        D ]2}t          |t           j                  st          d |j        D                       r=|j        dk    rI|j        j        sV|j        j        d         j	        t          j
        |          D ]}t          |t           j                  r|j        D ]}t          |t           j                  r!|j        k    r|                    |           =t          |t           j                  r5t          fd|j        D                       r|                    |           4@|S )zReturns a list of "bad" assignments: if there are instances
    of assigning to the first argument of the class method (except
    for staticmethod's).
    c                 F    g | ]}t          |t          j                  |S  )
isinstanceastClassDef).0r   s     r   
<listcomp>z)find_self_assignments.<locals>.<listcomp>H   s)    EEEqAs|)D)DEEEEr   c              3   `   K   | ])}t          |t          j                  |j        d k    V  *dS )staticmethodNr    r!   Nameid)r#   ds     r   	<genexpr>z(find_self_assignments.<locals>.<genexpr>O   sV       I I
1ch0G0GI14>) I I I I I Ir   __new__r   c              3   b   K   | ])}t          |t          j                  |j        k    V  *d S Nr'   )r#   q	first_args     r   r+   z(find_self_assignments.<locals>.<genexpr>^   sN       "> ">%/38%<%<">!$)"3 "> "> "> "> "> ">r   )r!   parsebodyr    FunctionDefanydecorator_listnameargsargr   Assigntargetsr(   r)   appendTupleelts)r   tbadcr   mar0   s          @r   find_self_assignmentsrC   C   s   
 	FECIaLL%EEEA
C * * 	* 	*Aa11  I I,I I I I I v""6; A*IXa[[ * *a,, *Y * *%a22 *qty7H7HJJqMMMM(CI66 *! "> "> "> ">QV "> "> "> > >*  JJqMMM*	*, Jr   z*.pyc           	          | sdS t          |           D ]2\  }}}t          t          t          ||                    ||           3d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filess          r   check_directory_treerM   e   sb      !)__ G GdEDdG,,--z:FFFFG Gr   c                     | sdS | D ]_t                    rt                    s!t          fd|D                       r=|t          j        |          r |           `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       K   | ]}|v V  	d S r.   r   )r#   exfnames     r   r+   zcheck_files.<locals>.<genexpr>{   s'      00rrU{000000r   )r	   r
   r4   rematch)rL   rG   rH   rI   rQ   s       @r   rE   rE   q   s    
    e}} 	F5MM 	0000Z00000 	?bhw66?Ju r   c                       e Zd ZdZd Z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                     t          |j        t          j        t          j        f          rJ t
          d|j        fz              d S )N )r    valuer!   BinOpComparemessage_bare_exprlinenoselfnodes     r   
visit_Exprz_Visit.visit_Expr   sD    dj39ck":;; 	?>*b$+->>>>>	? 	?r   c                     d S r.   r   r]   s     r   
visit_Withz_Visit.visit_With   s    r   N)__name__
__module____qualname____doc__r`   rb   r   r   r   rU   rU      s=        $ $J? ? ?    r   rU   c                    t          j        |           }	 t                              |           dS # t          $ r}|j        sJ |j        d         }|                    t                              dd          d                   sJ t          |
                    dd          d                             d                    cY d}~S d}~ww xY w)z]return None or else 0-based line number of code on which
    a bare expression appeared.
    r   :    .N)r!   r1   BareExprvisitAssertionErrorr7   
startswithr[   r   intrsplitrstrip)codetreemsgs      r   line_with_bare_exprrv      s     9T??D6t 6 6 6xhqk~~/55c1==a@AAAAA3::c1%%a(//4455555555	6s   2 
CBC	C	Cc                     fd} fdd dD             }dt           z  dt           z  dt           z  dt           z  d	t           z  h}d
t           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  dt           z  ht          ||            t          t          | h d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                     t          | d          5 } | |           d d d            n# 1 swxY w Y   t          | d          5 }t          | |           d d d            d S # 1 swxY w Y   d S )Nutf8)encoding)openr   )rQ   	test_filetest_this_files     r   testztest_files.<locals>.test   s    %&))) 	-YN5),,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-%&))) 	7Y$UI666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   ,00A&&A*-A*c                 h    d }|                                 }|                    d           t           vr n                      t          d          d         }|                    d          rt          |          }|J t           |dz   fz              d }d}t                      }t          |          D ]\  }}t          
                               rt          
                    |          rJ t           |dz   fz              t          
                    |          rw|dz  }|                    |dd                              d          d                                                    t#          |          |k    rJ t$           |dz   fz              |                    d          rJ t(           |dz   fz              |                    d	          rJ t*           |dz   fz              t-          |          rJ t.           |dz   fz              t0                              |          rJ t4           |dz   fz              t6                              |          rJ t8           |dz   fz              t:                              |          r7t=          t?           fd
	                    sJ t@           |dz   fz              tB                              |          r1t                                         sJ tD           |dz   fz              tF                              |          }|+J tH           |dz   |%                    d          fz              |O|dk    r|dk    rJ tL           |dz   fz              |                    d          sJ tN           |dz   fz              d S d S )Nr   ri   test_Fr   ()z 
z	
z
c                     | v S r.   r   )rP   rQ   s    r   <lambda>z4test_files.<locals>.test_this_file.<locals>.<lambda>   s    rU{ r      
)(readseekr   rq   ro   rv   r[   set	enumeratetest_file_rerS   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)
rQ   r|   idxrs   pylineteststest_setresultimport_excludes
   `        r   r}   z"test_files.<locals>.test_this_file   s   ~~q&&UUELLa,@,@,D==!! 	,%d++C?>+ucAg.>>>>>55"9-- 	5 	5IC!!%(( P$**400 LK"8E37;K"KKKK!''-- PQJELLabb!4!4Q!7!=!=!?!?@@@8}}--O&<sQw?O&OOOO}}_-- ?>mucAg.>>>>>}}V$$ BA.%q1AAAAAd## >=leS1W-=====""4(( CB/5#'2BBBBB""4(( CB/5#'2BBBBB ''-- BV$:$:$:$:NKKLLBA.%q1AAAAA  && A|/B/B5/I/I A@oa0@@@@@!((..F!5/37FLLOO35 5 5 5 5 " t||aB/5#'2BBBBB]]4(( =<kUC!G,<<<<< = =r   c                 8    g | ]}t          t          |          S r   )r   TOP_PATH)r#   files     r   r$   ztest_files.<locals>.<listcomp>
  s.       tHd++   r   )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>   .sh.mjs.pyc~*N)sepdrE   rM   BIN_PATH
SYMPY_PATHEXAMPLES_PATH)r~   top_level_filesexcluder   r}   s      @@r   
test_filesr      s    7 7 7 7 71= 1= 1= 1= 1=j  9   O 	WY]]UX\\X[__RUYYQTXXG 	)4/ 	*D0,t3*T1(4/6=-4T!(4/.50471D83d:4t;,t3*T1,t3,t33d:;N> &&&4)E)E)EsKKKT7333g66666r   c                 8    t          j        dd          dz  | z   S )Nr   
   rj   )randomrandint)r@   s    r   _with_spacer   =  s    >!R  $q((r   c                     g d} g d}g d}g d}| D ]}t                               t          |                    
J |            t                              t          |                    
J |            t                              t          |                    
J |            |D ]3}t                               t          |                    
J |            4|D ]3}t                              t          |                    
J |            4|D ]3}t                              t          |                    
J |            4d S )N)z#some text # raise Exception, 'text'z2raise ValueError('text') # raise Exception, 'text'raise ValueError('text')zraise ValueErrorr   z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'raise Exception('text')zraise Exceptionr   zraise Exception('text') #,raise Exception, 'text'1raise Exception, 'text' # raise Exception('text')1raise Exception, 'text' # raise Exception, 'text'>>> raise Exception, 'text'5>>> raise Exception, 'text' # raise Exception('text')5>>> raise Exception, 'text' # raise Exception, 'text')r   r   r   r   r   r   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   r   r   )candidates_okstr_candidates_failgen_candidates_failold_candidates_failr@   s        r   'test_raise_statement_regular_expressionr   B  s   
 
 
M      .  > >"";q>>22::A:::"";q>>22::A:::"";q>>22::A::::  B B"";q>>22>>>>>>  B B"";q>>22>>>>>>  B B"";q>>22>>>>>>B Br   c                      g d} g d}| D ]3}t                               t          |                    
J |            4|D ]3}t                               t          |                    
J |            4d S )N)z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   r   candidates_failr@   s      r   (test_implicit_imports_regular_expressionr     s      M   O  B B&&{1~~66>>>>>> F F&&{1~~66BBABBBBF Fr   c                      g d} g d}| D ]&}t                               |          
J |            '|D ]&}t                               |          
J |            'd S )N)z    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():
)r   r   r   s      r   test_test_suite_defsr     s      M  O  6 6 ''**22A2222 : : ''**666666: :r   c                  x    g d} ddg}d}d }| D ]} ||          |k    sJ |D ]} ||          |k    sJ d S )N)z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                    d}t                      }t          |                                           D ]\  }}t                              |          rs|dz  }|                    |dd                              d          d                                                    t          |          |k    rdt          d|dz   fz  fc S dS )Nr   ri   r   r   Fr   r   )
r   r   
splitlinesr   rS   r   r   r   r   r   )r   r   r   r   r   s        r   r   z'test_test_duplicate_defs.<locals>.check  s    55"4??#4#455 	N 	NIC##D)) N
T!""X^^C00399;;<<<x==E)) "8GS1W;M"MMMMM}r   r   )r   r   okr   r@   s        r   test_test_duplicate_defsr     s      M 	()O 
B	 	 	   uQxx2~~~~~  uQxx2~~~~~ r   c                  ~    g d} g d}| D ]}t          |          g k    sJ |D ]}t          |          g k    sJ d S )N)z4class 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
)rC   r   s      r   test_find_self_assignmentsr     s      M  O  . .$Q''2----- . .$Q''2-----. .r   c                       dgdgd dgt          t           fd           d dgt                      d dgt          t           fd           d dgt                      d S )Nfoobarabcu   αc                  (    t                     S r.   r   rQ   r|   unicode_strict_whitelistunicode_whitelists   r   r   z,test_test_unicode_encoding.<locals>.<lambda>      #;y+-E$G $G r   c                  (    t                     S r.   r   r   s   r   r   z,test_test_unicode_encoding.<locals>.<lambda>  r   r   )r   rn   r   r   s   @@@@r   test_test_unicode_encodingr     s    %wEI
> G G G G G G G H H H EIy+-EG G G EI
> G G G G G G G H H H EIy+-EG G G G Gr   )@osr   r   r   os.pathr   r   r   r	   r
   r   rR   r   r!   sympy.testing.pytestr   sympy.testing.quality_unicoder   r   __file__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   message_self_assignmentsr   r[   compiler   r   r   r   r   r   r   r   r   rC   r   rM   rE   NodeVisitorrU   rl   rv   r   r   r   r   r   r   r   r   r   r   r   <module>r      s\                       8 8 8 8 8 8 8 8 8 8 8 8 8 8       				  



 ' ' ' ' ' ' B B B B B B 	s| WTT%%//!,ff==>>
vj   744
F++,,4%  Xz** BC CO A B R =E Q I P :A 2:IJJ rz@B BrzDF FrzNOOBJFGG /00rz011RZ)**
	- 	- 	-  D <?355& 	G 	G 	G 	G /2ceeT     * * * * *S_ * * *Z 6886 6 6{7 {7 {7|) ) )
@B @B @BFF F F>: : :&  6. . .,G G G G Gr   