Beispiel #1
0
def result_to_pfh(
        result: ExecutionResultAndStderr) -> pfh.PassOrFailOrHardError:
    if result.exit_code != 0:
        return pfh.new_pfh_fail(
            top_lvl_error_msg_rendering.non_zero_exit_code_msg(
                result.program, result.exit_code, result.stderr_contents))
    return pfh.new_pfh_pass()
def result_to_pfh(result_and_stderr: ResultAndStderr) -> pfh.PassOrFailOrHardError:
    result = result_and_stderr.result
    if not result.is_success:
        return pfh.new_pfh_hard_error(failure_message_for_nonzero_status(result_and_stderr))
    if result.exit_code != 0:
        return pfh.new_pfh_fail(failure_message_for_nonzero_status(result_and_stderr))
    return pfh.new_pfh_pass()
Beispiel #3
0
def translate_pfh_exception_to_pfh(action, *args,
                                   **kwargs) -> pfh.PassOrFailOrHardError:
    try:
        action(*args, **kwargs)
        return pfh.new_pfh_pass()

    except PfhException as ex:
        return ex.pfh
def translate_pfh_exception_to_pfh(action,
                                   *args, **kwargs) -> pfh.PassOrFailOrHardError:
    try:
        action(*args, **kwargs)
        return pfh.new_pfh_pass()

    except PfhException as ex:
        return ex.pfh
 def main(self,
          environment: InstructionEnvironmentForPostSdsStep,
          os_services: OsServices) -> pfh.PassOrFailOrHardError:
     actual_contents = environment.sds.result.stdout_file.read_text()
     if actual_contents == self.expected:
         return pfh.new_pfh_pass()
     else:
         err_msg = 'Expected: {}\nActual  : {}'.format(self.expected, actual_contents)
         return pfh.new_pfh_fail(err_msg)
    def _assert_with_file_matcher(self) -> pfh.PassOrFailOrHardError:
        mb_failure_of_existence = path_check.failure_message_or_none(
            _FILE_EXISTENCE_CHECK, self.described_path)

        if mb_failure_of_existence is not None:
            return (pfh.new_pfh_fail(mb_failure_of_existence)
                    if self._is_positive_check() else pfh.new_pfh_pass())

        return self._file_exists_but_must_also_satisfy_file_matcher()
Beispiel #7
0
 def ret_val(environment: InstructionEnvironmentForPostSdsStep, *args):
     file_path = standard_phase_file_path(environment.sds.act_dir, phase)
     with open(str(file_path), 'w') as f:
         contents = os.linesep.join(
             file_lines_from_env(environment)) + os.linesep
         f.write(contents)
     return pfh.new_pfh_pass(
     ) if phase is phase_identifier.PhaseEnum.ASSERT else sh.new_sh_success(
     )
    def __init__(self,
                 assertion_action=do_nothing,
                 assertion_return_value=pfh.new_pfh_pass(),
                 non_assertion_action=do_nothing,
                 non_assertion_return_value=sh.new_sh_success(),

                 ):
        self.non_assertion_return_value = non_assertion_return_value
        self.non_assertion_action = non_assertion_action
        self.assertion_return_value = assertion_return_value
        self.assertion_action = assertion_action
 def __init__(
         self,
         assertion_action=do_nothing,
         assertion_return_value=pfh.new_pfh_pass(),
         non_assertion_action=do_nothing,
         non_assertion_return_value=sh.new_sh_success(),
 ):
     self.non_assertion_return_value = non_assertion_return_value
     self.non_assertion_action = non_assertion_action
     self.assertion_return_value = assertion_return_value
     self.assertion_action = assertion_action
 def new_assert_instruction(self,
                            value_for_symbol_usages,
                            value_for_validate_pre_sds,
                            value_for_validate,
                            value_for_execute) -> AssertPhaseInstruction:
     return assert_phase_instruction_that(
         symbol_usages_initial_action=self._do_record_first_invokation(value_for_symbol_usages),
         validate_pre_sds=self._do_record_and_return_svh(value_for_validate_pre_sds),
         validate_post_setup=self._do_record_and_return_svh(value_for_validate),
         main=self._do_record_and_return(value_for_execute,
                                         pfh.new_pfh_pass()))
Beispiel #11
0
 def _file_exists_but_must_also_satisfy_file_matcher(self) -> pfh.PassOrFailOrHardError:
     try:
         failure_message_resolver = self._matches_file_matcher_for_expectation_type()
         if failure_message_resolver is None:
             return pfh.new_pfh_pass()
         else:
             err_msg = (_FILE_EXISTS_BUT_INVALID_PROPERTIES_ERR_MSG_HEADER +
                        self._err_msg_for(failure_message_resolver))
             return pfh.new_pfh_fail(err_msg)
     except hard_error.HardErrorException as ex:
         return pfh.new_pfh_hard_error(self._err_msg_for(ex.error))
Beispiel #12
0
    def _assert_without_file_matcher(
            self) -> Optional[pfh.PassOrFailOrHardError]:
        check = _FILE_EXISTENCE_CHECK
        if self.expectation_type is ExpectationType.NEGATIVE:
            check = file_properties.negation_of(check)

        mb_failure = path_check.failure_message_or_none(
            check, self.described_path)

        return (pfh.new_pfh_pass()
                if mb_failure is None else pfh.new_pfh_fail(mb_failure))
 def new_assert_instruction(self, value_for_symbol_usages,
                            value_for_validate_pre_sds, value_for_validate,
                            value_for_execute) -> AssertPhaseInstruction:
     return assert_phase_instruction_that(
         symbol_usages_initial_action=self._do_record_first_invokation(
             value_for_symbol_usages),
         validate_pre_sds=self._do_record_and_return_svh(
             value_for_validate_pre_sds),
         validate_post_setup=self._do_record_and_return_svh(
             value_for_validate),
         main=self._do_record_and_return(value_for_execute,
                                         pfh.new_pfh_pass()))
def assert_phase_instruction_that(validate_pre_sds: Callable = do_return(svh.new_svh_success()),
                                  validate_pre_sds_initial_action: Optional[Callable] = None,
                                  validate_post_setup: Callable = do_return(svh.new_svh_success()),
                                  validate_post_setup_initial_action: Optional[Callable] = None,
                                  main: Callable = do_return(pfh.new_pfh_pass()),
                                  main_initial_action: Optional[Callable] = None,
                                  symbol_usages_initial_action: Optional[Callable] = None,
                                  symbol_usages: Callable = do_return([])) -> AssertPhaseInstruction:
    return _AssertPhaseInstructionThat(action_of(validate_pre_sds_initial_action, validate_pre_sds),
                                       action_of(validate_post_setup_initial_action, validate_post_setup),
                                       action_of(main_initial_action, main),
                                       action_of(symbol_usages_initial_action, symbol_usages))
Beispiel #15
0
    def _assert_with_file_matcher(self) -> pfh.PassOrFailOrHardError:
        failure_message_of_existence = pre_or_post_sds_failure_message_or_none(
            FileRefCheck(self.file_ref_resolver,
                         _FILE_EXISTENCE_CHECK),
            self.environment.path_resolving_environment_pre_or_post_sds)

        if failure_message_of_existence:
            return (pfh.new_pfh_fail(failure_message_of_existence)
                    if self._is_positive_check()
                    else pfh.new_pfh_pass()
                    )

        return self._file_exists_but_must_also_satisfy_file_matcher()
Beispiel #16
0
def assert_phase_instruction_that(
    validate_pre_sds: ValidatePreSdsAction = do_return(svh.new_svh_success()),
    validate_pre_sds_initial_action: Optional[Callable] = None,
    validate_post_setup: ValidatePostSdsAction = do_return(
        svh.new_svh_success()),
    validate_post_setup_initial_action: Optional[Callable] = None,
    main: AssertMainAction = do_return(pfh.new_pfh_pass()),
    main_initial_action: Optional[AssertMainInitialAction] = None,
    symbol_usages_initial_action: Optional[Callable] = None,
    symbol_usages: Callable = do_return([])
) -> AssertPhaseInstruction:
    return _AssertPhaseInstructionThat(
        action_of(validate_pre_sds_initial_action, validate_pre_sds),
        action_of(validate_post_setup_initial_action, validate_post_setup),
        action_of(main_initial_action, main),
        action_of(symbol_usages_initial_action, symbol_usages))
Beispiel #17
0
 def main(self,
          environment: InstructionEnvironmentForPostSdsStep,
          settings: InstructionSettings,
          os_services: OsServices) -> pfh.PassOrFailOrHardError:
     actual_contents = environment.sds.result.stdout_file.read_text()
     if actual_contents == self.expected:
         return pfh.new_pfh_pass()
     else:
         return pfh.new_pfh_fail(
             new_pre_formatted_str_for_test(
                 str_constructor.FormatPositional(
                     'Expected: {}\nActual  : {}',
                     self.expected, actual_contents,
                 )
             )
         )
Beispiel #18
0
    def _file_exists_but_must_also_satisfy_file_matcher(
            self) -> pfh.PassOrFailOrHardError:
        matching_result = self._matches_file_matcher_for_expectation_type()
        if matching_result.value:
            return pfh.new_pfh_pass()
        else:
            err_msg = rend_comb.SequenceR([
                path_err_msgs.line_header_block__primitive(
                    str_constructor.FormatMap(
                        'Existing {PATH} does not satisfy {FILE_MATCHER}',
                        _EXISTING_PATH_FAILURE_FORMAT_MAP),
                    self.described_path.describer,
                ),
                rendering__node_bool.BoolTraceRenderer(matching_result.trace),
            ])

            return pfh.new_pfh_fail(err_msg)
Beispiel #19
0
 def test_unsuccessful_WHEN_actual_is_not_expected(self):
     # ARRANGE #
     assertion = sut.is_hard_error__with_arbitrary_message()
     cases = [
         NameAndValue(
             'pass',
             pfh.new_pfh_pass(),
         ),
         NameAndValue(
             'fail',
             pfh.new_pfh_fail__str('error message'),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assert_that_assertion_fails(assertion, case.value)
    def _execute(self,
                 os_services: OsServices,
                 environment: InstructionEnvironmentForPostSdsStep,
                 model_getter_ddv: ModelGetterDdv[MODEL],
                 matcher_ddv: MatcherDdv[MODEL],
                 ) -> pfh.PassOrFailOrHardError:
        tcds = environment.tcds
        app_env = ApplicationEnvironment(os_services,
                                         environment.proc_exe_settings,
                                         environment.tmp_dir__path_access.paths_access,
                                         environment.mem_buff_size)
        model_getter = model_getter_ddv.value_of_any_dependency(tcds).primitive(app_env)
        matcher = matcher_ddv.value_of_any_dependency(tcds).primitive(app_env)
        model = model_getter.get()
        result = matcher.matches_w_trace(model)

        if result.value:
            return pfh.new_pfh_pass()
        else:
            return pfh.new_pfh_fail(self._failure_message(model_getter, model, result))
Beispiel #21
0
 def test_unsuccessful_WHEN_actual_is_not_expected(self):
     # ARRANGE #
     cases = [
         NEA(
             'pass',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.PASS),
             pfh.new_pfh_fail__str('fail msg'),
         ),
         NEA(
             'fail',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.FAIL),
             pfh.new_pfh_hard_error__str('hard err msg'),
         ),
         NEA(
             'hard error',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.HARD_ERROR),
             pfh.new_pfh_pass(),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assert_that_assertion_fails(case.expected, case.actual)
Beispiel #22
0
 def test_success_WHEN_actual_is_expected(self):
     # ARRANGE #
     cases = [
         NEA(
             'pass',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.PASS),
             pfh.new_pfh_pass(),
         ),
         NEA(
             'fail',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.FAIL),
             pfh.new_pfh_fail(
                 asrt_text_doc.new_single_string_text_for_test('fail msg')),
         ),
         NEA(
             'fail/const msg',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.FAIL),
             pfh.new_pfh_fail__str('fail msg'),
         ),
         NEA(
             'hard error',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.HARD_ERROR),
             pfh.new_pfh_hard_error(
                 asrt_text_doc.new_single_string_text_for_test(
                     'hard err msg')),
         ),
         NEA(
             'hard error/const msg',
             sut.status_is(pfh.PassOrFailOrHardErrorEnum.HARD_ERROR),
             pfh.new_pfh_hard_error__str('hard err msg'),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             case.expected.apply_without_message(self, case.actual)
 def translate_for_assertion(self, error_message) -> pfh.PassOrFailOrHardError:
     return pfh.new_pfh_pass() if error_message is None else pfh.new_pfh_hard_error(error_message)
 def translate_for_assertion(self, error_message) -> pfh.PassOrFailOrHardError:
     return pfh.new_pfh_pass()
 def ret_val(environment: common.InstructionEnvironmentForPostSdsStep, *args):
     file_path = standard_phase_file_path(environment.sds.act_dir, phase)
     with open(str(file_path), 'w') as f:
         contents = os.linesep.join(file_lines_from_env(environment)) + os.linesep
         f.write(contents)
     return pfh.new_pfh_pass() if phase is phase_identifier.PhaseEnum.ASSERT else sh.new_sh_success()
Beispiel #26
0
 def translate_for_assertion(self,
                             error_message) -> pfh.PassOrFailOrHardError:
     return pfh.new_pfh_pass()
Beispiel #27
0
 def translate_for_assertion(
         self, error_message: TextRenderer) -> pfh.PassOrFailOrHardError:
     return (pfh.new_pfh_pass() if error_message is None else
             pfh.new_pfh_hard_error(error_message))
Beispiel #28
0
 def test_success_WHEN_actual_is_pass(self):
     # ARRANGE #
     assertion = sut.is_pass()
     actual = pfh.new_pfh_pass()
     # ACT #
     assertion.apply_without_message(self, actual)
 def main(self, environment: InstructionEnvironmentForPostSdsStep,
          settings: InstructionSettings,
          os_services: OsServices) -> pfh.PassOrFailOrHardError:
     utils.raise_test_error_if_cwd_is_not_test_root(environment.sds)
     return pfh.new_pfh_pass()
 def main(self, environment: InstructionEnvironmentForPostSdsStep,
          os_services: OsServices) -> pfh.PassOrFailOrHardError:
     utils.raise_test_error_if_cwd_is_not_test_root(environment.sds)
     return pfh.new_pfh_pass()