class TestStepStatusListener(object): def setup_method(self, method): CommandArgumentParser() sys.argv.clear() sys.argv.append("spam") sys.argv.append("spam") self._listener = StepStatusListener() self._executor = StepExecutor(["1"]) self._log_file = os.path.join(env.BASE_DIR, "logs", "app.log") def test_after_step(self): self._listener.after_step(self._executor) with open(self._log_file) as f: for line in f: pass last_line = line assert "Finish" in last_line def test_before_step(self): self._listener.before_step(self._executor) with open(self._log_file) as f: for line in f: pass last_line = line assert "Start" in last_line
def setup_method(self, method): CommandArgumentParser() sys.argv.clear() sys.argv.append("spam") sys.argv.append("spam") self._listener = StepStatusListener() self._executor = StepExecutor(["1"]) self._log_file = os.path.join(env.BASE_DIR, "logs", "app.log")
def test_end_with_noerror(self): if sys.version_info.minor < 6: # ignore test if python version is less 3.6(assert_called is not supported) return with ExitStack() as stack: mock_before_step = stack.enter_context( patch("cliboa.core.listener.StepStatusListener.before_step")) mock_error_step = stack.enter_context( patch("cliboa.core.listener.StepStatusListener.error_step")) mock_after_step = stack.enter_context( patch("cliboa.core.listener.StepStatusListener.after_step")) mock_post_step = stack.enter_context( patch( "cliboa.core.listener.StepStatusListener.after_completion") ) step = SampleCustomStep() Helper.set_property(step, "logger", LisboaLog.get_logger(step.__class__.__name__)) Helper.set_property(step, "listeners", [StepStatusListener()]) executor = SingleProcExecutor([step]) executor.execute_steps(None) mock_before_step.assert_called_once() mock_error_step.assert_not_called() mock_after_step.assert_called_once() mock_post_step.assert_called_once()
def _append_listeners(self, instance, args): listeners = [StepStatusListener()] if args is not None: from cliboa.core.factory import CustomInstanceFactory if type(args) is str: listeners.append(CustomInstanceFactory.create(args)) elif type(args) is list: for arg in args: listeners.append(CustomInstanceFactory.create(arg)) Helper.set_property(instance, "listeners", listeners)
def _append_listeners(self, instance, args, values): listeners = [StepStatusListener()] if args is not None: from cliboa.core.factory import CustomInstanceFactory if type(args) is str: clz = CustomInstanceFactory.create(args) clz.__dict__.update(values) listeners.append(clz) elif type(args) is list: for arg in args: clz = CustomInstanceFactory.create(arg) clz.__dict__.update(values) listeners.append(CustomInstanceFactory.create(clz)) Helper.set_property(instance, "listeners", listeners)
def __execute_steps(self): """ Execute steps in scenario.yml """ while not self._scenario_queue.step_queue.is_empty(): strategy = StepExecutorFactory.create( self._scenario_queue.step_queue.pop()) strategy.regist_listeners(StepStatusListener()) res = strategy.execute_steps(self._cmd_args) if res is None: continue if res == 0: self._logger.info("Step response [0]. Scenario will be end.") break else: self._logger.error( "Step response [%s]. Scenario will be end." % res) break
def __execute_steps(self): """ Execute steps in scenario.yml """ res = None while not self._scenario_queue.step_queue.is_empty(): strategy = StepExecutorFactory.create( self._scenario_queue.step_queue.pop()) strategy.regist_listeners(StepStatusListener()) res = strategy.execute_steps(self._cmd_args) if res is None: continue elif res == StepStatus.SUCCESSFUL_TERMINATION: self._logger.info( "Step response [successful termination]. Scenario will be end." ) break else: self._logger.error( "Step response [%s]. Scenario will be end." % res) break return StepStatus.SUCCESSFUL_TERMINATION if res is None else res