"""Load and run the Pygame test suitepython -c "import pygame.tests.go" [<test options>]orpython test/go.py [<test options>]Command line option --help displays a command line usage message.run_tests.py in the main distribution directory is an alternative to test.go"""importsysif__name__=='__main__':importospkg_dir=os.path.split(os.path.abspath(__file__))[0]parent_dir,pkg_name=os.path.split(pkg_dir)is_pygame_pkg=(pkg_name=='tests'andos.path.split(parent_dir)[1]=='pygame')ifnotis_pygame_pkg:sys.path.insert(0,parent_dir)else:is_pygame_pkg=__name__.startswith('pygame.tests.')ifis_pygame_pkg:frompygame.tests.test_utils.run_testsimportrun_and_exitfrompygame.tests.test_utils.test_runnerimportopt_parserelse:fromtest.test_utils.run_testsimportrun_and_exitfromtest.test_utils.test_runnerimportopt_parserifis_pygame_pkg:test_pkg_name="pygame.tests"else:test_pkg_name="test"program_name=sys.argv[0]ifprogram_name=='-c':program_name='python -c "import %s.go"'%test_pkg_name############################################################################ Set additional command line options## Defined in test_runner.py as it shares options, added to hereopt_parser.set_usage("""Runs all or some of the %(pkg)s.xxxx_test tests.$ %(exec)s sprite threads -sdRuns the sprite and threads module tests isolated in subprocesses, dumpingall failing tests info in the form of a dict."""%{'pkg':test_pkg_name,'exec':program_name})opt_parser.add_option("-d","--dump",action='store_true',help="dump failures/errors as dict ready to eval")opt_parser.add_option("-F","--file",help="dump failures/errors to a file")opt_parser.add_option("-a","--all",action='store_true',help="dump all results not just errors eg. -da")opt_parser.add_option("-m","--multi_thread",metavar='THREADS',type='int',help="run subprocessed tests in x THREADS")opt_parser.add_option("-t","--time_out",metavar='SECONDS',type='int',help="kill stalled subprocessed tests after SECONDS")opt_parser.add_option("-f","--fake",metavar="DIR",help="run fake tests in run_tests__tests/$DIR")opt_parser.add_option("-p","--python",metavar="PYTHON",help="path to python excutable to run subproccesed tests\n""default (sys.executable): %s"%sys.executable)opt_parser.add_option("-I","--interactive",action='store_true',help="include tests requiring user input")############################################################################ Set run() keyword arguements according to command line arguemnts.# args will be the test module list, passed as positional argumemts.options,args=opt_parser.parse_args()kwds={}ifoptions.incomplete:kwds['incomplete']=Trueifoptions.nosubprocess:kwds['nosubprocess']=Trueifoptions.dump:kwds['dump']=Trueifoptions.file:kwds['file']=options.filekwds['timings']=options.timingsifoptions.exclude:kwds['exclude']=options.excludeifoptions.show_output:kwds['show_output']=Trueifoptions.all:kwds['all']=Trueifoptions.randomize:kwds['randomize']=Trueifoptions.seedisnotNone:kwds['seed']=options.seedifoptions.multi_threadisnotNone:kwds['multi_thread']=options.multi_threadifoptions.time_outisnotNone:kwds['time_out']=options.time_outifoptions.fake:kwds['fake']=options.fakeifoptions.python:kwds['python']=options.pythonifoptions.interactive:kwds['interactive']=True############################################################################ Run the test suite.run_and_exit(*args,**kwds)