a
    ñ»j7/  ã                   @   sö   d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ e d
¡Zg d¢ZG dd„ dejƒZG dd„ dejƒZe ZZdd„ Zddd„Zdd„ Ze dkròeƒ  dS )z+Implements nose test program and collector.é    N)ÚConfigÚall_config_files)ÚdefaultTestLoader)ÚPluginManagerÚDefaultPluginManager)ÚRestrictedPluginManager)ÚTextTestResult)ÚFinalizingSuiteWrapper)ÚisclassÚtolistz	nose.core)ÚTestProgramÚmainÚrunÚrun_exitÚ	runmoduleÚ	collectorÚTextTestRunnerc                   @   s4   e Zd ZdZejdddfdd„Zdd„ Zdd	„ ZdS )
r   zÄTest runner that uses nose's TextTestResult to enable errorClasses,
    as well as providing hooks for plugins to override or replace the test
    output stream, results, and the test case itself.é   Nc                 C   s*   |d u rt ƒ }|| _tj | |||¡ d S ©N)r   ÚconfigÚunittestr   Ú__init__)ÚselfÚstreamÚdescriptionsÚ	verbosityr   © r   ú/E:\soccer\ml_env\Lib\site-packages\nose/core.pyr      s    zTextTestRunner.__init__c                 C   s   t | j| j| j| jƒS r   )r   r   r   r   r   ©r   r   r   r   Ú_makeResult    s    ÿzTextTestRunner._makeResultc                 C   s–   | j j |¡}|dur|}| j j | j¡}|dur8|| _|  ¡ }t ¡ }z||ƒ W n tyf   Y n0 t ¡ }| ¡  | 	||¡ | j j 
|¡ |S )zXOverrides to provide plugin hooks and defer all output to
        the test result class.N)r   ÚpluginsÚprepareTestÚsetOutputStreamr   r   ÚtimeÚKeyboardInterruptZprintErrorsZprintSummaryÚfinalize)r   ÚtestÚwrapperÚwrappedÚresultÚstartÚstopr   r   r   r   %   s"    zTextTestRunner.run)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚsysÚstderrr   r   r   r   r   r   r   r      s
   
ÿ
r   c                   @   sb   e Zd ZdZdZddd„Zddd	„Zdd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZeeƒZdS )r   a·  Collect and run tests, returning success or failure.
    The arguments to TestProgram() are the same as to
    :func:`main()` and :func:`run()`:
    * module: All tests are in this module (default: None)
    * defaultTest: Tests to load (default: '.')
    * argv: Command line arguments (default: None; sys.argv is read)
    * testRunner: Test runner instance (default: None)
    * testLoader: Test loader instance (default: None)
    * env: Environment; ignored if config is provided (default: None;
      os.environ is read)
    * config: :class:`nose.config.Config` instance (default: None)
    * suite: Suite or list of tests to run (default: None). Passing a
      suite or lists of tests will bypass all test discovery and
      loading. *ALSO NOTE* that if you pass a unittest.TestSuite
      instance as the suite, context fixtures at the class, module and
      package level will not be used, and many plugin hooks will not
      be called. If you want normal nose behavior, either pass a list
      of tests, or a fully-configured :class:`nose.suite.ContextSuite`.
    * exit: Exit after running tests and printing report (default: True)
    * plugins: List of plugins to use; ignored if config is provided
      (default: load plugins with DefaultPluginManager)
    * addplugins: List of **extra** plugins to use. Pass a list of plugin
      instances in this argument to make custom plugins available while
      still using the DefaultPluginManager.r   NÚ.Tc                 C   sv   |d u rt j}|d u r"|  ||
¡}|r4|jj|d� || _|| _|	| _i }|	|d< tj	j
| f|||||dœ|¤Ž d S )N)ZextrapluginsÚexit)ÚmoduleÚdefaultTestÚargvÚ
testRunnerÚ
testLoader)ÚosÚenvironÚ
makeConfigr    Z
addPluginsr   Úsuiter3   r   r   r   )r   r4   r5   r6   r7   r8   Úenvr   r<   r3   r    Z
addpluginsÚ
extra_argsr   r   r   r   V   s&    ÿþýzTestProgram.__init__c                 C   s"   |pi }|  dd¡rg S tƒ S d S )NZNOSE_IGNORE_CONFIG_FILESF)Úgetr   )r   r=   r   r   r   ÚgetAllConfigFilesj   s    zTestProgram.getAllConfigFilesc                 C   s.   |   |¡}|rt|d�}ntƒ }t|||d�S )zALoad a Config pre-filled with user config files if any are found.)r    )r=   Úfilesr    )r@   r   r   r   )r   r=   r    Z	cfg_filesÚmanagerr   r   r   r;   q   s
    
zTestProgram.makeConfigc                 C   sH  | j j||  ¡ d� t d| j ¡ | j jjrhddlm} t	j
t	_tdtj t	jd ¡|f ƒ t	 d¡ | j jjr„|  ¡  t	 d¡ | jdu ržt| j d�| _nt| jƒr¸| j| j d�| _| j j | j¡}|durÖ|| _t d| j¡ | j jrø| j j| _nt| jƒ| _t d	| j¡ t d
| j¡ | j jdu�r<t | j j¡ |  ¡  dS )z5Parse argv and env and configure running environment.)Údoczconfigured %sr   )Ú__version__z%s version %sN)r   ztest loader is %szdefaultTest %szTest names are %s)r   Ú	configureÚusageÚlogÚdebugÚoptionsÚversionÚnoserD   r0   Ú
__stdout__ÚstdoutÚprintr9   ÚpathÚbasenamer6   r3   ÚshowPluginsr8   r   r
   r    ÚprepareTestLoaderÚ	testNamesr   r5   Z
workingDirÚchdirÚcreateTests)r   r6   rD   Zplug_loaderr   r   r   Ú	parseArgsz   s8    
ÿ




zTestProgram.parseArgsc                 C   s>   t  d| j¡ | jdur*| j | j¡| _n| j | j¡| _dS )zÀCreate the tests to run. If a self.suite is set,
        then that suite will be used. Otherwise, tests will be loaded from
        the given test names (self.testNames) using the test loader.zcreateTests called with %sN)rG   rH   r<   r8   Z
suiteClassr&   ÚloadTestsFromNamesrS   r   r   r   r   rU   š   s    
zTestProgram.createTestsc                 C   s~   t  d¡ | jdu r.t| jj| jj| jd�| _| jj | j¡}|durL|| _| j 	| j
¡}| ¡ | _| jrxt | j ¡ | jS )zfRun Tests. Returns true on success, false on failure, and sets
        self.success to the same value.zrunTests calledN)r   r   r   )rG   rH   r7   r   r   r   r   r    ÚprepareTestRunnerr   r&   ZwasSuccessfulÚsuccessr3   r0   )r   Zplug_runnerr)   r   r   r   ÚrunTests¤   s    

þ
zTestProgram.runTestsc              
   C   sü   ddl }G dd„ dƒ}| jj}| jj ¡  | jjD ]Ä}td|j ƒ |dkr2td|j ƒ td |j	| 
¡  ¡ d	d	d
�¡ƒ |dkrð|ƒ }| |¡ t|jƒrðtƒ  tdƒ |jD ]<\}}tdd |¡ ƒ |r²td |j	| ¡ ddd
�¡ƒ q²tƒ  q2dS )z Print list of available plugins.r   Nc                   @   s   e Zd Zdd„ Zdd„ ZdS )z,TestProgram.showPlugins.<locals>.DummyParserc                 S   s
   g | _ d S r   )rI   r   r   r   r   r   º   s    z5TestProgram.showPlugins.<locals>.DummyParser.__init__c                 _   s   | j  || dd¡f¡ d S )NÚhelpÚ )rI   ÚappendÚpop)r   ÚargÚkwr   r   r   Ú
add_option½   s    z7TestProgram.showPlugins.<locals>.DummyParser.add_optionN)r,   r-   r.   r   ra   r   r   r   r   ÚDummyParser¹   s   rb   z	Plugin %sé   z  score: %sÚ
z  )Úinitial_indentÚsubsequent_indenté   z
  Options:z  %sz, z    )Útextwrapr   r   r    ÚsortrN   ÚnameZscoreÚjoinÚwrapr[   ÚstripZ
addOptionsÚlenrI   )r   rh   rb   ÚvÚpÚparserÚoptsr[   r   r   r   rQ   µ   s8    þ



þÿzTestProgram.showPluginsc                 C   s–   dd l }z&|j}| tj tj t¡d¡¡}W nN ty|   t	tj tj t¡d¡dƒ}z| 
¡ }W | ¡  n
| ¡  0 Y n0 t|tƒs’| d¡}|S )Nr   z	usage.txtÚrzutf-8)rK   Ú
__loader__Úget_datar9   rO   rk   ÚdirnameÚ__file__ÚAttributeErrorÚopenÚreadÚcloseÚ
isinstanceÚstrÚdecode)ÚclsrK   ÚldÚtextÚfr   r   r   rF   Ø   s$    
ÿ
ÿÿ


zTestProgram.usage)Nr2   NNNNNNTNN)N)N)r,   r-   r.   r/   r   r   r@   r;   rV   rU   rZ   rQ   rF   Úclassmethodr   r   r   r   r   ;   s      þ


	 
#r   c                  O   s   d|d< t | i |¤ŽjS )a–  Collect and run tests, returning success or failure.
    The arguments to `run()` are the same as to `main()`:
    * module: All tests are in this module (default: None)
    * defaultTest: Tests to load (default: '.')
    * argv: Command line arguments (default: None; sys.argv is read)
    * testRunner: Test runner instance (default: None)
    * testLoader: Test loader instance (default: None)
    * env: Environment; ignored if config is provided (default: None;
      os.environ is read)
    * config: :class:`nose.config.Config` instance (default: None)
    * suite: Suite or list of tests to run (default: None). Passing a
      suite or lists of tests will bypass all test discovery and
      loading. *ALSO NOTE* that if you pass a unittest.TestSuite
      instance as the suite, context fixtures at the class, module and
      package level will not be used, and many plugin hooks will not
      be called. If you want normal nose behavior, either pass a list
      of tests, or a fully-configured :class:`nose.suite.ContextSuite`.
    * plugins: List of plugins to use; ignored if config is provided
      (default: load plugins with DefaultPluginManager)
    * addplugins: List of **extra** plugins to use. Pass a list of plugin
      instances in this argument to make custom plugins available while
      still using the DefaultPluginManager.
    With the exception that the ``exit`` argument is always set to False.Fr3   )r   rY   )r_   r`   r   r   r   r   î   s    r   Ú__main__c                 K   s   t f d| i|¤Ž dS )z¥Collect and run tests in a single module only. Defaults to running
    tests in __main__. Additional arguments to TestProgram may be passed
    as keyword arguments.r5   N)r   )rj   r`   r   r   r   r   
  s    r   c                  C   s\   d} t | d�}ttƒ |d�}|jdgd� t|ƒ}|jrF| |j¡}n
| d¡}t||jƒS )a  TestSuite replacement entry point. Use anywhere you might use a
    unittest.TestSuite. The collector will load options from
    all config files and execute loader.loadTestsFromNames() on the
    configured testNames, or '.' if no testNames are configured.)Úreportr!   rR   rX   r"   )Úexclude)rA   r    r   )r6   )r2   )	r   r   r   rE   r   rS   rW   r	   r%   )Zsetuptools_incompatr    ZconfÚloaderr<   r   r   r   r     s    

r   )r„   )!r/   Úloggingr9   r0   r#   r   Znose.configr   r   Znose.loaderr   Znose.plugins.managerr   r   r   Znose.resultr   Z
nose.suiter	   Z	nose.utilr
   r   Ú	getLoggerrG   Ú__all__r   r   r   r   r   r   r   r,   r   r   r   r   Ú<module>   s.   
' 1
