예제 #1
0
    def eject_next_input(self) -> List[str]:
        if len(self.input_text_funcs) == 0:
            return []

        input_function = self.input_text_funcs[0]
        if input_function.trigger_count > 0:
            input_function.trigger_count -= 1

        curr_output = StdoutHandler.get_partial_output()
        next_func = input_function.input_function

        new_input: str
        try:
            obj = next_func(curr_output)
            if isinstance(obj, str):
                new_input = obj
            elif isinstance(obj, CheckResult):
                if obj.result:
                    raise TestPassedException()
                else:
                    raise WrongAnswerException(obj.feedback)
            else:
                raise FatalErrorException(
                    'Dynamic input should return ' +
                    f'str or CheckResult objects only. Found: {type(obj)}')
        except BaseException as ex:
            TestRun.curr_test_run.error_in_test = ex
            return []

        if input_function.trigger_count == 0:
            self.input_text_funcs.pop(0)

        new_input = clear_text(new_input)
        return new_input.strip().split('\n')
예제 #2
0
 def get_dynamic_output() -> str:
     return clear_text(''.join(StdoutHandler.mock_stdout.dynamic))
예제 #3
0
 def get_partial_output() -> str:
     output = clear_text(''.join(StdoutHandler.mock_stdout.partial))
     StdoutHandler.mock_stdout.partial = []
     return output
예제 #4
0
 def get_output() -> str:
     return clear_text(''.join(StdoutHandler.mock_stdout.cloned))