Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@s�dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZmZmZyddlmZWn!ek
r�ddlmZnXddlZddlZeje�ZyddlZejWn)eefk
rKddl j!j"ZnXej#Z$d	e$fd
��YZ%e%e_#dej&fd��YZ'd
e
fd��YZ(dejfd��YZdej)fd��YZ)dS(s�Use the Doctest plugin with ``--with-doctest`` or the NOSE_WITH_DOCTEST
environment variable to enable collection and execution of :mod:`doctests
<doctest>`.  Because doctests are usually included in the tested package
(instead of being grouped into packages or modules of their own), nose only
looks for them in the non-test packages it discovers in the working directory.

Doctests may also be placed into files other than python modules, in which
case they can be collected and executed by using the ``--doctest-extension``
switch or NOSE_DOCTEST_EXTENSION environment variable to indicate which file
extension(s) to load.

When loading doctests from non-module files, use the ``--doctest-fixtures``
switch to specify how to find modules containing fixtures for the tests. A
module name will be produced by appending the value of that switch to the base
name of each doctest file loaded. For example, a doctest file "widgets.rst"
with the switch ``--doctest_fixtures=_fixt`` will load fixtures from the module
``widgets_fixt.py``.

A fixtures module may define any or all of the following functions:

* setup([module]) or setup_module([module])
   
  Called before the test runs. You may raise SkipTest to skip all tests.
  
* teardown([module]) or teardown_module([module])

  Called after the test runs, if setup/setup_module did not raise an
  unhandled exception.

* setup_test(test)

  Called before the test. NOTE: the argument passed is a
  doctest.DocTest instance, *not* a unittest.TestCase.
  
* teardown_test(test)
 
  Called after the test, if setup_test did not raise an exception. NOTE: the
  argument passed is a doctest.DocTest instance, *not* a unittest.TestCase.
  
Doctests are run like any other test, with the exception that output
capture does not work; doctest does its own output capture while running a
test.

.. note ::

   See :doc:`../doc_tests/test_doctest_fixtures/doctest_fixtures` for
   additional documentation and examples.

i�(t
generatorsN(t	getmodule(tPlugin(tContextList(tanypt
getpackagettest_addresstresolve_nametsrcttolistt
isproperty(tStringIOtNoseOutputRedirectingPdbcBs#eZd�Zd�Zd�ZRS(cCst|_tj||�dS(N(tFalset(_NoseOutputRedirectingPdb__debugger_usedt_orpt__init__(tselftout((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRZs	cCs&t|_tj|tj�j�dS(N(tTrueRRt	set_tracetsyst	_getframetf_back(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR^s	cCs|jrtj|�ndS(N(RRtset_continue(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRbs	(t__name__t
__module__RRR(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRYs		tDoctestSuitecBsAeZdZeZdded�Zd�Zd�Zd�Z	RS(s�
    Doctest suites are parallelizable at the module or file level only,
    since they may be attached to objects that are not individually
    addressable (like properties). This suite subclass is used when
    loading doctests from a module to ensure that behavior.

    This class is used only if the plugin is not fully prepared;
    in normal use, the loader's suiteClass is used.
    
    cCs,||_||_tjj|d|�dS(Nttests(tcontextt	can_splittunittestt	TestSuiteR(RRRR((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRws		cCs
t|j�S(N(RR(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytaddress|scCs
t|j�S(N(titert_tests(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt__iter__scCs
t|j�S(N(tstrR#(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt__str__�s(N(
RRt__doc__R
RtNoneRR!R$R&(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRjs
		tDoctestcBsbeZdZd	ZeZd�Zd�Zd�Z	d�Z
d�Zd�Zd�Z
d�ZRS(
sO
    Activate doctest plugin to find and run doctests in non-test modules.
    cCstj|||�|jdddddd|jd�dd	�|jd
ddddd
ddd�|jdddd|jd�d
ddd�|jdddddd
ddd�|jdddddd
dddd�|jd�}|d k	r|jdt|��nd S(!s'Register commmandline options.
        s--doctest-teststactiont
store_truetdestt
doctest_teststdefaulttNOSE_DOCTEST_TESTSthelps�Also look for doctests in test modules. Note that classes, methods and functions should have either doctests or non-doctest tests, not both. [NOSE_DOCTEST_TESTS]s--doctest-extensiontappendtdoctestExtensiontmetavartEXTsLAlso look for doctests in files with this extension [NOSE_DOCTEST_EXTENSION]s--doctest-result-variabletdoctest_result_vartNOSE_DOCTEST_RESULT_VARtVARs�Change the variable name set to the result of the last interpreter command from the default '_'. Can be used to avoid conflicts with the _() function used for text translation. [NOSE_DOCTEST_RESULT_VAR]s--doctest-fixtureststoretdoctestFixturestSUFFIXsgFind fixtures for a doctest file in module with this name appended to the base name of the doctest files--doctest-optionstdoctestOptionstOPTIONSs$Specify options to pass to doctest. s%Eg. '+ELLIPSIS,+NORMALIZE_WHITESPACE'tNOSE_DOCTEST_EXTENSIONN(Rtoptionst
add_optiontgetR(tset_defaultsR	(Rtparsertenvtenv_setting((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR>�s4cCs@tj|||�|j|_|j|_t|j�|_|j|_t	j
�|_d|_|j
r<dj|j
�jd�}x�|D]�}yx|jd�r�|jtt	|d�O_nF|jd�r�jtt	|d�M_ntdd|f��Wq�tk
r4td|df��q�Xq�Wnd	S(
sConfigure plugin.
        it,t+it-s+Must specify doctest options with starting s'+' or '-'.  Got %ssUnknown doctest option %sN(Rt	configureR5R-R	R2t	extensionR9tfixturestdoctestt
DocTestFindertfindertoptionflagsR;tjointsplitt
startswithtgetattrt
ValueErrortAttributeError(RR>tconfigtflagstflag((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRH�s*		
 
cCs|j|_dS(snCapture loader's suiteClass.

        This is used to create test suites from doctest files.
        
        N(t
suiteClass(Rtloader((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytprepareTestLoader�sccs+tjd|�|j|j�s6tjd|�dSy|jj|�}Wn"tk
rptjd|�dSX|s�tjd|�dS|j�t	|j
�}g}xW|D]O}|js�q�n|js�||_n|j
t|d|jd|j��q�W|r'|j|d|d	t�VndS(
s'Load doctests from the module.
        sloading from %ssDoctest doesn't want module %sNsAttribute error loading from %ssNo tests found in %sRNt
result_varRR(tlogtdebugtmatchesRRMtfindRTt	exceptiontsortRt__file__texamplestfilenameR1tDocTestCaseRNR5RXR
(RtmoduleRtmodule_filetcasesttest((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytloadTestsFromModule�s2


			ccs�|jr�|j|j�r�jj|�}t|�}z|j�}Wd|j�Xd}i|d6}|j
rEtjj|�\}}tjj|�}	t
jj|	�||j
}
y"t|
t�t�dg�}Wn,tk
r
}tjd|
|t
j�nXtjd|
|�t|d�rE|j|�}qEntj�}|j|d|d|d|d	d
�}
|
jr�|
d|jdt|d
d�dt|dd�d|j�}|r�|fd|�Vq�Vq�VndS(s�Load doctests from the file.

        Tests are loaded only if filename's extension matches
        configured doctest extension.

        NRbtnopsCould not import %s: %s (%s)s Fixture module %s resolved to %stglobstnameRdtlinenoiRNtsetUpt
setup_testttearDownt
teardown_testR[R(!RIRtendswithtostpathtbasenametopentreadtcloseR(RJtsplitexttdirnameRR1t
__import__tglobalstlocalstImportErrorR\R]thasattrRlRKt
DocTestParsertget_doctestRctDocFileCaseRNRRR5RR
(RRdRmtdhtdoctfixture_contextRltbasetextR{tfixt_modteRBRitcase((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytloadTestsFromFile�sL
	
	
		c	cs�t|ddt|��}|jj|dt|�d|�}|r�xO|D]D}t|j�dkrnqMnt|d|d|jd|j	�VqMWnd	S(
sbLook for doctests in the given object, which will be a
        function, method or class.
        RsUnnammed %sRfRmitobjRNR[N(
RRttypeRMR_RtlenRcReRNR5(RR�tparentRmtdoctestsRi((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytmakeTest.s$
cCs�|dkrtS|jsl|jjj|�sl|jjo�tdg|jjD]}|j|�^qN�o�|jjp�tdg|jjD]}|j|�^q��S(Ns__init__.py(	R
R-tconft	testMatchtsearchtincludetfilterR(texclude(RRmtinctexc((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR^;s(
c	Csx|jd�rtS|jrtt|j|j�rt|jjsptdg|jjD]}|j|�^qQ�rttSdS(sfOverride to select all modules and any file ending with
        configured doctest extension.
        s.pyN(	RsRRIRR�R�R�R(R�(RtfileR�((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytwantFileKs	
)N(RRR'R(RIRRXR>RHRZRjR�R�R^R�(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR)�s	+			!	2	
	RecBsneZdZddddddd�Zd�Zd�Zd�ZeZd�Z	d�Z
d	�Zd
�ZRS(s#Overrides DocTestCase to
    provide an address() method that returns the correct address for
    the doctest case. To provide hints for address(), an obj may also
    be passed -- this will be used as the test object for purposes of
    determining the test address, if it is provided.
    it_c
CsD||_||_tt|�j|d|d|d|d|�dS(NRNRoRqtchecker(t_result_vart	_nose_objtsuperReR(RRiRNRoRqR�R�R[((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRds
		cCs�|jdk	rt|j�St|jj�}t|�r�|jjjd�}dj|d �}t|�}t|�}|d|ddj|d|dg�fSt|�SdS(Nt.i�iii(	R�R(RRt_dt_testRmR
RPRO(RR�tpartst
class_nametclst	base_addr((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR!ls
cCsY|jj}|jj}|dk	rUt|�}|j|�sUd||f}qUn|S(Ns%s.%s(R�RmRdR(RRQ(RRmRdtpk((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytid�scCs:|j�}|jd�}d|ddj|d �fS(NR�s%s (%s)i�(R�RPRO(RRm((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt__repr__�scCsd|j�S(NsDoctest: %s(R�(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytshortDescription�scCsA|jdk	r*tj|_|jt_ntt|�j�dS(N(	R�R(Rtdisplayhookt_old_displayhookt_displayhookR�ReRo(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRo�scCs2|dkrdStt|j|�t|�GHdS(N(R(tsetattrtbuiltin_modR�trepr(Rtvalue((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR��scCsEtt|�j�|jdk	rA|jt_tt	|j�ndS(N(
R�ReRqR�R(R�RR�tdelattrR�(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRq�sN(
RRR'R(RR!R�R�R&R�RoR�Rq(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRe]s								R�cBsJeZdZdddddd�Zd�Zd�Zd�Zd�ZRS(	sfOverrides to provide address() method that returns the correct
    address for the doc file case.
    iR�c
Cs;||_tt|�j|d|d|d|dd�dS(NRNRoRqR�(R�R�R�RR((RRiRNRoRqR�R[((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR�s	cCs|jjddfS(N(R�RdR((R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR!�scCsA|jdk	r*tj|_|jt_ntt|�j�dS(N(	R�R(RR�R�R�R�R�Ro(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRo�scCs2|dkrdStt|j|�t|�GHdS(N(R(R�R�R�R�(RR�((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR��scCsEtt|�j�|jdk	rA|jt_tt	|j�ndS(N(
R�R�RqR�R(R�RR�R�R�(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRq�sN(	RRR'R(RR!RoR�Rq(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR��s				(*R't
__future__RtloggingRtRRtinspectRtnose.plugins.baseRt
nose.suiteRt	nose.utilRRRRRR	R
t	cStringIORRt__builtin__R�t	getLoggerRR\RKReRTtnose.ext.dtcompatR�tdtcompatt_OutputRedirectingPdbRRR RR)R�(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt<module>1s84
		�I

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.