U AT^+@stdZddlZddlZddlZddlmZmZddlmZdZ dZ dZ d d Z d d Z d dZGdddeZeZdS)zUnittest main programN)loaderrunner)installHandlerTaExamples: %(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 aFExamples: %(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 cCsxtj|rt|drttj|rXtj|t}tj|sP|tj rT|S|}|dd dd ddS|S)Nz.py\./) ospathisfilelowerendswithisabsrelpathgetcwd startswithpardirreplace)nameZrel_pathr%/usr/lib64/python3.8/unittest/main.py _convert_names rcCsdd|DS)NcSsg|] }t|qSr)r).0rrrr .sz"_convert_names..r)namesrrr_convert_names-srcCsd|krd|}|S)N*z*%s*r)patternrrr_convert_select_pattern1src @seZdZdZdZdZdZZZZ Z Z dZ dddde jddddddf dddd Zdd d Zd d ZddZdddZddZddZddZddZd ddZddZdS)! TestProgramzA command-line program that runs a set of tests; this is primarily for making test modules conveniently executable. Nr__main__TF) tb_localsc Cst|tr _main_parser format_help MAIN_EXAMPLESr7r? print_helpMODULE_EXAMPLES)r:argskwargsrrrrAos   zTestProgram._print_helpcCs||jdkrpt|dkrD|ddkrD||dddS|j|dd||js|gdSn|j|dd||jrt|j|_ t dkrd|_n6|j dkrd|_ n$t |j t r|j f|_ n t|j |_ |dS)Nrdiscoverr=r!)r@r'lenr _do_discoveryrE parse_argstestsr testNames__name__r3r$r%list createTests)r:r+rrrr8xs(       zTestProgram.parseArgscCst|jr|j|j_|r@|dkr"|jn|}||j|j|j|_n0|jdkr\|j|j |_n|j |j|j |_dSN) testNamePatternsr5rLstartrtoptestrQZloadTestsFromModuler'ZloadTestsFromNames)r:from_discoveryLoaderrrrrrTs   zTestProgram.createTestscCs$|}|||_|||_dSrU)_getParentArgParser_getMainArgParserrE_getDiscoveryArgParserr?)r:Z parent_parserrrrr@s zTestProgram._initArgParserscCstjdd}|jddddddd |jd d ddd d d |jddddd|jdkrn|jddddddd|_|jdkr|jddddddd|_|jdkr|jddddddd|_|jdkr|jdd d!td"d#g|_|S)$NF)add_helpz-vz --verboser/ store_constr=zVerbose output)destactionconsthelpz-qz--quietrz Quiet outputz--localsr" store_truez"Show local variables in tracebacks)rarbrdz-fz --failfastr-zStop on first fail or errorz-cz--catchr.z'Catch Ctrl-C and display results so farz-bz--bufferr0z%Buffer stdout and stderr during testsz-krVappendz.Only run tests which match the given substring)rarbtyperd)argparseArgumentParser add_argumentr-r.r0rVr)r:parserrrrr\sR          zTestProgram._getParentArgParsercCs2tj|gd}|j|_|j|_|jdddd|S)NparentsrPrz?a list of any number of test modules, classes and test methods.)nargsrd)rhrir7rDrArHrj)r:parentrkrrrr]szTestProgram._getMainArgParsercCsztj|gd}d|j|_d|_|jddddd|jd d d d d|jd dddddD]}|j|dtjtjdqZ|S)Nrlz %s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directoryrWz*Directory to start discovery ('.' default))rardz-pz --patternrz+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrXzs  ]