
    d,                         d 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Z
dZdZd	 Zd
 Zd Z G d de          ZeZdS )zUnittest main program    N   )loaderrunner)installHandlerTa  Examples:
  %(prog)s test_module               - run tests from test_module
  %(prog)s module.TestClass          - run tests from module.TestClass
  %(prog)s module.Class.test_method  - run specified test method
  %(prog)s path/to/test_file.py      - run tests from test_file.py
aF  Examples:
  %(prog)s                           - run default set of tests
  %(prog)s MyTestSuite               - run suite 'MyTestSuite'
  %(prog)s MyTestCase.testSomething  - run MyTestCase.testSomething
  %(prog)s MyTestCase                - run all 'test*' test methods
                                       in MyTestCase
c                 V   t           j                            |           r|                                                     d          rt           j                            |           rst           j                            | t          j                              }t           j                            |          s|                    t           j	                  r| S |} t           j        
                    |           d d                             dd                              dd          S | S )Nz.py\./)ospathisfilelowerendswithisabsrelpathgetcwd
startswithpardirnormpathreplace)namerel_paths       /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/unittest/main.py_convert_namer      s    
 
w~~d P

 5 5e < < P7== 	wtRY[[99Hw}}X&& (*=*=bi*H*H D w%%crc*224==EEc3OOOK    c                     d | D             S )Nc                 ,    g | ]}t          |          S  )r   ).0r   s     r   
<listcomp>z"_convert_names.<locals>.<listcomp>/   s     222DM$222r   r   )namess    r   _convert_namesr#   .   s    22E2222r   c                     d| vrd| z  } | S )N*z*%s*r   )patterns    r   _convert_select_patternr'   2   s    '>>7"Nr   c                       e Zd ZdZdZdZdxZxZxZxZ	xZ
ZdZddddej        ddddddfdddZdd	Zd
 Zd ZddZd Zd Zd Zd ZddZd ZdS )TestProgramzA command-line program that runs a set of tests; this is primarily
       for making test modules conveniently executable.
    Nr   __main__TF)	tb_localsc                V   t          |t                    rOt          |          | _        |                    d          dd          D ]}t          | j        |          | _        n|| _        |t          j        }|| _        || _	        |	| _
        || _        |
| _        || _        |t          j        sd| _        n|| _        || _        || _        || _        t&          j                            |d                   | _        |                     |           |                                  d S )Nr
   r   defaultr   )
isinstancestr
__import__modulesplitgetattrsysargvexitfailfast
catchbreak	verbositybufferr+   warnoptionswarningsdefaultTest
testRunner
testLoaderr   r   basenameprogName	parseArgsrunTests)selfr1   r=   r5   r>   r?   r6   r9   r7   r8   r:   r<   r+   parts                 r   __init__zTestProgram.__init__B   s    fc"" 	!$V,,DKS))!""- 9 9%dk4889 !DK<8D	 $""CO &DMM %DM&$$((a11tr   c                     t          j        dt                     |rt          |           | j        |                                  |                                  t          j        d           d S )NzHTestProgram.usageExit() is deprecated and will be removed in Python 3.13   )	r<   warnDeprecationWarningprint_discovery_parser_initArgParsers_print_helpr4   r6   )rD   msgs     r   	usageExitzTestProgram.usageExith   sr     01C	E 	E 	E 	#JJJ!)  """r   c                 Z   | j         _t          | j                                                   t          t          d| j        iz             | j                                         d S t          | j                                                   t          t          d| j        iz             d S )Nprog)	r1   rK   _main_parserformat_helpMAIN_EXAMPLESrA   rL   
print_helpMODULE_EXAMPLES)rD   argskwargss      r   rN   zTestProgram._print_helpr   s    ;$#//11222-64="99:::"--/////$#//11222/VT]$;;<<<<<r   c                    |                                   | j        t          |          dk    r=|d                                         dk    r|                     |dd                     d S | j                            |dd          |            | j        s|                     g            d S n#| j                            |dd          |            | j        r,t          | j                  | _	        t          dk    rd | _        nP| j        d | _	        nAt          | j        t                    r| j        f| _	        nt          | j                  | _	        |                                  d S )Nr   discoverrH   r*   )rM   r1   lenr   _do_discoveryrS   
parse_argstestsr#   	testNames__name__r=   r.   r/   listcreateTests)rD   r5   s     r   rB   zTestProgram.parseArgs{   s^   ;4yy1}}aJ!>!>""48,,,((abb4888:  ""2&&&	 ((abb4888: 	4+DJ77DN:%%"%!DNN(#.. 	4".0DNN!$"233DNr   c                 ^   | j         r| j         | j        _         |r;|| j        n	 |            } |j        | j        | j        | j                  | _        d S | j        &| j                            | j	                  | _        d S | j        
                    | j        | j	                  | _        d S N)testNamePatternsr?   r[   startr&   toptestr`   loadTestsFromModuler1   loadTestsFromNames)rD   from_discoveryLoaderr   s       r   rc   zTestProgram.createTests   s      	E/3/DDO, 	H(.T__FFHHF'
DL$(KKDIII^#;;DKHHDIII::4>;?;H HDIIIr   c                     |                                  }|                     |          | _        |                     |          | _        d S re   )_getParentArgParser_getMainArgParserrS   _getDiscoveryArgParserrL   )rD   parent_parsers     r   rM   zTestProgram._initArgParsers   sE    0022 22=AA!%!<!<]!K!Kr   c                    t          j        d          }|                    dddddd	           |                    d
ddddd	           |                    dddd           | j        !|                    ddddd           d| _        | j        !|                    ddddd           d| _        | j        !|                    ddddd           d| _        | j        &|                    dd d!t          d"#           g | _        |S )$NF)add_helpz-vz	--verboser9   store_constrH   zVerbose output)destactionconsthelpz-qz--quietr   zQuiet outputz--localsr+   
store_truez"Show local variables in tracebacks)rv   rw   ry   z-fz
--failfastr7   zStop on first fail or errorz-cz--catchr8   z'Catch Ctrl-C and display results so farz-bz--bufferr:   z%Buffer stdout and stderr during testsz-krf   appendz.Only run tests which match the given substring)rv   rw   typery   )argparseArgumentParseradd_argumentr7   r8   r:   rf   r'   )rD   parsers     r   ro   zTestProgram._getParentArgParser   s   (%888D+K#0!1 	 	3 	3 	3 	D)+#0!/ 	 	1 	1 	1 	J[#/!E 	 	G 	G 	G = l'3%B   D D D "DM?"il'3%N   P P P $DO;jx'3%L   N N N  DK (+='/6M%U   W W W %'D!r   c                     t          j        |g          }| j        |_        | j        |_        |                    ddd           |S )Nparentsr_   r%   z?a list of any number of test modules, classes and test methods.)nargsry   )r}   r~   rA   rR   rN   rV   r   )rD   parentr   s      r   rp   zTestProgram._getMainArgParser   sX    (&:::m ,G3"8 	 	9 	9 	9 r   c                 X   t          j        |g          }d| j        z  |_        d|_        |                    dddd           |                    d	d
dd           |                    dddd           dD ]/}|                    |dt           j        t           j                   0|S )Nr   z%s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directoryrg   z*Directory to start discovery ('.' default))rv   ry   z-pz	--patternr&   z+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrh   z<Top level directory of project (defaults to start directory))rg   r&   rh   ?)r   r-   ry   )r}   r~   rA   rR   epilogr   SUPPRESS)rD   r   r   args       r   rq   z"TestProgram._getDiscoveryArgParser   s    (&:::#dm3$ 	D"5G!M 	 	O 	O 	OD+I!N 	 	P 	P 	PD"9"4 	 	5 	5 	5 / 	8 	8C3(0(9%-%6   8 8 8 8 r   c                     d| _         d| _        d | _        |6| j        |                                  | j                            ||            |                     d|           d S )Nr
   ztest*.pyT)rl   rm   )rg   r&   rh   rL   rM   r^   rc   )rD   r5   rm   s      r   r]   zTestProgram._do_discovery   sp    
!%-$$&&&"--dD999V<<<<<r   c                 z   | j         rt                       | j        t          j        | _        t          | j        t                    r	 	 |                     | j        | j        | j	        | j
        | j                  }n=# t          $ r0 |                     | j        | j        | j	        | j
                  }Y nw xY wn+# t          $ r |                                 }Y nw xY w| j        }|                    | j                  | _        | j        r.t#          j        | j                                                    d S d S )N)r9   r7   r:   r<   r+   )r9   r7   r:   r<   )r8   r   r>   r   TextTestRunnerr.   r|   r9   r7   r:   r<   r+   	TypeErrorrunri   resultr6   r4   wasSuccessful)rD   r>   s     r   rC   zTestProgram.runTests   sY   ? 	?"$3DOdot,, 	)/I!%4>:>-8<:>-;?>	 "1 "K "KJJ
 ! I I I!%4>:>-8<:>- "1 "I "IJJJI  / / /!__..


/
 J nnTY//9 	6H2244455555	6 	6s0   
3A> =B< >7B85B< 7B88B< <CCre   )FN)ra   
__module____qualname____doc__r1   r9   r7   r8   r:   rA   r<   rf   rL   r   defaultTestLoaderrF   rP   rN   rB   rc   rM   ro   rp   rq   r]   rC   r   r   r   r)   r)   8   s>         FINRRHRzRFRXR;K(d#0HTd$$ >C$ $ $ $ $L   = = =  :
H 
H 
H 
HL L L
! ! !F	 	 	  *= = = =6 6 6 6 6r   r)   )r   r4   r}   r   r<    r   r   signalsr   
__unittestrU   rW   r   r#   r'   objectr)   mainr   r   r   <module>r      s      



  				          # # # # # #
   3 3 3  \6 \6 \6 \6 \6& \6 \6 \6| r   