a xa+@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/lib/python3.9/unittest/main.py _convert_names rcCsdd|DS)NcSsg|] }t|qSr)r).0rrrr .z"_convert_names..r)namesrrr_convert_names-srcCsd|vrd|}|S)N*z*%s*r)patternrrr_convert_select_pattern1sr c @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|trr")rAr(lenr _do_discoveryrF parse_argstestsr testNames__name__r4r%r&list createTests)r;r,rrrr9xs(       zTestProgram.parseArgscCst|jr|j|j_|r@|dur"|jn|}||j|j|j|_n0|jdur\|j|j |_n|j |j|j |_dSN) testNamePatternsr6rLstartrtoptestrQZloadTestsFromModuler(ZloadTestsFromNames)r;from_discoveryLoaderrrrrrTs   zTestProgram.createTestscCs$|}|||_|||_dSrU)_getParentArgParser_getMainArgParserrF_getDiscoveryArgParserr@)r;Z parent_parserrrrrAs zTestProgram._initArgParserscCstjdd}|jddddddd |jd d ddd d d |jddddd|jdurn|jddddddd|_|jdur|jddddddd|_|jdur|jddddddd|_|jdur|jdd d!td"d#g|_|S)$NF)Zadd_helpz-vz --verboser0Z store_constr>zVerbose output)destactionZconsthelpz-qz--quietrz Quiet outputz--localsr# store_truez"Show local variables in tracebacks)r_r`raz-fz --failfastr.zStop on first fail or errorz-cz--catchr/z'Catch Ctrl-C and display results so farz-bz--bufferr1z%Buffer stdout and stderr during testsz-krVappendz.Only run tests which match the given substring)r_r`typera)argparseArgumentParser add_argumentr.r/r1rVr )r;parserrrrr\sL          zTestProgram._getParentArgParsercCs2tj|gd}|j|_|j|_|jdddd|S)NparentsrPrz?a list of any number of test modules, classes and test methods.)nargsra)rerfr8rErBrHrg)r;parentrhrrrr]szTestProgram._getMainArgParsercCsztj|gd}d|j|_d|_|jddddd|jd d d d d|jd dddddD]}|j|dtjtjdqZ|S)Nriz %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))r_raz-pz --patternrz+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrXzs  ]