Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/pytest.cpython-37.pyc

B

�d{T>��@s�dZddlmZdZdZdZdZddlZddlZddl	Z	ddl
mZddl
m
Z
mZddlZddlZdd	lmZmZdd
lmZddlmZddlmZdd
lmZmZddlmZmZddlm Z ddl!Z!ddlZ"e#e"dd��syddl$m%Z&Wn e'k
�re�(d�YnXnddl)m%Z&y ddl*Z*ddl+m,Z,m-Z-dZ.Wne'k
�r\dZ.YnXdZ/edDdd��Z0dd�Z1Gdd�de2�Z3e3j4Z4e3j5Z5dd�Z6e	�7d�Z8dd�Z9e	�7d �Z:d!d"�Z;d#d$�Z<e�=�fd%d&�Z>Gd'd(�d(e2�Z?d)d*�Z@Gd+d,�d,e2�ZAGd-d.�d.eA�ZBd/d0�ZCd1d2�ZDd3d4�ZEGd5d6�d6ejF�ZGGd7d8�d8ejH�ZIGd9d:�d:ejJ�ZKdEd;d<�ZLdFd=d>�ZMejNd?k�r�dGd@d<�ZLdAdB�ZOejPe_QeIe_HeKe_JeGe_FejNdCk�r�ejRfe!jS_TnejRfejU_TeLejV_EeMejV_WdS)Ha<
pytest is a tool that eases test running and debugging.

To be able to use pytest, you should either write tests using
the logilab.common.testlib's framework or the unittest module of the
Python's standard library.

You can customize pytest's behaviour by defining a ``pytestconf.py`` file
somewhere in your test directory. In this file, you can add options or
change the way tests are run.

To add command line options, you must define a ``update_parser`` function in
your ``pytestconf.py`` file. The function must accept a single parameter
that will be the OptionParser's instance to customize.

If you wish to customize the tester, you'll have to define a class named
``CustomPyTester``. This class should extend the default `PyTester` class
defined in the pytest module. Take a look at the `PyTester` and `DjangoTester`
classes for more information about what can be done.

For instance, if you wish to add a custom -l option to specify a loglevel, you
could define the following ``pytestconf.py`` file ::

    import logging
    from logilab.common.pytest import PyTester

    def update_parser(parser):
        parser.add_option('-l', '--loglevel', dest='loglevel', action='store',
                          choices=('debug', 'info', 'warning', 'error', 'critical'),
                          default='critical', help="the default log level possible choices are "
                          "('debug', 'info', 'warning', 'error', 'critical')")
        return parser


    class CustomPyTester(PyTester):
        def __init__(self, cvg, options):
            super(CustomPyTester, self).__init__(cvg, options)
            loglevel = options.loglevel.upper()
            logger = logging.getLogger('erudi')
            logger.setLevel(logging.getLevelName(loglevel))


In your TestCase class you can then get the value of a specific option with
the ``optval`` method::

    class MyTestCase(TestCase):
        def test_foo(self):
            loglevel = self.optval('loglevel')
            # ...


You can also tag your tag your test for fine filtering

With those tag::

    from logilab.common.testlib import tag, TestCase

    class Exemple(TestCase):

        @tag('rouge', 'carre')
        def toto(self):
            pass

        @tag('carre', 'vert')
        def tata(self):
            pass

        @tag('rouge')
        def titi(test):
            pass

you can filter the function with a simple python expression

 * ``toto`` and ``titi`` match ``rouge``
 * ``toto``, ``tata`` and ``titi``, match ``rouge or carre``
 * ``tata`` and ``titi`` match``rouge ^ carre``
 * ``titi`` match ``rouge and not carre``
�)�print_functionzrestructuredtext ena\%prog [OPTIONS] [testfile [testpattern]]

examples:

pytest path/to/mytests.py
pytest path/to/mytests.py TheseTests
pytest path/to/mytests.py TheseTests.test_thisone
pytest path/to/mytests.py -m '(not long and database) or regr'

pytest one (will run both test_thisone and test_thatone)
pytest path/to/mytests.py -s not (will skip test_notthisone)
Fz.pytest.restartN)�time�clock)�isgeneratorfunction�isclass)�contextmanager)�abspath_listdir)�	textutils)�testlib�
STD_BLACKLIST)�unittest�start_interactive_mode)�
deprecated�__package__z7You have to install python-unittest2 to use this module)�modpath_from_file�load_module_from_modpathTz
pytestconf.pyc	csNt��}t�|�z
dVWd|dk	r>t|�s>t|d�r>|j}t�|�XdS)z<A context manager that temporary replaces the trace functionN�pytrace)�sys�gettrace�settrace�callable�hasattrr)�traceZoldtrace�r�F/opt/alt/python37/lib/python3.7/site-packages/logilab/common/pytest.py�
replace_trace�s


rcCst�S)z3A context manager that temporary pauses any tracing)rrrrr�pause_trace�src@s8eZdZgZeed�dd���Zeed�dd���ZdS)�TraceControllerz2[lgc 0.63.1] Use the pause_trace() context managercCs |j�t��|jd��dS)N���)�	ctx_stack�appendr�	__enter__)�clsrrr�
pause_tracing�szTraceController.pause_tracingcCs|j���ddd�dS)N)r�pop�__exit__)r"rrr�resume_tracing�szTraceController.resume_tracingN)�__name__�
__module__�__qualname__r�classmethodrr#r&rrrrr�s
rcs*t�d�r�Sd�_�fdd�}d|_|S)z0Function decorator that pauses tracing functions�	uncoveredTc	st���||�SQRXdS)N)r)�args�kwargs)�funcrr�not_covered�sznocoverage.<locals>.not_covered)rr+)r.r/r)r.r�
nocoverage�s
r0z^((unit)?test.*|smoketest)\.py$cCst�t�|��S)z2returns True if `filename` seems to be a test file)�TESTFILE_RE�match�osp�basename)�filenamerrr�this_is_a_testfile�sr6z^(unit)?tests?$cCst�t�|��S)z7returns True if `filename` seems to be a test directory)�
TESTDIR_REr2r3r4)�dirpathrrr�this_is_a_testdir�sr9cCs8i}tt|d���|�d|kr,|d|�|�dt�S)zRloads a ``pytestconf.py`` file and update default parser
    and / or tester.
    �rbZ
update_parserZCustomPyTester)�exec�open�read�get�PyTester)�path�parser�	namespacerrr�load_pytest_conf�s
rCcCs�t�|�}}t}t�|t�}t�|�r2t||�}xdt|�sNt�t�|d��r�t�t�|t	j
��}||krlP|}|}t�|t�}t�|�r4t||�}q4W||fS)z1try to find project's root and add it to sys.pathz__init__.py)r3�abspathr?�join�	CONF_FILE�isfilerCr9�normpath�os�pardir)rAZprojdir�previousdir�curdir�	testerclsZconf_file_path�newdirrrr�project_root�s 



rOc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�GlobalTestReportz'this class holds global test statisticscCs4d|_d|_d|_d|_d|_d|_d|_g|_dS)Nr)�ran�skipped�failures�errors�ttime�ctime�modulescount�
errmodules)�selfrrr�__init__�szGlobalTestReport.__init__cCs�|j}|j|7_|jtt|dd��7_|jt|j�7_|jt|j�7_|j|7_|j|7_|j	d7_	|�
�s�t|j�t|j�}|j�|dd�||f�dS)z8integrates new test information into internal statisticsrRr�N���)
�testsRunrQrR�len�getattrrSrTrUrVrW�
wasSuccessfulrXr )rYr5Z
testresultrUrVrQZproblemsrrr�feedszGlobalTestReport.feedcCsH|jd7_|jd7_|jd7_|j�|dd�ddf�dS)zFcalled when the test module could not be imported by unittest
        r[Nr\)rTrWrQrXr )rYr5rrr�failed_to_test_modulesz&GlobalTestReport.failed_to_test_modulecCs:|jd7_|jd7_|j�|dd�ddf�dS)Nr[r\r)rWrQrXr )rYr5rrr�skip_moduleszGlobalTestReport.skip_modulecCs�d|j|j|jfg}|jr,|�d|j�|jrB|�d|j�|jrX|�d|j�|jt|j	�}|jst|jr�d|t|j	�f}d�
dd�|j	D��}d	|}n|r�d
|}d}ndSdd�
|�||fS)
zthis is just presentation stuffz&Ran %s test cases in %.2fs (%.2fs CPU)z	%s errorsz%s failuresz
%s skippedz%s modules OK (%s failed)z, cSsg|]}d|�qS)z
%s [%s/%s]r)�.0�inforrr�
<listcomp>-sz,GlobalTestReport.__str__.<locals>.<listcomp>z
failures: %szAll %s modules OK�z%s
%s%s)rQrUrVrTr rSrRrWr^rXrE)rYZline1Z	modulesokZline2�descrZline3rrr�__str__s&
zGlobalTestReport.__str__N)	r'r(r)�__doc__rZrarbrcrirrrrrP�s
rPcCsXxRttj���D]@\}}|dkr"qt|d�s.q|j}t�|�rH|�|�rtj|=qWdS)abremove all modules from cache that come from `testdir`

    This is used to avoid strange side-effects when using the
    testall() mode of pytest.
    For instance, if we run pytest on this tree::

      A/test/test_utils.py
      B/test/test_utils.py

    we **have** to clean sys.modules to make sure the correct test_utils
    module is ran in B
    N�__file__)	�listr�modules�itemsrrkr3�isabs�
startswith)�testdir�modname�modZmodfilerrr�remove_local_modules_from_sys8s

rtc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zeee�Z	ddd�Z
dd
d�Zddd�ZdS)r?zencapsulates testrun logiccCs$t�|_||_||_d|_d|_dS)NT)rP�report�cvg�options�
firstwrite�_errcode)rYrvrwrrrrZVs
zPyTester.__init__cCstd�t|j�dS)z2prints the report and returns appropriate exitcodezO*******************************************************************************N)�printru)rYrrr�show_report]szPyTester.show_reportcCs |jdk	r|jS|jj|jjS)N)ryrurSrT)rYrrr�get_errcodecs
zPyTester.get_errcodecCs
||_dS)N)ry)rY�errcoderrr�set_errcodeiszPyTester.set_errcodeFcCs�t��}xnt�|�D]`\}}}xtD]}||kr$|�|�q$Wt�|�}t|�rtd|�|�	||�shPg|dd�<qW|j
jdkr�td|�|�	|�dS)z�walks through current working directory, finds something
        which can be considered as a testdir and runs every test there
        z
going intoNrzno test dir found testing here:)rI�getcwd�walkr�remover3r4r9rz�
testonedirrurQ)rY�	exitfirst�here�dirname�dirs�_rRr4rrr�testallms



zPyTester.testallc
Cs�x�t|�D]�}t|�r
|jjrp|jjspyttd�}|��Wn2tk
rnt	dt
�t�
�t�tjd��YnX|j|dd�}|r�|dks�|j��s�dSd|_q
Wt|�dS)z�finds each testfile in the `testdir` and runs it

        return true when all tests has been executed, false if exitfirst and
        some test has failed.
        �wz-Error while overwriting succeeded test file :)�fileT)�	batchmodeNF)rr6rwr��restartr<�FILE_RESTART�close�	Exceptionrzr3rErIrr�
__stderr__�testfile�resultr`rxrt)rYrqr�r5�restartfile�progrrrr��s"


zPyTester.testonedirc
Cs�t��}t�|�}|r t�|�|jjr�|jjs�|jr�yt	t
d�}|��Wn2tk
r~t
dt�t��t
�tjd��YnXt�|�dd�}t
dt�|��dd�tjd��zt�t�}}yt|||j|jtjd	�}	Wn�tk
r��Yn�tk
�r"}
z|
j|_�Wdd}
~
XYnttjk
�rNt
d
|�|j�|�dStk
�r�|j� |�t
d|tjd�ddl!}|j"tjd�dSXt�t�}}
|||
|}}|j�#||	j$||�|	S|�r�t�|�XdS)
zmruns every test in `filename`

        :param filename: an absolute path pointing to a unittest file
        r�z-Error while overwriting succeeded test file :)r�Nr\z  %s  �F�=)r�rvrw�	outstreamzModule skipped:z*unhandled exception occurred while testingr)%rIrr3r��chdirrwr�r�rxr<r�r�r�rzrErr�r4�centerrr�SkipAwareTestProgramrv�stderr�KeyboardInterrupt�
SystemExit�coder}r
ZSkipTestrurcrb�	traceback�	print_excrar�)rYr5r�r�r�r�rr�tstart�cstart�testprog�excr��tend�cendrUrVrrrr��sT






zPyTester.testfileN)F)F)F)
r'r(r)rjrZr{r|r~�propertyr}r�r�r�rrrrr?Ss


r?c@sBeZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zddd
�ZdS)�DjangoTestercCs�t�|�}|}xTt�t�|d��sbt�t�|d��rbt�t�|tj��}||krXtd��|}|}qWtt	t�|d���}ddl
m}||�d|_||_
|tjkr�tj�d|�dS)	z)try to find project's setting and load itzsettings.pyz__init__.pyzcould not find settings.pyr)�
setup_environFr[N)r3rDrGrErHrIrJ�AssertionErrorrrZdjango.core.managementr��DEBUG�settingsrr@�insert)rYr�rLrKrNr�r�rrr�load_django_settings�s 

z!DjangoTester.load_django_settingscCs6ddlm}ddlm}|�|dd�|jj|_dS)Nr)�setup_test_environment)�create_test_db)�	verbosity)�django.test.utilsr�r�r�ZTEST_DATABASE_NAME�dbname)rYr�r�rrr�before_testfile�s

zDjangoTester.before_testfilecCs<ddlm}ddlm}|�td|j�||jdd�dS)Nr)�teardown_test_environment)�destroy_test_dbZ
destroying)r�)r�r�r�rzr�)rYr�r�rrr�after_testfile�s
zDjangoTester.after_testfileFcCs�x�t�t���D]�\}}}xdD]}||kr |�|�q Wd|kr^|�||�sPPg|dd�<qt�|�}|dkrtd|�|�||�s�Pg|dd�<qWdS)z�walks through current working directory, finds something
        which can be considered as a testdir and runs every test there
        )�CVSz.svnz.hgztests.pyN)�test�testsz
going into)rIr�rr�r�r3r4rz)rYr�r�r��filesrRr4rrrr��s


zDjangoTester.testallcCs�dd�t|�D�}t|�dkrJy|�t�|d��Wntk
rHYnXx4|D],}|j|dd�}|rP|dksx|j��sPdSqPWt	|�dS)	z�finds each testfile in the `testdir` and runs it

        return true when all tests has been executed, false if exitfirst and
        some test has failed.
        cSsg|]}t|�r|�qSr)r6)rdZfpathrrrrfsz+DjangoTester.testonedir.<locals>.<listcomp>r[ztests.pyT)r�NF)
rr^r�r3rE�
ValueErrorr�r�r`rt)rYrqr�Z	testfilesr5r�rrrr�s
zDjangoTester.testonedirc
CsJt��}t�|�}|r t�|�|�|�t�|�dd�}tdt�|��dd�t	j
d�z�y^t�t�}}|�
�t|||jd�}t�t�}	}
|	||
|}}|j�||j||�|Stk
r��YnVtk
�r&}
z6ddl}|��|j�|�td	|�td
|
�dSd}
~
XYnXWd|��|�rDt�|�XdS)zmruns every test in `filename`

        :param filename: an absolute path pointing to a unittest file
        Nr\z  %s  r�r�)r�)r�rvrz*unhandled exception occurred while testingz	error: %s)rIrr3r�r�r�r4rzr�rr�rrr�r�rvrurar�r�r�r�r�rbr�)rYr5r�r�r�rrr�r�r�r�r�rUrVr�r�rrrr�(s:




zDjangoTester.testfileN)F)F)F)	r'r(r)r�r�r�r�r�r�rrrrr��s

r�c	s<ddlm}|td�}g|_dd��dd�}�fdd	�}|jd
ddd
d�|jdddddd�|jdd�ddd�|jdd|dddd�|jdd |d!ddd"d#�|jd$d%|d&ddd'd#�|jd(�dd)d�|jd*d+d,d-dd.d/�|jd0d1�dd2d�|jd3d4dd5d6d7�|jd8d9dd:d;d7�t�r8|jd<d=d>ddd?d�|S)@z&creates the OptionParser instance
    r)�OptionParser)�usagecSs|j�|�dS)z!carry the option to unittest_mainN)�newargsr )�option�opt�valuerArrr�rebuild_cmdlineTsz$make_parser.<locals>.rebuild_cmdlinecSs |j�|�t|j|jd�dS)zXcarry the option to unittest_main and store
        the value on current parser
        TN)r�r �setattr�values�dest)r�r�r�rArrr�rebuild_and_storeXsz&make_parser.<locals>.rebuild_and_storecst�dt��||||�dS)N�ignore)�warnings�simplefilter�DeprecationWarning)r�r�r�rA)r�rr�capture_and_rebuild_sz(make_parser.<locals>.capture_and_rebuildz-trqNz'directory where the tests will be found)r��default�helpz-d�dbcF�
store_truezenable design-by-contract)r�r��actionr�z-vz	--verbose�callbackzVerbose output)r�r�r�z-iz--pdb�pdbzEnable test failure inspection)r�r�r�r�z-xz--exitfirstr�zEExit on first failure (only make sense when pytest run one test file))r�r�r�r�r�z-Rz	--restartr�ztRestart tests from where it failed (implies exitfirst) (only make sense if tests previously ran with exitfirst only)z--colorzcolorize tracebacksz-sz--skip�storerRzRtest names matching this name will be skipped to skip several patterns, use commas)r�r�r�r�z-qz--quietzMinimal outputz-Pz	--profile�profilez2Profile execution and store data in the given file)r�r�r�z-mz--match�tags_patternz5only execute test whose tag match the current patternz-Jz--django�djangoz use pytest for django test cases)�optparser��
PYTEST_DOCr��
add_option�DJANGO_FOUND)r�rAr�r�r)r�r�make_parserMsN











r�cCs�|��\}}dd�|D�}|rHt|�dkr4|�d�|d}|�|�nd}|jt_|j}|jrp|�	d|jg�|j
r|d|_||7}||fS)	z}Parse the command line and return (options processed), (options to pass to
    unittest_main()), (explicitfile or None).
    cSsg|]}|�d�r|�qS)z.py)�endswith)rd�argrrrrf�szparseargs.<locals>.<listcomp>r[zonly one filename is acceptablerNz--skipT)�
parse_argsr^�errorr�r�r
�
ENABLE_DBCr�rR�extendr�r�)rArwr,�	filenames�explicitfiler�rrr�	parseargs�s 
r�c	CsJt�}t|�\}}t|�\}}|jtjdd�<d}dtjkrJtj�dd�tr`|j	r`t
||�}n
|||�}|r~|j|f}}n,|jr�|j
|j|jf}}n|j|jf}}z�yL|jr�ddl}	|	�|j�}
|
j|f|��|
��td|j�n||�Wn2tk
�r�Ynddl}|��YnXWd|��t�|j�XdS)Nr[rgrzprofile data saved in)r�rOr�r�r�argvr@r�r�r�r�r�rqr�r�r�r��hotshotZProfileZruncallr�rzr�r�r�r{�exitr})rAZrootdirrMrwr�rv�tester�cmdr,r�Zprofr�rrr�run�s>


r�csHeZdZdZdddddejf�fdd�	Zdd�Zd	d
�Zdd�Z	�Z
S)
r�azUsage: %(progName)s [options] [test] [...]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -i, --pdb        Enable test failure inspection
  -x, --exitfirst  Exit on first failure
  -s, --skip       skip test matching this pattern (no regexp for now)
  -q, --quiet      Minimal output
  --color          colorize tracebacks

  -m, --match      Run only test whose tag match this pattern

  -P, --profile    FILE: Run the tests using cProfile and saving results
                   in FILE

Examples:
  %(progName)s                               - run default set of tests
  %(progName)s MyTestSuite                   - run suite 'MyTestSuite'
  %(progName)s MyTestCase.testSomething      - run MyTestCase.testSomething
  %(progName)s MyTestCase                    - run all 'test*' test methods
                                               in MyTestCase
�__main__NFcs4||_||_||_||_tt|�j||t�d�dS)N)�module�defaultTest�
testLoader)r�rvrwr��superr�rZ�NonStrictTestLoader)rYr�r�r�rvrwr�)�	__class__rrrZ�s
zSkipAwareTestProgram.__init__c	Cs�d|_d|_g|_d|_d|_d|_d|_ddl}�y�|�|dd�dddddd	d
ddd
dg
�\}}x�|D]�\}}|dkr�|��|dkr�d|_|dkr�d|_|dkr�d|_	d|_|dkr�d|_
|dkr�d|_
|dkr�dd�|�d�D�|_|dkr�d|_|dk�r||jd<|dkrj||_qjW|j|j
_t|�dk�r�|jdk�r�t|jdd�}t|tjtjf��rt|j��|_n|j
�|j�|_dSt|�dk�r�|d|_||_n
|jf|_|��Wn0|jk
�r�}z|�|�Wdd}~XYnXdS) NFrr[zhHvixrqcp:s:m:P:r��verbose�quietr�r�r�zskip=�colorzmatch=zprofile=)z-hz-Hz--help)z-iz--pdbT)z-xz--exitfirst)z-rz	--restart)z-qz--quiet)z-vz	--verbose�)z-sz--skipcSsg|]}|���qSr)�strip)rd�patrrrrfsz2SkipAwareTestProgram.parseArgs.<locals>.<listcomp>z, z--color)z-mz--matchZtag_pattern)z-Pz	--profile�suite)�pdbmoder��skipped_patterns�test_patternr��colorize�profile_name�getoptZ	usageExitr�r��splitrwr�r^r�r_r��
isinstance�types�FunctionType�
MethodTyper�r�ZloadTestsFromModuleZ	testNamesZcreateTestsr�)	rYr�r�rwr,r�r�Z	suitefunc�msgrrr�	parseArgs�sf





zSkipAwareTestProgram.parseArgscCs2|jr&ddl}|�dt�t�|j�n|��SdS)Nrzself._runTests())r��cProfileZrunctx�globals�locals�	_runTests)rYrrrr�runTests.szSkipAwareTestProgram.runTestscs&t|j|j|j|j|j|j|j|j|j	|j
d�
|_�fdd��t|j
dd�r�y@t
td�}z&tdd�|��D��}�|j|�Wd|��XWn>tk
r�}z td	t�t��t�|f��Wdd}~XYnX|j�|j�}|`t|d
d�r�t|dd�r�t|�t|dd��st�|���||_dS)
N)
r��streamr�r�rvr�r�r�r�rwcs�t|tj�r�|j|�t|t�r�xd|dd�D]T}t|tj�rL�||�q0t|tj�r0d�|jj|jj	|j
f�}||kr0|�|�q0WdS)z` Recursive function that removes succTests from
            a TestSuite or TestCase
            N�.)rr�	TestSuite�_testsrl�TestCaserEr�r(r'Z_testMethodNamer�)�objZ	succTests�elrh)�removeSucceededTestsrrrAs


z<SkipAwareTestProgram._runTests.<locals>.removeSucceededTestsr�F�rcss|]}|�d�VqdS)z

N)�rstrip)rd�elemrrr�	<genexpr>Wsz1SkipAwareTestProgram._runTests.<locals>.<genexpr>z/Error while reading succeeded tests into %s: %sZ	debuggersr�r�)�SkipAwareTextTestRunnerr�r�r�r�rvr�r�r�r�rwZ
testRunnerr_r<r�rl�	readlinesr�r�r�r3rErIrr�r
rr�r`r�)rYr�Zsucceededtests�exr�r)rrr
5s<
*zSkipAwareTestProgram._runTests)r'r(r)�USAGErr�rZrrr
�
__classcell__rr)r�rr��s	8r�c
s^eZdZejdddddddddf
�fdd�	Zdd�Zdd
d�Zdd
�Zdd�Z	dd�Z
�ZS)rr[FNrcsHtt|�j||d�||_||_||_||_||_||_|	|_	|
|_
dS)N)rr�)r�rrZr�r�rvr�r�r�r�rw)rYrr�r�r�rvr�r�r�r�rw)r�rrrZnsz SkipAwareTextTestRunner.__init__cst�fdd�|jD��S)Ncsg|]}|�k�qSrr)rdr�)�
testednamerrrf~sz<SkipAwareTextTestRunner._this_is_skipped.<locals>.<listcomp>)�anyr�)rYrr)rr�_this_is_skipped}sz(SkipAwareTextTestRunner._this_is_skippedTcCst|tj�r|j}n~t|tj�r:|��}d|j|jf}nBt|tj�rR|}|j}n*t|tj	�rx|j
j}d|j|jf}ndSt|�r�|r�|�
|�S|�|�r�dS|jdk	�r
y6|j�d�\}}|�d�\}	}
||	ks�||
kr�dSWn&tk
�r|j|k�rdSYnX|�
|�S)Nz%s.%sTFr
)rr
Z	InnerTest�namerZ_get_test_methodr'rrr�__self__r�r�does_match_tagsrr�rr�)rYr�Z
skipgenerator�testname�methr.r"ZclasspatternZtestpattern�klassr rrr�
_runcondition�s4


z%SkipAwareTextTestRunner._runconditioncCsf|jdk	rbt|jdd�}|dk	rbt|dt���}|jrXt|tj�rX|t|jdt���B}|�	|�SdS)Nr��tagsT)
rwr_r
ZTagsZinheritrrrZim_classr2)rYr�r�r'rrrr"�s

z'SkipAwareTextTestRunner.does_match_tagsc	Cs$t�|j|j|j|j|j|j|j�S)N)	r
�SkipAwareTestResultrZdescriptionsr�r�r�rvr�)rYrrr�_makeResult�sz#SkipAwareTextTestRunner._makeResultc
Cs�|��}t�}|||j|jd�t�}||}|��|j�s�|j�|j�|j	}|j�d||dkrhdpjd|f�|j��|�
�s�|jr�|j�t
jddd��q�|j�d�n*|jr�|j�t
jd	d
d��n|j�d	�tt|j|j|jf�\}}}	g}
xFd|jfd|jfd
|jffD]&\}}|�r|
�d|t|�f��qW|
�rt|j�d�|j�d�|
��|j�d�|j�d�|S)z&Run the given test case or test suite.)�runconditionrwzRan %d test%s in %.3fsr[�srgZFAILEDZred)r�ZOKZgreenrSrTrRz%s=%iz (z, �))r)rr&rwZprintErrorsr�r�writelnZ
separator2r]r`r��writer	Z
colorize_ansi�mapr^rSrTrRr rE)
rYr�r�Z	startTimeZstopTimeZ	timeTakenr��failedZerroredrRZdet_resultsr r�rrrr��sD

zSkipAwareTextTestRunner.run)T)r'r(r)rr�rZrr&r"r)r�rrr)r�rrls

rcsXeZdZdZdd�Zddd�Zdd�Zd	d
�Zd�fdd�	Zd
d�Z	�fdd�Z
�ZS)r�a�
    Overrides default testloader to be able to omit classname when
    specifying tests to run on command line.

    For example, if the file test_foo.py contains ::

        class FooTC(TestCase):
            def test_foo1(self): # ...
            def test_foo2(self): # ...
            def test_bar1(self): # ...

        class BarTC(TestCase):
            def test_bar2(self): # ...

    'python test_foo.py' will run the 3 tests in FooTC
    'python test_foo.py FooTC' will run the 3 tests in FooTC
    'python test_foo.py test_foo' will run test_foo1 and test_foo2
    'python test_foo.py test_foo1' will run test_foo1
    'python test_foo.py test_bar' will run FooTC.test_bar1 and BarTC.test_bar2
    cCs
d|_dS)Nr)r�)rYrrrrZ�szNonStrictTestLoader.__init__NcCs.g}x|D]}|�|�||��q
W|�|�S)N)r��loadTestsFromNameZ
suiteClass)rY�namesr�Zsuitesr rrr�loadTestsFromNames�s
z&NonStrictTestLoader.loadTestsFromNamescCs�i}x�t|���D]�}t|�rt|tj�r|j}|ddks|�|�rHqg}x8t|�D],}|�	|j
�rVt||�}t|�rV|�
|�qVW||f||<qW|S)Nrr�)�varsr�r�
issubclassrrr'r�dirrpZtestMethodPrefixr_rr )rYr�r�r�	classname�methodnames�attrname�attrrrr�_collect_tests�s
z"NonStrictTestLoader._collect_testscCsHyt||��}Wntk
r$gSXt|d�sBtd|j|f��|jS)Nrz%s.%s is not a valid TestSuite)r_�AttributeErrorrr�r'r)rYr�Z	suitenamer�rrr�loadTestsFromSuite
sz&NonStrictTestLoader.loadTestsFromSuitec	sP|�d�}|dkst|�dkr0tt|��|�gS|�|�}g}t|�dkr�|d�tt|�d��rv�|krv|�|��S�|kr�|�\�}xp|D]}�fdd�|D�}q�WnPx�|�	�D]B\�}x |j
D]��fdd�|D�}q�W|��fdd�|D�7}q�WnNt|�dk�rL|\}�|�|dgf�\�}x"|D]}��fd	d�|D�}�q.W|S)
Nr
r�r[rcsg|]}�|��qSrr)rd�
methodname)r%rrrf&sz9NonStrictTestLoader.loadTestsFromName.<locals>.<listcomp>csg|]}�|kr|�qSrr)rdr>)�skip_patternrrrf-scsg|]}�|kr�|��qSrr)rdr>)r%�patternrrrf0scsg|]}�|kr�|��qSrr)rdr>)r%r@rrrf8s)rr^r�r�r1r;rr_r=r�r�r>)	rYr r��partsr�Z	collectedr8r>r7)r�)r%r@r?rr1s6





z%NonStrictTestLoader.loadTestsFromNamecst�fdd�|jD��S)Ncsg|]}|�k�qSrr)rdr�)rrrrf=sz8NonStrictTestLoader._this_is_skipped.<locals>.<listcomp>)rr�)rYrr)rrr<sz$NonStrictTestLoader._this_is_skippedcsF|j�|j}|ddks �|�r$gStt|��|�}�fdd�|D�S)zLReturn a sorted sequence of method names found within testCaseClass
        rr�csg|]}�|�s|�qSrr)rdr#)�
is_skippedrrrfHsz8NonStrictTestLoader.getTestCaseNames.<locals>.<listcomp>)rr'r�r��getTestCaseNames)rYZ
testCaseClassr7Z	testnames)r�)rBrrC?s
z$NonStrictTestLoader.getTestCaseNames)N)N)r'r(r)rjrZr3r;r=r1rrCrrr)r�rr��s
'r�cCs*|j|||d�|�d|�|�|�|S)N)r*rw)�_wrapped_run�_tearDownPreviousClass�_handleModuleTearDown)rYr�r*rwrrr�_ts_runPs
rGc	Cs�x�|D]�}|jrPt�|�rd|�||�|�||�|�||�|j|_t|jdd�st|dd�rdqt	|d�r�y|j
||||d�Wq�tk
r�|�
||�Yq�Xq|s�y||||�Wq�tk
r�||�Yq�Xq|��qW|S)NZ_classSetupFailedFZ_moduleSetUpFailedrD)r*rw)
Z
shouldStop�unittest_suiteZ_isnotsuiterEZ_handleModuleFixtureZ_handleClassSetUpr�Z_previousTestClassr_rrD�	TypeError�debug)rYr�rJr*rwr�rrr�_ts_wrapped_runVs.

	
rK)r��cCsRd}t|dd�dkrd|_}|�||||�|rN|�d|�|�|�d|_|S)NF�_testRunEnteredT)r_rMrDrErF)rYr�rJr*rwZtopLevelrrrrG}s

cGsdtsdSyddlm}ddlm}Wn tk
rDtj�d�dSXx|D]}|�	||�qLWdS)a
    Without arguments, return True if contracts can be enabled and should be
    enabled (see option -d), return False otherwise.

    With arguments, return False if contracts can't or shouldn't be enabled,
    otherwise weave ContractAspect with items passed as arguments.
    Fr)�weaver)�ContractAspectz>Warning: logilab.aspects is not available. Contracts disabled.T)
r�Zlogilab.aspects.weaverrNZlogilab.aspects.lib.contractsrO�ImportErrorrr�r.Zweave_module)r,rNrOr�rrr�
enable_dbc�s
rQ)r��)N)NN)FNN)FNN)Xrj�
__future__r�
__docformat__r�r�r�rIr�re�os.pathr@r3rrr�r�inspectrr�
contextlibrZlogilab.common.fileutilsrZlogilab.commonr	r
rZlogilab.common.testlibrr
Zlogilab.common.deprecationrZdoctestZunittest_legacyr_Zunittest2.suiter�rHrPr�Zunittest.suiter�Zlogilab.common.modutilsrrr�rFrr�objectrr#r&r0�compiler1r6r7r9rCrrOrPrtr?r�r�r�r�ZTestProgramr�ZTextTestRunnerrZ
TestLoaderr�rGrK�version_inforQr(Z_TextTestResultrZDocTestCase�	__bases__ZFunctionTestCaserrDrrrr�<module>^s�



@yB&ky

#