Exemplo n.º 1
0
def execute_element(
    executor: ControlledInstructionExecutor, element: SectionContentElement,
    instruction_info: InstructionInfo
) -> Optional[SingleInstructionExecutionFailure]:
    """
    :param element: Must be an instruction (i.e., element.is_instruction is True)
    :return: If None, then the execution was successful.
    """

    try:
        instruction = instruction_info.instruction
        assert isinstance(instruction,
                          TestCaseInstruction), _INSTRUCTION_TYPE_ERROR_MESSAGE
        fail_info = executor.apply(instruction)
        if fail_info is None:
            return None
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus(fail_info.status.value),
            element.source_location_info.source_location_path,
            FailureDetails.new_message(fail_info.error_message))
    except HardErrorException as ex:
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus.HARD_ERROR,
            element.source_location_info.source_location_path,
            FailureDetails.new_message(ex.error))
    except Exception as ex:
        from exactly_lib.util import traceback_
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus.INTERNAL_ERROR,
            element.source_location_info.source_location_path,
            FailureDetails.new_exception(ex, traceback_.traceback_as_str()))
Exemplo n.º 2
0
    def _hard_error(ex: Exception):
        from exactly_lib.test_case.hard_error import HardErrorException
        from exactly_lib.common.report_rendering.parts.failure_details import FailureDetailsRenderer
        from exactly_lib.test_case.result.failure_details import FailureDetails
        from exactly_lib.execution.phase_step import ACT__PREPARE

        msg = 'Error in {}'.format(ACT__PREPARE.step)
        raise HardErrorException(
            FailureDetailsRenderer(
                FailureDetails.new_exception(ex, message=msg)))
 def test_matches(self):
     cases = [
         NEA('expected type of exception',
             expected=
             sut.is_exception_of_type(ValueError),
             actual=
             FailureDetails.new_exception(ValueError('an exception')),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
 def test_not_matches(self):
     cases = [
         NEA('not a ' + str(FailureDetails),
             expected=
             sut.is_failure_message_of(''),
             actual=
             'not a ' + str(FailureDetails),
             ),
         NEA('message is absent',
             expected=
             sut.is_failure_message_of(''),
             actual=
             FailureDetails.new_exception(ValueError('an exception')),
             ),
         NEA('unexpected message',
             expected=
             sut.is_failure_message_of('expected'),
             actual=
             FailureDetails.new_constant_message('actual'),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
 def test_not_matches(self):
     cases = [
         NEA('not a ' + str(FailureDetails),
             expected=
             sut.matches_exception(asrt.anything_goes()),
             actual=
             'not a ' + str(FailureDetails),
             ),
         NEA('unexpected type of exception',
             expected=
             sut.matches_exception(asrt.is_instance(ValueError)),
             actual=
             FailureDetails.new_exception(NotImplementedError('an exception')),
             ),
         NEA('exception is absent',
             expected=
             sut.matches_exception(asrt.is_not_none),
             actual=
             FailureDetails.new_constant_message('just a message'),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Exemplo n.º 6
0
 def internal_error(self, ex: Exception, message: Optional[str] = None) -> PhaseStepFailure:
     return self.apply(ExecutionFailureStatus.INTERNAL_ERROR,
                       FailureDetails.new_exception(ex, message))