ó
ù¢TQc           @   s  d  d l  Z d  d l m Z d  d l m 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 m Z d  d l m  Z  d  d	 l m Z d  d
 l m Z d Z d Z e ƒ  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e  f d „  ƒ  YZ! d S(   iÿÿÿÿN(   t   settings(   t   ImproperlyConfigured(   t   get_appt   get_apps(   t   _doctest(   t   setup_test_environmentt   teardown_test_environment(   t   OutputCheckert   DocTestRunner(   t   unittest(   t   import_module(   t   module_has_submodulet   DjangoTestSuiteRunnert   testsc         C   s¤   |  j  j d ƒ } | d  | d } } y  t d j | t g ƒ ƒ } WnV t k
 rŸ | d k r{ t d j | ƒ ƒ } n |  } t | t ƒ s™ d  } q  ‚  n X| S(   Nt   .iÿÿÿÿt   models(   t   __name__t   splitR
   t   joint   TEST_MODULEt   ImportErrorR   t   None(   t
   app_modulet   partst   prefixt   lastt   test_modulet   app_root(    (    s+   ../Django//lib/python/django/test/simple.pyt	   get_tests   s     	c         C   s  t  j ƒ  } t |  d ƒ r1 | j |  j ƒ  ƒ nS | j t  j j |  ƒ ƒ y& | j t j |  d t	 d t
 ƒƒ Wn t k
 rƒ n Xt |  ƒ } | rt | d ƒ r» | j | j ƒ  ƒ q| j t  j j | ƒ ƒ y& | j t j | d t	 d t
 ƒƒ Wqt k
 rqXn  | S(   sR   
    Create a complete Django test suite for the provided application module.
    t   suitet   checkert   runner(   R	   t	   TestSuitet   hasattrt   addTestR   t   defaultTestLoadert   loadTestsFromModulet   doctestt   DocTestSuitet   doctestOutputCheckerR   t
   ValueErrorR   (   R   R   R   (    (    s+   ../Django//lib/python/django/test/simple.pyt   build_suite-   s0    

c   	   
   C   s  |  j  d ƒ } t | ƒ d k  s3 t | ƒ d k rF t d |  ƒ ‚ n  t | d ƒ } t | ƒ } t | | d d ƒ } | d k r¦ | r¦ t | | d d ƒ } q¦ n  y€ t | t j	 t
 j	 f ƒ r%t | ƒ d k ry t j ƒ  j | ƒ SWq"t k
 rt d |  ƒ ‚ q"Xq%| | d ƒ Sn  Wn t k
 r9n Xg  } x´ | | f D]¦ } yŒ t j | d t d	 t ƒ} xj | D]b } | j j d
 | j d j | d ƒ f d | j d j | d ƒ f f k rx| j | ƒ qxqxWWqMt k
 ròqMXqMW| st d |  ƒ ‚ n  t j | ƒ S(   sÞ   
    Construct a test case with the specified label. Label should be of the
    form model.TestClass or model.TestClass.test_method. Returns an
    instantiated test or test suite corresponding to the label provided.

    R   i   i   sN   Test label '%s' should be of the form app.TestCase or app.TestCase.test_methodi    i   s.   Test label '%s' does not refer to a test classR   R   s   %s.%ss   %s.__test__.%ss(   Test label '%s' does not refer to a testN(   R   t   lenR(   R   R   t   getattrR   t
   issubclassR	   t   TestCaset   real_unittestt
   TestLoadert   loadTestsFromTestCaset	   TypeErrorR%   R&   R'   R   t   _dt_testt   nameR   R   t   appendR    (	   t   labelR   R   R   t	   TestClassR   t   modulet   doctestst   test(    (    s+   ../Django//lib/python/django/test/simple.pyt
   build_testW   sP    $		#c         C   s   x‰ |  D] } t  | t j ƒ r2 t | | | ƒ q xS t t | ƒ ƒ D]. } t  | | | ƒ rE | | j | ƒ PqE qE W| d j | ƒ q Wd S(   s  
    Partitions a test suite by test type.

    classes is a sequence of types
    bins is a sequence of TestSuites, one more than classes

    Tests of type classes[i] are added to bins[i],
    tests with no match found in classes are place in bins[-1]
    iÿÿÿÿN(   t
   isinstanceR	   R    t   partition_suitet   rangeR*   R"   (   R   t   classest   binsR9   t   i(    (    s+   ../Django//lib/python/django/test/simple.pyR<   œ   s    
c         C   s}   t  | ƒ } g  t | d ƒ D] } t j ƒ  ^ q } t |  | | ƒ x- t | ƒ D] } | d j | | d ƒ qR W| d S(   sß   
    Reorders a test suite by test type.

    `classes` is a sequence of types

    All tests of type classes[0] are placed first, then tests of type
    classes[1], etc. Tests with no match in classes are placed last.
    i   i    (   R*   R=   R	   R    R<   t   addTests(   R   R>   t   class_countR@   R?   (    (    s+   ../Django//lib/python/django/test/simple.pyt   reorder_suite²   s    	)c         C   sA  g  } t  ƒ  } i  } xy |  D]q \ } \ } } t  ƒ  } x' | D] }	 | j | j |	 g  ƒ ƒ q> W| j | ƒ sƒ t d | ƒ ‚ n  | | | <q Wx© |  r<t }
 g  } xu |  D]m \ } \ } } | | j | ƒ r| j | ƒ | j | | | f f ƒ t }
 q­ | j | | | f f ƒ q­ W|
 s3t d ƒ ‚ n  | }  q” W| S(   so   
    Reorder test_databases into an order that honors the dependencies
    described in TEST_DEPENDENCIES.
    sH   Circular dependency: databases %r depend on each other, but are aliases.s(   Circular dependency in TEST_DEPENDENCIES(	   t   sett   updatet   gett
   isdisjointR   t   Falset   issubsetR4   t   True(   t   test_databasest   dependenciest   ordered_test_databasest   resolved_databasest   dependencies_mapt   sigt   _t   aliasest   all_depst   aliast   changedt   deferredt	   signaturet   db_name(    (    s+   ../Django//lib/python/django/test/simple.pyt   dependency_orderedÃ   s4    				
c           B   sh   e  Z d  e e d „ Z d „  Z d
 d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d
 d	 „ Z RS(   i   c         K   s   | |  _  | |  _ | |  _ d  S(   N(   t	   verbosityt   interactivet   failfast(   t   selfRZ   R[   R\   t   kwargs(    (    s+   ../Django//lib/python/django/test/simple.pyt   __init__î   s    		c         K   s   t  ƒ  t t _ t j ƒ  d  S(   N(   R   RH   R    t   DEBUGR	   t   installHandler(   R]   R^   (    (    s+   ../Django//lib/python/django/test/simple.pyR   ó   s    	c         K   sÈ   t  j ƒ  } | rg xy | D]G } d | k rA | j t | ƒ ƒ q t | ƒ } | j t | ƒ ƒ q Wn' x$ t ƒ  D] } | j t | ƒ ƒ qq W| rµ x | D] } | j | ƒ q› Wn  t | t  j f ƒ S(   NR   (	   R	   R    R"   R:   R   R)   R   RC   R-   (   R]   t   test_labelst   extra_testsR^   R   R5   t   appR9   (    (    s+   ../Django//lib/python/django/test/simple.pyR)   ø   s    c         K   sù  d d l  m } m } i  } i  } i  } xÃ | D]» } | | } | j d r` | j d | | <q/ | j | j j ƒ  | j d t ƒ  f ƒ }	 |	 d j | ƒ d | j k r¿ | j d | | <q/ | | k r/ | j j	 d | g ƒ | | <q/ q/ Wg  }
 g  } x› t
 | j ƒ  | ƒ D]„ \ } \ } } d  } xi | D]a } | | } |
 j | | t f ƒ | d  k rƒ| j j |  j d |  j ƒ} q/| | j d <q/WqWxT | j ƒ  D]F \ } } | j | | | j d f ƒ | | j d | | j d <q¥W|
 | f S(   Niÿÿÿÿ(   t   connectionst   DEFAULT_DB_ALIASt   TEST_MIRRORt   NAMEi   t   TEST_DEPENDENCIESt   autoclobber(   t	   django.dbRe   Rf   t   settings_dictt
   setdefaultt   creationt   test_db_signatureRD   t   addRF   RY   t   itemsR   R4   RJ   t   create_test_dbRZ   R[   (   R]   R^   Re   Rf   t   mirrored_aliasesRK   RL   RT   t
   connectiont   itemt	   old_namest   mirrorsRW   RX   RR   t   test_db_namet   mirror_alias(    (    s+   ../Django//lib/python/django/test/simple.pyt   setup_databases  sB    
	"
	 c         K   s%   t  j d |  j d |  j ƒ j | ƒ S(   NRZ   R\   (   R	   t   TextTestRunnerRZ   R\   t   run(   R]   R   R^   (    (    s+   ../Django//lib/python/django/test/simple.pyt	   run_suiteF  s    	c         K   sI   | \ } } x6 | D]. \ } } } | r | j  j | |  j ƒ q q Wd S(   s8   
        Destroys all the non-mirror databases.
        N(   Rn   t   destroy_test_dbRZ   (   R]   t
   old_configR^   Rv   Rw   Rt   t   old_namet   destroy(    (    s+   ../Django//lib/python/django/test/simple.pyt   teardown_databasesJ  s    c         K   s   t  j ƒ  t ƒ  d  S(   N(   R	   t   removeHandlerR   (   R]   R^   (    (    s+   ../Django//lib/python/django/test/simple.pyR   S  s    
c         K   s   t  | j ƒ t  | j ƒ S(   N(   R*   t   failurest   errors(   R]   R   t   resultR^   (    (    s+   ../Django//lib/python/django/test/simple.pyt   suite_resultW  s    c         K   s^   |  j  ƒ  |  j | | ƒ } |  j ƒ  } |  j | ƒ } |  j | ƒ |  j ƒ  |  j | | ƒ S(   s…  
        Run the unit tests for all the test labels in the provided list.
        Labels must be of the form:
         - app.TestClass.test_method
            Run a single specific test method
         - app.TestClass
            Run all the test methods in a given class
         - app
            Search for doctests and unittests in the named application.

        When looking for tests, the test runner will look in the models and
        tests modules for the application.

        A list of 'extra' tests may also be provided; these tests
        will be added to the test suite.

        Returns the number of tests that failed.
        (   R   R)   Rz   R}   R‚   R   R‡   (   R]   Rb   Rc   R^   R   R   R†   (    (    s+   ../Django//lib/python/django/test/simple.pyt	   run_testsZ  s    

N(   R   t
   __module__RJ   R_   R   R   R)   Rz   R}   R‚   R   R‡   Rˆ   (    (    (    s+   ../Django//lib/python/django/test/simple.pyR   í   s   		:					("   R	   R.   t   django.confR    t   django.core.exceptionsR   t   django.db.modelsR   R   t   django.testR   R%   t   django.test.utilsR   R   t   django.test.testcasesR   R   t   django.utilst   django.utils.importlibR
   t   django.utils.module_loadingR   t   __all__R   R'   R   R)   R:   R<   RC   RY   t   objectR   (    (    (    s+   ../Django//lib/python/django/test/simple.pyt   <module>   s&   			*	E			*