Spade
Mini Shell
| Directory:~$ /usr/lib/python2.7/site-packages/future/tests/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@@s8ddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl
mZddlm
Z
mZmZmZmZddlmZmZmZer�ddlZnd�Zd�Zdefd ��YZd
efd��YZdefd
��YZdejfd��YZejed�Zd�Z
d�Z!d�Z"d�Z#e$ejd�r�ejj%ej_&ne'd�Z(e$ejd�r�e
ejde(�nde)fd��YZ*de*fd��YZ+e'd�Z,e$ejd�r4e
ejde,�ndS(i(tprint_functiontabsolute_importN(tdedent(tbind_methodtPY26tPY3tPY2tPY27(tcheck_outputtSTDOUTtCalledProcessErrorcC@s&|jd�r|d}nt|�S(s,
Removes any leading
and dedents.
s
i(t
startswithR(tcode((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt
reformat_codes
cC@s|jd�}gt|�D]!\}}|jd�r|^q}gt|�D]0\}}|jd�sz|jd�rP|^qP}gt|�D]!\}}|jd�r�|^q�}d�}d�}tg|D]}||^q��} tt|| ��}
tg|D]}||^q�}tt||��}tg|D]}||^qF�}
tt||
��}g}x�tt|��D]w}||kr�|j|
|�q�||kr�|j||�q�||kr�|j||�q�|j||�q�Wdj |�S(s
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.
s
sfrom __future__ import sfrom futures from pasts
from builtinscS@s
t|�dkrt|�SdS(Ni(tlentmax(tnumbers((s5/usr/lib/python2.7/site-packages/future/tests/base.pytmymax7scS@s&t|�dkrt|�Std�S(Nitinf(Rtmintfloat(R((s5/usr/lib/python2.7/site-packages/future/tests/base.pytmymin:s(
tsplitt enumerateRtsortedtdicttziptrangeRtappendtjoin(Rtlinestitlinetuufuture_line_numberstfuture_line_numberstbuiltins_line_numbersRRtuultsorted_uufuture_linestfltsorted_future_linestbltsorted_builtins_linest new_lines((s5/usr/lib/python2.7/site-packages/future/tests/base.pytorder_future_liness4
###tVerboseCalledProcessErrorcB@s#eZdZdd�Zd�ZRS(s�
Like CalledProcessError, but it displays more information (message and
script output) for diagnosing test failures etc.
cC@s(||_||_||_||_dS(N(tmsgt
returncodetcmdtoutput(tselfR-R.R/R0((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt__init__`s cC@s
d|j|j|j|jfS(Ns>Command '%s' failed with exit status %d
Message: %s
Output:
%s(R/R.R-R0(R1((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt__str__fsN(t__name__t
__module__t__doc__tNoneR2R3(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR,[st
FuturizeErrorcB@seZRS((R4R5(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR8jstPasteurizeErrorcB@seZRS((R4R5(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR9mstCodeHandlercB@s�eZdZd�Zdeeeeed�Zed�Zd�Zdeeeeed�Z d�Z
d d
�Zd d�Zd deeed�Z
d ejd
�ZRS(st
Handy mixin for test classes for writing / reading / futurizing /
running .py files in the test suite.
cC@s�td�|_td�|_tjg|_tj�tj j
|_tjd�}|ritj
�tj|d6|_nitj
�d6|_dS(si
The outputs from the various futurize stages should have the
following headers:
s�
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
s4
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 *
t
PYTHONPATHN(R
theaders1theaders2tsyst
executabletinterpretersttempfiletmkdtemptostpathtsepttempdirtgetenvtgetcwdtpathseptenv(R1tpypath((s5/usr/lib/python2.7/site-packages/future/tests/base.pytsetUpvs$iic C@s�|rt|�}n|j|�|jd|d|d|d|�|j�}|rx&|jD]} |jd| �}
q`Wn|S(s�
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.
tstagestall_importstfrom3tconservativetinterpreter(R
t_write_test_scriptt_futurize_test_scriptt_read_test_scriptR@t_run_test_script(R1RRMRNROtreformattrunRPR0RQt_((s5/usr/lib/python2.7/site-packages/future/tests/base.pytconvert�s
cC@s�|r'|j|�}|j|�}nt|t�rXt|t�rX|jd�}nt|t�r�t|t�r�|jd�}n|jt|j��|j��dS(s�
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.
sutf-8N(tstrip_future_importst
isinstancetbytestdecodetassertEqualR+trstrip(R1R0texpectedtignore_imports((s5/usr/lib/python2.7/site-packages/future/tests/base.pytcompare�scC@s�g}x{|jd�D]j}|jd�pm|jd�pm|jd�pmd|kpmd|kpm|jd�s|j|�qqWdj|�S(s
Strips any of these import lines:
from __future__ import <anything>
from future <anything>
from future.<anything>
from builtins <anything>
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)
s
sfrom __future__ import sfrom future sfrom builtins
sinstall_hooks()sinstall_aliases()sfrom future.(RRRR(R1RR0R
((s5/usr/lib/python2.7/site-packages/future/tests/base.pyRZ�sc C@s�|j|d|d|d|d|d|�} |rTd|krH|jn|j}
nd}
t|�}|
|kr{d}
n|j| |
|d|�d S(
s<
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.
RMRNRORWRPitRaN(RYR=R<R
Rb(R1tbeforeR`RMRNRaRORWRPR0theaderstreformatted((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt
convert_check�s! cK@s|j|||�dS(se
Convenience method to ensure the code is unchanged by the
futurize process.
N(Rg(R1Rtkwargs((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt unchangedssmytestscript.pycC@s`t|t�r!|jd�}ntj|j|ddd��}|jt|��WdQXdS(s�
Dedents the given code (a multiline string) and writes it out to
a file in a temporary folder like /tmp/tmpUDCn7x/mytestscript.py.
sutf-8twttencodingN(R[R\R]tiotopenRFtwriteR(R1Rtfilenametf((s5/usr/lib/python2.7/site-packages/future/tests/base.pyRR!s"cC@s8tj|j|ddd��}|j�}WdQX|S(NtrtRksutf-8(RlRmRFtread(R1RoRpt newsource((s5/usr/lib/python2.7/site-packages/future/tests/base.pyRT,s"c
C@s�g}t|�}|r(|jd�n|r7d}nZd}|dgkr\|jd�n|dgkr{|jd�n|r�|jd�n|j|}tj|g|d |g} yt| d
td|j�}
Wn�tk
r�}t |��7}dd
j
| �d|j|d|j�f}
WdQXd|krCtnt
}t|d�sdd|_n||
|j|jd|j��nX|
S(Ns
--all-importss
pasteurize.pysfuturize.pyis--stage1is--stage2s--conservatives-wtstderrRJs8Error
running the command %s
%s
Contents of file %s:
%st senv=%ss----
%s
----tfuturizeR0(tlistRRFR>R?RR RJR
RmRRrR8R9thasattrR7R0R.R/(R1RoRMRNRORPtparamstscripttfnt call_argsR0teRpR-t
ErrorClass((s5/usr/lib/python2.7/site-packages/future/tests/base.pyRS1s:
%c
C@s�|j|}y%t||gd|jdt�}Wn�tk
r�}t|��=}ddj||g�d|j|d|j�f}WdQXt|d�s�d|_
nt||j|j
d|j
��nX|S(NRJRts8Error running the command %s
%s
Contents of file %s:
%sRusenv=%ss----
%s
----R0(RFRRJR R
RmRRrRxR7R0R,R.R/(R1RoRQR{R0R}RpR-((s5/usr/lib/python2.7/site-packages/future/tests/base.pyRU`s
%(ii(ii(ii(R4R5R6RLtFalsetTrueRYRbRZRgRiRRRTRSR>R?RU(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR:qs" + " ! -s#this
test is known to fail on Py2.6cC@sts
|Stj|�S(N(RtunittesttexpectedFailure(tfunc((s5/usr/lib/python2.7/site-packages/future/tests/base.pytexpectedFailurePY3scC@sts
|Stj|�S(N(RR�R�(R�((s5/usr/lib/python2.7/site-packages/future/tests/base.pytexpectedFailurePY26�scC@sts
|Stj|�S(N(RR�R�(R�((s5/usr/lib/python2.7/site-packages/future/tests/base.pytexpectedFailurePY27�scC@sts
|Stj|�S(N(RR�R�(R�((s5/usr/lib/python2.7/site-packages/future/tests/base.pytexpectedFailurePY2�stassertRaisesRegexcC@snt|ttf�r'tj|�}n|j|�sj|p?d}d||j|f}|j|��ndS(s=Fail
the test unless the text matches the regular expression.sRegex didn't
matchs%s: %r not found in
%rN(R[tstrtunicodetretcompiletsearchtpatterntfailureException(R1ttexttexpected_regexR-((s5/usr/lib/python2.7/site-packages/future/tests/base.pytassertRegex�sR�t_AssertRaisesBaseContextcB@s)eZddd�Zd�Zd�ZRS(cC@s�||_||_|dk rTy|j|_Wq]tk
rPt|�|_q]Xn d|_t|ttf�r�t j
|�}n||_d|_dS(N(
R`t test_caseR7R4tobj_nametAttributeErrorR�R[R\R�R�R�R-(R1R`R�tcallable_objR�((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR2�s
cC@s.|jj|j|�}|jj|��dS(N(R�t_formatMessageR-R�(R1tstandardMsgR-((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt
_raiseFailure�scC@sC|dkr%|jdd�|_|S|�|||�WdQXdS(s�
If callable_obj is None, assertRaises/Warns is being used as a
context manager, so check for a 'msg' kwarg and return
self.
If callable_obj is not None, call it passing args and kwargs.
R-N(R7tpopR-(R1tnameR�targsRh((s5/usr/lib/python2.7/site-packages/future/tests/base.pythandle�s
N(R4R5R7R2R�R�(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR��s t_AssertWarnsContextcB@s
eZdZd�Zd�ZRS(sBA context manager used to implement
TestCase.assertWarns*
methods.cC@svx5tjj�D]$}t|dd�ri|_qqWtjdt�|_ |j j
�|_tjd|j�|S(Nt__warningregistry__trecordtalways(
R>tmodulestvaluestgetattrR7R�twarningstcatch_warningsR�twarnings_managert __enter__tsimplefilterR`(R1tv((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR��scC@so|jj|||�|dk r&dSy|jj}Wn
tk
rXt|j�}nXd}x�|jD]�}|j}t ||j�s�qin|dkr�|}n|j
dk r�|j
jt|��r�qin||_|j
|_
|j|_dSW|dk r-|jdj|j
jt|���n|jrU|jdj||j��n|jdj|��dS(Ns"{}"
does not match "{}"s{} not triggered by {}s{} not
triggered(R�t__exit__R7R`R4R�R�R�tmessageR[R�R�twarningRotlinenoR�tformatR�R�(R1texc_typet exc_valuettbtexc_nametfirst_matchingtmtw((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR��s8
(R4R5R6R�R�(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR��s cO@s(t|||�}|jd|||�S(s�Fail
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)
tassertWarns(R�R�(R1texpected_warningR�R�Rhtcontext((s5/usr/lib/python2.7/site-packages/future/tests/base.pyR��sR�(-t
__future__RRRCRAR�R>R�R�RlttextwrapRtfuture.utilsRRRRRtfuture.moves.subprocessRR R
t unittest2R
R+R,R8R9tTestCaseR:tskipIftskip26R�R�R�R�RxtassertRaisesRegexpR�R7R�tobjectR�R�R�(((s5/usr/lib/python2.7/site-packages/future/tests/base.pyt<module>sD( @�
"1