コード例 #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()))
コード例 #2
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
 def action():
     res = self.atc.validate_post_setup(self.environment_for_validate_post_setup)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus(res.status.value),
                         FailureDetails.new_message(res.failure_message))
         )
コード例 #3
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
 def action():
     mb_failure_message = self.atc_input.validate()
     if mb_failure_message:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus.HARD_ERROR,
                         FailureDetails.new_message(mb_failure_message))
         )
コード例 #4
0
 def action():
     res = self._action_to_check.validate_pre_sds(self._instruction_environment_pre_sds)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con.apply(ExecutionFailureStatus(res.status.value),
                               FailureDetails.new_message(res.failure_message))
         )
コード例 #5
0
 def action():
     res = self._validation_executor.apply(self._action_to_check)
     if res is not None:
         raise PhaseStepFailureException(
             failure_con.apply(
                 ExecutionFailureStatus(res.status.value),
                 FailureDetails.new_message(res.error_message)))
コード例 #6
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
 def action():
     res = self.atc.prepare(self.environment_for_other_steps,
                            self.os_services)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus.HARD_ERROR,
                         FailureDetails.new_message(res.failure_message))
         )
コード例 #7
0
def full_result_with_failure_info(
        status: FullExeResultStatus,
        failure_phase_step=phase_step.ASSERT__MAIN) -> FullExeResult:
    return FullExeResult(
        status, DUMMY_SDS, None,
        ActPhaseFailureInfo(
            failure_phase_step,
            FailureDetails.new_constant_message('failure message'),
            'actor name', 'phase source'))
コード例 #8
0
ファイル: act_helper.py プロジェクト: emilkarlen/exactly
 def parse_action() -> ActionToCheck:
     try:
         return actor.parse(self.instructions)
     except ParseException as ex:
         raise PhaseStepFailureException(
             failure_constructor.apply(
                 ExecutionFailureStatus.SYNTAX_ERROR,
                 FailureDetails.new_message(ex.cause)
             )
         )
コード例 #9
0
def _raise_he__single_line(
    format_str: str,
    format_map: Mapping[str, ToStringObject],
    ex: Exception,
):
    raise HardErrorException(
        failure_details.FailureDetailsRenderer(
            FailureDetails.new_message(
                text_docs.single_line(
                    str_constructor.FormatMap(format_str, format_map)), ex)))
コード例 #10
0
ファイル: executor.py プロジェクト: emilkarlen/exactly
    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)))
コード例 #11
0
 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)
コード例 #12
0
 def test_matches(self):
     message_str = 'message'
     cases = [
         NEA('equals',
             expected=
             sut.is_failure_message_of(message_str),
             actual=
             FailureDetails.new_constant_message(message_str),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
コード例 #13
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     settings = atc_proc_exe_settings.for_atc(environment, atc_input)
     try:
         exit_code = self._executor.execute(environment, settings,
                                            atc_input.stdin, output)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
コード例 #14
0
 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)
コード例 #15
0
 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)
コード例 #16
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     resolving_environment = full_resolving_env_for_instruction_env(
         os_services, environment)
     try:
         command = self._make_command(resolving_environment)
         settings = atc_proc_exe_settings.for_atc(environment, atc_input)
         with std_files.of_optional_stdin(atc_input.stdin,
                                          output) as std_files_:
             exit_code = os_services.command_executor.execute(
                 command, settings, std_files_)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
コード例 #17
0
 def hard_error(self, ex: HardErrorException) -> PhaseStepFailure:
     return self.apply(ExecutionFailureStatus.HARD_ERROR,
                       FailureDetails.new_message(ex.error))
コード例 #18
0
 def internal_error(self, ex: Exception, message: Optional[str] = None) -> PhaseStepFailure:
     return self.apply(ExecutionFailureStatus.INTERNAL_ERROR,
                       FailureDetails.new_exception(ex, message))
コード例 #19
0
 def internal_error_msg(self, msg: str) -> PhaseStepFailure:
     return self.apply(ExecutionFailureStatus.INTERNAL_ERROR,
                       FailureDetails.new_constant_message(msg))