9L,|ddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZmZmZddlmZmZmZerddlZdZdZGdd eZGd d eZGd d eZGddejZejedZdZ dZ!dZ"dZ#e$ejdsejj%ej_&ddZ'e$ejdse ejde'Gdde(Z)Gdde)Z*ddZ+e$ejdse ejde+dSdS))print_functionabsolute_importN)dedent) bind_methodPY26PY3PY2PY27) check_outputSTDOUTCalledProcessErrorc^|dr |dd}t|S)z, Removes any leading and dedents.  N) startswithr)codes /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/future/tests/base.py reformat_coders1 tABBx $<<c |ddtD}dtD}dtD}||ks Jdd}d}||||ks Jdtfd |D}t t ||}tfd |D}t t ||} tfd |D} t t || } g} t tD]}} | |vr| || "| |vr| | | B| |vr| | | b| | ~d | S) a Returns the code block with any ``__future__`` import lines sorted, and then any ``future`` import lines sorted, then any ``builtins`` import lines sorted. This only sorts the lines within the expected blocks. See test_order_future_lines() for an example. rcBg|]\}}|d|S)from __future__ import r.0ilines r z&order_future_lines..*sDNNN71d"&//2K"L"LNQNNNrclg|]1\}}|ds|d/|2S)z from futurez from pastrrs rrz&order_future_lines..-sP>>>D $ > >> $ < <>1>>>rcBg|]\}}|d|S)z from builtinsrrs rrz&order_future_lines..1sCBBB71d $ @ @BQBBBrzIinternal usage error: dedent the code before calling order_future_lines()cJt|dkrt|ndS)Nr)lenmaxnumberss rmymaxz!order_future_lines..mymax7s""7||a//s7|||Q6rcdt|dkrt|ntdS)Nrinf)r"minfloatr$s rmyminz!order_future_lines..mymin:s("7||a//s7|||U5\\Arz2the __future__ and future imports are out of orderc g|] }| Sr-rrliness rrz&order_future_lines..Cs:::q%(:::rc g|] }| Sr-r-r.s rrz&order_future_lines..Fs777aq777rc g|] }| Sr-r-r.s rrz&order_future_lines..Is999aq999r) split enumeratelstripsorteddictzipranger"appendjoin)ruufuture_line_numbersfuture_line_numbersbuiltins_line_numbersr&r+uulsorted_uufuture_linesflsorted_future_linesblsorted_builtins_lines new_linesrr/s @rorder_future_linesrEs JJt  ENNi.>.>NNN>>Ie,<,<>>>BBi.>.>BBB ;;==D $B 777BBB 5& ' '551D+E+E E E E @ F E E ::::$9::: ; ;C %:C!@!@AA 7777#6777 8 8Bs#6;;<< 9999#8999 : :B %:B!?!?@@I 3u::  '' % % %   215 6 6 6 6 % % %   03 4 4 4 4 ' ' '   215 6 6 6 6   U1X & & & & 99Y  rc eZdZdZddZdZdS)VerboseCalledProcessErrorz Like CalledProcessError, but it displays more information (message and script output) for diagnosing test failures etc. Nc>||_||_||_||_dSN)msg returncodecmdoutput)selfrJrKrLrMs r__init__z"VerboseCalledProcessError.__init__`s"$ rc<d|j|j|j|jfzS)Nz>Command '%s' failed with exit status %d Message: %s Output: %s)rLrKrJrM)rNs r__str__z!VerboseCalledProcessError.__str__fs%R8T_dh DE FrrI)__name__ __module__ __qualname____doc__rOrQr-rrrGrG[sF FFFFFrrGceZdZdS) FuturizeErrorNrRrSrTr-rrrWrWjDrrWceZdZdS)PasteurizeErrorNrXr-rrr[r[mrYrr[czeZdZdZdZ ddZddZdZ dd Zd Z dd Z dd Z ddZ d e jfdZdS) CodeHandlerzt Handy mixin for test classes for writing / reading / futurizing / running .py files in the test suite. ctd|_td|_tjg|_t jtj j z|_ tj d}|r,dtj tjz|zi|_dSdtj i|_dS)zi The outputs from the various futurize stages should have the following headers: z from __future__ import absolute_import from __future__ import division from __future__ import print_function a4 from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from future import standard_library standard_library.install_aliases() from builtins import * PYTHONPATHN)rheaders1headers2sys executable interpreterstempfilemkdtempospathseptempdirgetenvgetcwdpathsepenv)rNpypaths rsetUpzCodeHandler.setUpvs&'    &'    !^,'))BGK7 <((  3$bikkBJ&>&GHDHHH$bikk2DHHHrrFTc|rt|}||||||||}|r |jD]} || } |S)a Converts the code block using ``futurize`` and returns the resulting code. Passing stages=[1] or stages=[2] passes the flag ``--stage1`` or ``stage2`` to ``futurize``. Passing both stages runs ``futurize`` with both stages by default. If from3 is False, runs ``futurize``, converting from Python 2 to both 2 and 3. If from3 is True, runs ``pasteurize`` to convert from Python 3 to both 2 and 3. Optionally reformats the code block first using the reformat() function. If run is True, runs the resulting code under all Python interpreters in self.interpreters. )stages all_importsfrom3 conservative) interpreter)r_write_test_script_futurize_test_script_read_test_scriptrd_run_test_script) rNrrtrurvreformatrunrwrMrx_s rconvertzCodeHandler.converts&  ' &&D %%% ""&k).\ # K K K''))  C#0 C C ))k)BB rc|r*||}||}t|tr*t|ts|d}t|tr*t|ts|d}|t ||dS)a Compares whether the code blocks are equal. If not, raises an exception so the test fails. Ignores any trailing whitespace like blank lines. If ignore_imports is True, passes the code blocks into the strip_future_imports method. If one code block is a unicode string and the other a byte-string, it assumes the byte-string is encoded as utf-8. utf-8N)strip_future_imports isinstancebytesdecode assertEqualrErstrip)rNrMexpectedignore_importss rcomparezCodeHandler.compares  ;..v66F00::H fe $ $ ,Z%-H-H ,]]7++F h & & 0z&%/H/H 0w//H +FMMOO<<!** , , , , ,rcBg}|dD]s}|ds\|dsG|ds2d|vs.d|vs*|ds||td|S)a Strips any of these import lines: from __future__ import from future from future. from builtins or any line containing: install_hooks() or: install_aliases() Limitation: doesn't handle imports split across multiple lines like this: from __future__ import (absolute_import, division, print_function, unicode_literals) rrz from future zfrom builtins zinstall_hooks()zinstall_aliases()z from future.)r2rr9r:)rNrrMrs rrz CodeHandler.strip_future_importss(JJt$$ $ $DOO$=>> $~66 $'788 $)D00*d22~663 d###yy   rc |||||||} |rd|vr|jn|j} nd} t|} | | vrd} || | | z|dS)a< Convenience method that calls convert() and compare(). Reformats the code blocks automatically using the reformat_code() function. If all_imports is passed, we add the appropriate import headers for the stage(s) selected to the ``expected`` code-block, so they needn't appear repeatedly in the test code. If ignore_imports is True, ignores the presence of any lines beginning: from __future__ import ... from future import ... for the purpose of the comparison. )rtrurvr~rwrr)rN)rrar`rr) rNbeforerrtrurrvr~rwrMheaders reformatteds r convert_checkzCodeHandler.convert_checks*fV$)sOO  '(F{{dmm GGG#H-- k ! !G VW{2$2  4 4 4 4 4rc $|j||fi|dS)ze Convenience method to ensure the code is unchanged by the futurize process. N)r)rNrkwargss r unchangedzCodeHandler.unchangeds' 40000000rmytestscript.pyct|tr|d}tj|j|zdd5}|t|ddddS#1swxYwYdS)z Dedents the given code (a multiline string) and writes it out to a file in a temporary folder like /tmp/tmpUDCn7x/mytestscript.py. rwtencodingN)rrrioopenrjwriter)rNrfilenamefs rryzCodeHandler._write_test_script!s dE " " (;;w''D WT\H,dW E E E " GGF4LL ! ! ! " " " " " " " " " " " " " " " " " "s #A::A>A>ctj|j|zdd5}|}dddn #1swxYwY|S)Nrtrr)rrrjread)rNrr newsources rr{zCodeHandler._read_test_script,s WT\H,dW E E E !I ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sAAAc g}t|}|r|d|rd}n]d}|dgkr|dn'|dgkr|dn |ddgksJ|r|d|j|z}tj|g|zd |gz} t | t |j } n#t$r} t|5} d d | d d|jzd|dd| z} dddn #1swxYwYd|vrtnt}t| dsd| _|| | j| j| jd} ~ wwxYw| S)Nz --all-importsz pasteurize.pyz futurize.pyrz--stage1rrz--stage2z--conservativez-w)stderrrnError running the command  renv=%s Contents of file : ---- %s ----futurizerMrM)listr9rjrbrcr r rnr rr:rrWr[hasattrrMrKrL)rNrrtrurvrwparamsscriptfn call_argsrMerrJ ErrorClasss rrzz!CodeHandler._futurize_test_script1sf  + MM/ * * *  0$FF"F!}} j))))A3 j))))!Q'''' 0 .///\H $^V,v5r B  H!)FIIIFF! H H Hb QQ++++ 48+++(1668833                ,6+?+?--_J1h'' *S!,ahGGG G% H& s=,C FE?"?D-! E?-D1 1E?4D1 5A E??Fc |j|z} t||g|jt}n#t$r}t |5}dd||gdd|jzd|dd|z}dddn #1swxYwYt|d sd|_ t||j |j |j d}~wwxYw|S) N)rnrrrrrrrrrMr) rjr rnr r rr:rrrMrGrKrL)rNrrxrrMrrrJs rr|zCodeHandler._run_test_script`sI\H $ W!;"3&*hv???FF! W W Wb QQ+r!23333 48+++(1668833                1h'' +CquQXVVV V! W" s9+ CCAB CB CB >x?C} N N O O O O O   188BB C C C C Cs /AAN)rRrSrTrUrrr-rrrrs=LL    D D D D DrrcTt|||}|d|||S)aFail unless a warning of class warnClass is triggered by callable_obj when invoked with arguments args and keyword arguments kwargs. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception. If called with callable_obj omitted or None, will return a context object used like this:: with self.assertWarns(SomeWarning): do_something() An optional keyword argument 'msg' can be provided when assertWarns is used as a context object. The context manager keeps a reference to the first matching warning as the 'warning' attribute; similarly, the 'filename' and 'lineno' attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:: with self.assertWarns(SomeWarning) as cm: do_something() the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147) assertWarns)rr)rNexpected_warningrrrcontexts rrrs.8""2D,GGG >>-tV D DDrrrI), __future__rrrgrerrbrrrtextwrapr future.utilsrrrr r future.moves.subprocessr r r unittest2rrErGrWr[TestCaser]skipIfskip26rrrrrassertRaisesRegexprrobjectrrrr-rrr s!66666666   ::::::::::::::LLLLLLLLLL!    = = = @ F F F F F 2 F F F     -        /   GGGGG(#GGGV D E E*** *** *** ***wx "566O*2*;*NH'))))wx -00?K!=+>>> * * * * *v * * *D.D.D.D.D.D2.D.D.DbEEEE>wx -00?K!=+>>>>>??r