K9Qc@sdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZmZmZmZmZyddlmZWn!ek rddlmZnXddlZddlZejeZyddlZejWn)eefk rKddl j!j"ZnXej#Z$d e$fd YZ%e%e_#d ej&fd YZ'd e fdYZ(dejfdYZdej)fdYZ)dS(sUse the Doctest plugin with ``--with-doctest`` or the NOSE_WITH_DOCTEST environment variable to enable collection and execution of :mod:`doctests `. 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(t ContextList(tanypt getpackaget test_addresst resolve_nametsrcttolistt isproperty(tStringIOtNoseOutputRedirectingPdbcBs#eZdZdZdZRS(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|tjjdS(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 DoctestSuitecBsAeZdZeZddedZdZdZdZ 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|jS(N(RR(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytaddress|scCs t|jS(N(titert_tests(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt__iter__scCs t|jS(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 ZeZdZdZdZ dZ dZ dZ dZ dZRS( sO Activate doctest plugin to find and run doctests in non-test modules. c Cstj||||jdddddd|jddd |jd dd dd d ddd|jdddd|jdd ddd|jdddddd ddd|jddd ddd dddd|jd}|d k r|jd t|nd S(!s'Register commmandline options. s--doctest-teststactiont store_truetdestt doctest_teststdefaulttNOSE_DOCTEST_TESTSthelpsAlso 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_VARtVARsChange 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 (Rtparsertenvt env_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|jdr|j tt |dO_ nF|jdr|j tt |dM_ ntdd|fWqtk r4td|dfqXqWnd 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 DocTestFindertfindert optionflagsR;tjointsplitt startswithtgetattrt ValueErrortAttributeError(RR>tconfigtflagstflag((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRHs*        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.pytprepareTestLoadersccs+tjd||j|js6tjd|dSy|jj|}Wn"tk rptjd|dSX|stjd|dS|jt |j }g}xW|D]O}|j sqn|j s||_ n|j t|d|jd|jqW|r'|j|d|d tVndS( 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__texamplestfilenameR1t DocTestCaseRNR5RXR (RtmoduleRt module_filetcasesttest((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytloadTestsFromModules2       c cs|jrt|j|jrtjj|}t|}z|j}Wd|jXd}i|d6}|j rEtjj |\}}tjj |} t jj| ||j } y"t| ttdg}Wn,tk r } tjd| | t jnXtjd| |t|drE|j|}qEntj} | j|d|d|d|d d } | jrt| d |jd t|d ddt|ddd|j}|rt|fd|Vq|Vqt VndS(sLoad 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__tglobalstlocalst ImportErrorR\R]thasattrRlRKt DocTestParsert get_doctestRct DocFileCaseRNRRR5RR (RRdRmtdhtdoctfixture_contextRltbasetextR{tfixt_modteRBRitcase((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytloadTestsFromFilesL           c cst|ddt|}|jj|dt|d|}|rxO|D]D}t|jdkrnqMnt|d|d|jd|j VqMWnd S( sbLook for doctests in the given object, which will be a function, method or class. Rs Unnammed %sRfRmitobjRNR[N( RRttypeRMR_RtlenRcReRNR5(RRtparentRmtdoctestsRi((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytmakeTest.s$ c Cs|dkrtS|jsl|jjj| sl|jjotdg|jjD]}|j|^qNo|jj ptdg|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|jdrtS|jrtt|j|jrt|jj sptdg|jjD]}|j|^qQ rttSdS(sfOverride to select all modules and any file ending with configured doctest extension. s.pyN( RsRRIRRRRR(R(RtfileR((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytwantFileKs  )N(RRR'R(RIRRXR>RHRZRjRRR^R(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR)s +   ! 2 RecBsneZdZdd d d d ddZdZdZdZeZdZ dZ d Z d 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(RRiRNRoRqRRR[((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRds   cCs|jdk rt|jSt|jj}t|r|jjjd}dj|d }t|}t|}|d|ddj|d|dgfSt|SdS(Nt.iiii( RR(RRt_dt_testRmR RPRO(RRtpartst 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(RRmRdR(RRQ(RRmRdtpk((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytids    cCs:|j}|jd}d|ddj|d fS(NRs%s (%s)i(RRPRO(RRm((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt__repr__s cCsd|jS(Ns Doctest: %s(R(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pytshortDescriptionscCsA|jdk r*tj|_|jt_ntt|jdS(N( RR(Rt displayhookt_old_displayhookt _displayhookRReRo(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRos cCs2|dkrdStt|j|t|GHdS(N(R(tsetattrt builtin_modRtrepr(Rtvalue((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRs cCsEtt|j|jdk rA|jt_tt |jndS(N( RReRqRR(RRRtdelattrR(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRqs N( RRR'R(RR!RRR&RRoRRq(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRe]s      RcBsJeZdZddddddZdZdZdZdZRS( sfOverrides to provide address() method that returns the correct address for the doc file case. iRc Cs;||_tt|j|d|d|d|dddS(NRNRoRqR(RRRRR((RRiRNRoRqRR[((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRs cCs|jjddfS(N(RRdR((R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyR!scCsA|jdk r*tj|_|jt_ntt|jdS(N( RR(RRRRRRRo(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRos cCs2|dkrdStt|j|t|GHdS(N(R(RRRR(RR((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRs cCsEtt|j|jdk rA|jt_tt |jndS(N( RRRqRR(RRRRR(R((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRqs N( RRR'R(RR!RoRRq(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyRs    (*R't __future__RtloggingRtRRtinspectRtnose.plugins.baseRt nose.suiteRt nose.utilRRRRRR R t cStringIOR Rt __builtin__Rt getLoggerRR\RKReRTtnose.ext.dtcompatRtdtcompatt_OutputRedirectingPdbRR R RR)R(((s9/sys/lib/python2.7/site-packages/nose/plugins/doctests.pyt1s8    4       I