def get_configuration(): cfg = configuration.parse(CONFIG) host = cfg['host'][0] port = int(cfg['port'][0]) return { "host": host, "port": port }
def parseArgs(self, argv): if len(argv) > 1 and argv[1].lower() == "discover": super(TestProgram, self).parseArgs(argv) return # we parse unittest options here and then re-construct the # argv array for unittest to be able to provide the correct usage # information in case of errors parser = argparse.ArgumentParser(epilog=self.HELP_EPILOG, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( "--host", metavar="HOST", type=str, action="append", nargs=1, help="Hosts that the tests will be run on" ) parser.add_argument("--list", action="store_true", help="List all tests") parser.add_argument("--config", nargs=1, default="config/config.ini", help="Path to configuration file") parser.add_argument("--verbose", "-v", action="count", help="Verbose output (can be specified multiple times)") parser.add_argument("--quiet", action="store_true", help="Minimal output") parser.add_argument("--failfast", action="store_true", help="Stop on first failure") parser.add_argument("tests", metavar="TEST", nargs="*", help="Test classes/methods to execute") self.__args = parser.parse_args(argv[1:]) self.__configuration = configuration.parse(self.__args.config) # construct the list of hosts if self.__args.host: tests = [] for h in self.__args.host: tests.extend(h) else: tests = [self.__configuration.default_test] for test in tests: if test in self.__configuration.tests: hosts = self.__configuration.tests[test].hosts elif test in self.__configuration.hosts: hosts = [self.__configuration.hosts[test]] else: print "'%s' is neither a configured host nor a host list" % test sys.exit(1) self.__hosts.update(dict((h.hostString, h) for h in hosts)) # create argv for unittest' TestProgram super_args = ["--%s" % s for s in self.UNITTEST_ARGS if getattr(self.__args, s)] super(TestProgram, self).parseArgs(argv[:1] + super_args + self.__args.tests) if self.__args.verbose > 0: self.verbosity = self.__args.verbose + 1 if self.__args.list: print "Tests:\n" self.__prettyPrintSuite() print "Hosts:\n" self.__prettyPrintHosts() print "" sys.exit(0)
def setUp(self) -> None: self.configurationService = configuration.Configuration() # reads and parses initial configuration file with open( self.configurationService. shared_memory_manager_dict["config_file"], "r") as f: raw = f.read() self.configurationService.shared_memory_manager_dict[ "config_data"], _flag, _error = configuration.parse(raw, yaml=True)
def parseArgs(self, argv): if len(argv) > 1 and argv[1].lower() == 'discover': super(TestProgram, self).parseArgs(argv) return # we parse unittest options here and then re-construct the # argv array for unittest to be able to provide the correct usage # information in case of errors parser = argparse.ArgumentParser( epilog=self.HELP_EPILOG, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('--host', metavar='HOST', type=str, action='append', nargs=1, help='Hosts that the tests will be run on') parser.add_argument('--list', action='store_true', help='List all tests') parser.add_argument('--config', nargs=1, default='config/config.ini', help='Path to configuration file') parser.add_argument( '--verbose', '-v', action='count', help='Verbose output (can be specified multiple times)') parser.add_argument('--quiet', action='store_true', help='Minimal output') parser.add_argument('--failfast', action='store_true', help='Stop on first failure') parser.add_argument('tests', metavar='TEST', nargs='*', help='Test classes/methods to execute') self.__args = parser.parse_args(argv[1:]) self.__configuration = configuration.parse(self.__args.config) # construct the list of hosts if self.__args.host: tests = [] for h in self.__args.host: tests.extend(h) else: tests = [self.__configuration.default_test] for test in tests: if test in self.__configuration.tests: hosts = self.__configuration.tests[test].hosts elif test in self.__configuration.hosts: hosts = [self.__configuration.hosts[test]] else: print "'%s' is neither a configured host nor a host list" % \ test sys.exit(1) self.__hosts.update(dict((h.hostString, h) for h in hosts)) # create argv for unittest' TestProgram super_args = [ '--%s' % s for s in self.UNITTEST_ARGS if getattr(self.__args, s) ] super(TestProgram, self).parseArgs(argv[:1] + super_args + self.__args.tests) if self.__args.verbose > 0: self.verbosity = self.__args.verbose + 1 if self.__args.list: print 'Tests:\n' self.__prettyPrintSuite() print 'Hosts:\n' self.__prettyPrintHosts() print '' sys.exit(0)