def __call__(self, argv): cf = self._config optlist, extraopts, args = getopt.getopt(argv[1:], "hdvc:f:n:N") for opt, optarg in optlist: if opt == "-h": print __doc__ sys.exit(2) if opt == "-d": cf.flags.DEBUG += 1 if opt == "-v": cf.flags.VERBOSE += 1 if opt == "-c" or opt == "-f": cf.mergefile(optarg) if opt == "-n": cf.NOTE = optarg if opt == "-N": cf.flags.NONOTE = True cf.update(extraopts) cf.argv = args # test args cf.arguments = [os.path.basename(argv[0])] + argv[1:] # original command line self.initialize() if cf.argv: self.run_modules(cf.argv) else: from pycopia import cliutils testlist = self.get_test_list() try: test = cliutils.choose(testlist) except: return None else: self.run_module(test) self.finalize()
def __call__(self, argv): """Run the test runner. Invoke the test runner by calling it. """ cf = self.runner.config # this getopt() is a lightweight getopt that only considers # traditional options as options (e.g. -x). Any long-option form (e.g. # --reportname=default) is converted into a dictionary and is used to # update the configuration. This allows the user or test runner to # provide or alter configuration parameters at run time without # needing a pre-defined list to getopt(). from pycopia import getopt optlist, extraopts, args = getopt.getopt(argv[1:], "h?dviIc:f:n:") for opt, optarg in optlist: if opt in ("-h", "-?"): print TestRunnerInterfaceDoc % (os.path.basename(argv[0]), ) return if opt == "-d": cf.flags.DEBUG += 1 if opt == "-v": cf.flags.VERBOSE += 1 if opt == "-i": cf.flags.INTERACTIVE = True if opt == "-I": cf.flags.INTERACTIVE = False if opt == "-c" or opt == "-f": cf.mergefile(optarg) if opt == "-n": cf.comment = optarg cf.update(extraopts) cf.argv = args # test args # original command line arguments saved for the report cf.arguments = [os.path.basename(argv[0])] + argv[1:] # Save extra options for overriding configuration after a mergefile # because command line options should have highest precedence. self.runner.SetOptions(extraopts) if not args: from pycopia import cliutils l = GetModuleList() l.insert(0, None) arg = cliutils.choose(l, prompt="Select test") if arg is None: return args = [arg] objects, errors = module.GetObjects(args) if errors: print >> sys.stderr, "Errors found while loading test object:" for error in errors: print >> sys.stderr, error if objects: self.runner.Initialize() self.runner.RunObjects(objects) self.runner.Finalize()
def choose(self, somelist, defidx=0, prompt=None): return cliutils.choose(somelist, defidx, self._get_prompt("PS3", prompt), input=self._io.raw_input, error=self.error)
def choose(self, somelist, defidx=0): if self.INTERACTIVE: return cliutils.choose(somelist, defidx) else: raise TestIncompleteError, "user input in non-interactive test."