class BotLauncher(object): def __init__(self, configuration, host, pickle_file_name, logging_cfg_file_name, scenario, iterations, options, verbose): super(BotLauncher, self).__init__() self.verbose = verbose self.options = options if isinstance(configuration, basestring): self.launch_files = [configuration] else: self.launch_files = configuration self.host = host self.pickle_file_name = pickle_file_name self.logging_cfg_file_name = logging_cfg_file_name self.scenario = scenario self.iterations = iterations self.results = [] self._set_logging_cfg() self._set_users() def _set_logging_cfg(self): logging.config.fileConfig(self.logging_cfg_file_name) def _set_users(self): self.users = len(self.scenario) def _add_exception(self, exceptions_dict, (exception, trace)): """ { "ExceptionType1": <BotError>, "ExceptionType2": <BotError>, ... } """ if exception.__class__.__name__ in exceptions_dict: exceptions_dict[exception.__class__.__name__].add_instance( (exception, trace)) else: exceptions_dict[exception.__class__.__name__] = Data.BotError( (exception, trace))
def test_botiteration(self): botexc = Data.BotError((Exception("foo"), "foobar"), 2, 4, 6) botuser = User.StandardBotUser( {"XMLRPC": ("http://foo", "http://foo/login")}, "XMLRPC", "user", "passwd", "exp_name", "cat_name", "bar", 0.05) botit = Data.BotIteration(100, [botexc], [botuser], "stdout", "stderr") self.assertTrue(repr(botit).find('botusers') > 0)
def test_bottrial(self): botexc = Data.BotError((Exception("foo"), "foobar"), 2, 4, 6) botuser = User.StandardBotUser( {"JSON": ("http://foo", "http://foo/login")}, "JSON", "user", "passwd", "exp_name", "cat_name", "bar", 0.05) botit = Data.BotIteration(100, {"Exception": botexc}, [botuser], "stdout", "stderr") bottri = Data.BotTrial([botit]) self.assertTrue(repr(bottri).find('iterations') > 0)
class BotLauncher(object): def __init__(self, configuration, host, pickle_file_name, logging_cfg_file_name, scenario, iterations, options, verbose): super(BotLauncher, self).__init__() self.verbose = verbose self.options = options if isinstance(configuration, basestring): self.launch_files = [ configuration ] else: self.launch_files = configuration for launch_file in self.launch_files: if not os.path.exists(launch_file): print("ERROR: launch file {} does not exist. Did you create the environment you wanted to test? (e.g., weblab-admin.py create example)".format(launch_file)) sys.exit(-1) self.host = host self.pickle_file_name = pickle_file_name self.logging_cfg_file_name = logging_cfg_file_name self.scenario = scenario self.iterations = iterations self.results = [] self._set_logging_cfg() self._set_users() def _set_logging_cfg(self): logging.config.fileConfig(self.logging_cfg_file_name) def _set_users(self): self.users = len(self.scenario) def _add_exception(self, exceptions_dict, (exception, trace)): """ { "ExceptionType1": <BotError>, "ExceptionType2": <BotError>, ... } """ if exception.__class__.__name__ in exceptions_dict: exceptions_dict[exception.__class__.__name__].add_instance((exception, trace)) else: exceptions_dict[exception.__class__.__name__] = Data.BotError((exception, trace))
def test_botexception(self): botexc = Data.BotError((Exception("foo"), "foobar"), 2, 4, 6) self.assertTrue(repr(botexc).find('instances') > 0)