K i81ddlZddlmZddlmZmZmZmZddl m Z ddl m Z ddlm ZddlmZmZGddZGdd eZ Gd d ee Z Gd d ee Z GddeeZy)N)messages)PYPY DoctestScope FunctionScope ModuleScope)Test)TestCaseskipc(eZdZdZdZfdZxZS) _DoctestMixinTcg}tj|jD]}|jdk(rn|j dsk|j dsZ|j dsI|j ds8|j ds'|j ds|r|dj d rd |z}nd |z}|j |tjd }|d j |zS)N zexcept:zexcept zfinally:zelse:zelif )z>>> @z... @z... %sz>>> %szo def doctest_something(): """ %s """ z )textwrapdedent splitlinesstrip startswithappendjoin)selfinputlineslinedoctestificators a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyflakes/test/test_doctests.py doctestifyz_DoctestMixin.doctestifysOOE*557 Dzz|r!//#&//),//),//*-//'*//'*U2Y112DE$$ LL  #//+ !1!1%!888cHt||j|g|i|S)N)superflakesr)rrargskw __class__s rr"z_DoctestMixin.flakes,s%w~dooe4BtBrBBr)__name__ __module__ __qualname__ withDoctestrr" __classcell__)r%s@rr r sK90CCrr ceZdZdZdZdZdZdZdZdZ dZ d Z e d d Z d Zd ZdZdZdZdZdZdZdZdZdZdZy)rTc$|jd}|j}|Dcgc]}|jtus|}}|Dcgc]}|jtus|}}|Dcgc]}|jt us|}}|j t|d|j t|d|d}|d}|j|t|j|t|j|t |j|t|jd||jd||jd||j t|d|jd|dycc}wcc}wcc}w) z-Check that a doctest is given a DoctestScope.z m = None def doctest_stuff(): ''' >>> d = doctest_stuff() ''' f = m return f rm doctest_stuffdfN) r" deadScopesr%rrr assertEquallenassertIsInstanceassertNotIsInstanceassertIn rcheckerscopesscope module_scopesdoctest_scopesfunction_scopes module_scope doctest_scopes rtest_scope_classzTest.test_scope_class4s++   ##%IK)GEI I &JL)HEJJ &KM)IEKK ]+Q/ ^,a0$Q' &q)  m\: m[9    >   |< c<( o|4 c=) _-q1 c?1-.1IJKs"FFFF&F >F c|jd}|j}|Dcgc]}|jtus|}}|Dcgc]}|jtus|}}|Dcgc]}|jt us|}}|j t|d|j t|d|d}|d}|jd||jd||jd||j t|d|jd|d|jd |dy cc}wcc}wcc}w) z'Check that nested doctests are ignored.a m = None def doctest_stuff(): ''' >>> def function_in_doctest(): ... """ ... >>> ignored_undefined_name ... """ ... df = m ... return df ... >>> function_in_doctest() ''' f = m return f r-rr.r/function_in_doctestr1dfN) r"r2r%rrrr3r4r7r8s rtest_nested_doctest_ignoredz Test.test_nested_doctest_ignored\sV++  $##%IK)GEI I &JL)HEJJ &KM)IEKK ]+Q/ ^,a0$Q' &q)  c<( o|4 +]; _-q1 c?1-. dOA./)IJKs"EEEE&E >E c|jd}|j}|Dcgc]}|jtus|}}|Dcgc]}|jtus|}}|Dcgc]}|jt us|}}|j t|d|j t|d|d}|d}|jd||jd||j t|d|jd|d|jd|d|jd |d|jd |y cc}wcc}wcc}w) z;Check that global in doctest does not pollute module scope.a[ def doctest_stuff(): ''' >>> def function_in_doctest(): ... global m ... m = 50 ... df = 10 ... m = df ... >>> function_in_doctest() ''' f = 10 return f r-rr/rCrDr1rEr.N) r"r2r%rrrr3r4r7 assertNotInr8s r"test_global_module_scope_pollutionz'Test.test_global_module_scope_pollutionsk++   ##%IK)GEI I &JL)HEJJ &KM)IEKK ]+Q/ ^,a0$Q' &q)  o|4 +]; _-q1 c?1-. dOA./ c?1-. l+-IJKs"EEEE&E>EcD|jdtjy)Nzn global m def doctest_stuff(): ''' >>> m ''' r"r. UndefinedNamers rtest_global_undefinedzTest.test_global_undefineds  __ rcb|jdtjtjy)z*Doctest within nested class are processed.a class C: class D: ''' >>> m ''' def doctest_stuff(self): ''' >>> m ''' return 1 NrKrMs rtest_nested_classzTest.test_nested_classs"  __aoo /rc&|jdy)z>> syntax error >>> inner_function() 1 >>> m ''' return 1 m = inner_function() return m Nr"rMs rtest_ignore_nested_functionz Test.test_ignore_nested_functions  rcD|jdtjy)z#Doctest may not access class scope.z class C: def doctest_stuff(self): ''' >>> m ''' return 1 m = 1 NrKrMs rtest_inaccessible_scope_classz"Test.test_inaccessible_scope_classs  __ rc&|jdy)Nzr import foo def doctest_stuff(): ''' >>> foo ''' rRrMs rtest_importBeforeDoctestzTest.test_importBeforeDoctests   rtodocD|jdtjy)Nz import foo def doctest_stuff(): """ >>> import foo >>> foo """ foo )r"r.RedefinedWhileUnusedrMs rtest_importBeforeAndInDoctestz"Test.test_importBeforeAndInDoctests   # # %rc&|jdy)Nz def doctest_stuff(): """ >>> import foo >>> foo """ import foo foo() rRrMs rtest_importInDoctestAndAfterz!Test.test_importInDoctestAndAfter  rc|jdtjjd}|j |j d|j |j dy)Nzg def doctest_stuff(): """ >>> x # line 5 """ r r"r.rLrr3linenocolrexcs rtest_offsetInDoctestszTest.test_offsetInDoctestsVkk __'hq* Q' "%rc|jdtjjd}|j |j d|j |j dy)Nzo def doctest_stuff(): """ >>> lambda: x # line 5 """ rr`rbres rtest_offsetInLambdasInDoctestsz#Test.test_offsetInLambdasInDoctestsrhrc|jdtjjd}|j |j d|j |j dy)Nzm def doctest_stuff(): """ >>> x = 5 """ x rrbres rtest_offsetAfterDoctestszTest.test_offsetAfterDoctests(sVkk  __ 'hq * Q' !$rc|jdtjtjtjj}|d}|j |j dt s|j |jdn|j |jd|d}|j |j dt r|j |jdn|j |jd |d }|j |j d |j |jdy) Nz def doctest_stuff(): """ >>> from # line 4 >>> fortytwo = 42 >>> except Exception: """ rr-r` rD)r"r.DoctestSyntaxErrorrr3rcrrdr exceptionsrfs rtest_syntaxErrorInDoctestzTest.test_syntaxErrorInDoctest6s[[    "#+( m Q'   SWWb )   SWWb ) m Q'    SWWb )   SWWb )m Q' "%rc|jdtjjd}|j |j d|j |j dy)Nz| def doctest_stuff(): """ >>> if True: ... pass """ rr`rs)r"r.rvrr3rcrdres rtest_indentationErrorInDoctestz#Test.test_indentationErrorInDoctestWsXkk  ! ! # $,8A / Q' "%rc\|jdtjtjj\}}|j |j d|j |jd|j |j d|j |jdy)Nz def doctest_stuff(arg1, arg2, arg3): """ >>> assert >>> this """ rura)r"r.rvrLrr3rcrd)rexc1exc2s rtest_offsetWithMultiLineArgsz!Test.test_offsetWithMultiLineArgsbs{{   OO &X t a( 2& a( 2&rc&|jdy)NzT def foo(): ''' >>> foo ''' rRrMs rtest_doctestCanReferToFunctionz#Test.test_doctestCanReferToFunctionts   rc&|jdy)Nz class Foo(): ''' >>> Foo ''' def bar(self): ''' >>> Foo ''' rRrMs rtest_doctestCanReferToClassz Test.test_doctestCanReferToClass|r^rc|jdtjtjj}|d}|j |j d|d}|j |j dy)NaF def buildurl(base, *args, **kwargs): """ >>> buildurl('/blah.php', ('a', '&'), ('b', '=') '/blah.php?a=%26&b=%3D' >>> buildurl('/blah.php', a='&', 'b'='=') '/blah.php?b=%3D&a=%26' """ pass rrpr-ru)r"r.rvrr3rcrws r!test_noOffsetSyntaxErrorInDoctestz&Test.test_noOffsetSyntaxErrorInDoctestso[[    "#+( m Q'm Q'rc&|jdy)Nz def func(): """A docstring >>> func() 1 >>> _ 1 """ return 1 rRrMs rtest_singleUnderscoreInDoctestz#Test.test_singleUnderscoreInDoctests  rcD|jdtjy)Nz from gettext import ugettext as _ def doctest_stuff(): ''' >>> pass ''' )r"r. UnusedImportrMs rtest_globalUnderscoreInDoctestz#Test.test_globalUnderscoreInDoctests  ^^ rN)r&r'r(r)rArFrIrNrPrSrUrWr r[r]rgrkrnryr{rrrrrrrrrr0sK&/P)0V),V / *   &\ % %   & & %&B &'$   (&  rrceZdZdZy) TestOtherz2Run TestOther with each test wrapped in a doctest.Nr&r'r(__doc__rrrrrsrrceZdZdZy)TestUndefinedNamesz;Run TestUndefinedNames with each test wrapped in a doctest.NrrrrrrsErr)rpyflakesrr.pyflakes.checkerrrrrpyflakes.test.test_otherrrpyflakes.test.test_importsr"pyflakes.test.test_undefined_namesrpyflakes.test.harnessr r r rrrrsl" 7:I0CC@@8@F = y=?-?F(:Fr