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()
コード例 #2
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()
コード例 #3
0
ファイル: keep_sandbox.py プロジェクト: emilkarlen/exactly
    def test_assert(self):
        # ARRANGE #
        cases = {
            STEP__VALIDATE_POST_SETUP:
                {
                    EXECUTION__VALIDATION_ERROR:
                        assert_phase_instruction_that(validate_post_setup=SVH_VALIDATION_ERROR),

                    EXECUTION__HARD_ERROR:
                        assert_phase_instruction_that(validate_post_setup=SVH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        assert_phase_instruction_that(validate_post_setup_initial_action=DO_RAISES_EXCEPTION),

                },
            STEP__MAIN:
                {
                    EXECUTION__FAIL:
                        assert_phase_instruction_that(main=do_return(pfh.new_pfh_fail('fail msg'))),

                    EXECUTION__HARD_ERROR:
                        assert_phase_instruction_that(main=do_return(pfh.new_pfh_hard_error('hard error msg'))),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        assert_phase_instruction_that(main_initial_action=DO_RAISES_EXCEPTION),
                },
        }
        # ACT & ASSERT #
        self._check_and_assert_sds_is_preserved_and_is_printed(phase_identifier.ASSERT, cases)
コード例 #4
0
 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)
コード例 #5
0
    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()
コード例 #6
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))
コード例 #7
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))
コード例 #8
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()
コード例 #9
0
ファイル: processors.py プロジェクト: emilkarlen/exactly
def configuration_with_assert_instruction_that_fails(instruction_name: str) -> sut.Configuration:
    assert_instruction_setup = instr_setup(instr.assert_phase_instruction_that(
        main=do_return(pfh.new_pfh_fail('fail error message')))
    )

    instruction_set = InstructionsSetup(
        config_instruction_set={},
        setup_instruction_set={},
        before_assert_instruction_set={},
        assert_instruction_set={instruction_name: assert_instruction_setup},
        cleanup_instruction_set={},
    )
    return configuration_for_instruction_set(instruction_set)
コード例 #10
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,
                 )
             )
         )
コード例 #11
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)
コード例 #12
0
 def runTest(self):
     # ARRANGE #
     the_error_message = 'the error message'
     parts = instruction_parts.InstructionParts(
         ValidatorThat(),
         MainStepExecutorThat(assertion_return_value=pfh.new_pfh_fail(the_error_message),
                              non_assertion_return_value=sh.new_sh_hard_error(the_error_message)))
     parser = self.conf.instruction_parser_from_parts_parser(PartsParserThatGives(parts))
     source = remaining_source('ignored')
     # ACT & ASSERT #
     self.conf.run_test_with_parser(self,
                                    parser,
                                    source,
                                    self.conf.arrangement(),
                                    self.conf.expect_failure_of_main(
                                        assertion_on_error_message=asrt.equals(the_error_message)
                                    ))
コード例 #13
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
    def _failure(self,
                 os_services: OsServices,
                 environment: InstructionEnvironmentForPostSdsStep,
                 err_msg_from_part: TextRenderer
                 ) -> pfh.PassOrFailOrHardError:
        err_msg = err_msg_from_part
        if self._failure_message_header:
            resolving_env = logic_type_resolving_helper.full_resolving_env_for_instruction_env(
                os_services,
                environment
            )
            err_msg = rend_comb.PrependR(
                self._failure_message_header(resolving_env),
                err_msg_from_part,
            )

        return pfh.new_pfh_fail(err_msg)
コード例 #14
0
ファイル: xfail.py プロジェクト: emilkarlen/exactly
    def test_with_assert_phase_that_fails(self):
        test_case = test_case_with_two_instructions_in_each_phase() \
            .add(phase_identifier.CONFIGURATION,
                 test.ConfigurationPhaseInstructionThatSetsExecutionMode(TestCaseStatus.FAIL)) \
            .add(phase_identifier.ASSERT,
                 test.assert_phase_instruction_that(
                     main=do_return(pfh.new_pfh_fail('fail message'))))
        self._check(Arrangement(test_case,
                                execute_test_action=execute_action_that_returns_exit_code(11)),
                    Expectation(
                        asrt_result.matches2(
                            FullExeResultStatus.XFAIL,
                            asrt_result.has_sds(),
                            asrt_result.has_action_to_check_outcome_with_exit_code(11),
                            ExpectedFailureForInstructionFailure.new_with_message(
                                phase_step.ASSERT__MAIN,
                                test_case.the_extra(phase_identifier.ASSERT)[0].source,
                                'fail message'),
                        ),
                        [phase_step.CONFIGURATION__MAIN,
                         phase_step.CONFIGURATION__MAIN] +
                        [phase_step.ACT__PARSE] +
                        SYMBOL_VALIDATION_STEPS__TWICE +
                        PRE_SDS_VALIDATION_STEPS__TWICE +
                        [phase_step.SETUP__MAIN,
                         phase_step.SETUP__MAIN,

                         phase_step.SETUP__VALIDATE_POST_SETUP,
                         phase_step.SETUP__VALIDATE_POST_SETUP,
                         phase_step.ACT__VALIDATE_POST_SETUP,
                         phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                         phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                         phase_step.ASSERT__VALIDATE_POST_SETUP,
                         phase_step.ASSERT__VALIDATE_POST_SETUP,

                         phase_step.ACT__PREPARE,
                         phase_step.ACT__EXECUTE,

                         phase_step.BEFORE_ASSERT__MAIN,
                         phase_step.BEFORE_ASSERT__MAIN,
                         phase_step.ASSERT__MAIN,
                         (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT),
                         (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT),
                         ],
                    ))
コード例 #15
0
ファイル: other_scenarios.py プロジェクト: emilkarlen/exactly
    def test_fail_in_assert_main_step(self):
        test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
            .add(PartialPhase.ASSERT,
                 test.assert_phase_instruction_that(
                     main=do_return(pfh.new_pfh_fail('fail msg from ASSERT'))))
        self._check(
            Arrangement(test_case,
                        act_executor_execute=execute_action_that_returns_exit_code(5)),
            Expectation(
                asrt_result.matches2(
                    PartialExeResultStatus.FAIL,
                    asrt_result.has_sds(),
                    asrt_result.has_action_to_check_outcome_with_exit_code(5),
                    ExpectedFailureForInstructionFailure.new_with_message(
                        phase_step.ASSERT__MAIN,
                        test_case.the_extra(PartialPhase.ASSERT)[0].source,
                        'fail msg from ASSERT'),
                ),
                [phase_step.ACT__PARSE] +

                SYMBOL_VALIDATION_STEPS__TWICE +
                PRE_SDS_VALIDATION_STEPS__TWICE +
                [phase_step.SETUP__MAIN,
                 phase_step.SETUP__MAIN,

                 phase_step.SETUP__VALIDATE_POST_SETUP,
                 phase_step.SETUP__VALIDATE_POST_SETUP,
                 phase_step.ACT__VALIDATE_POST_SETUP,
                 phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                 phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                 phase_step.ASSERT__VALIDATE_POST_SETUP,
                 phase_step.ASSERT__VALIDATE_POST_SETUP,

                 phase_step.ACT__PREPARE,
                 phase_step.ACT__EXECUTE,

                 phase_step.BEFORE_ASSERT__MAIN,
                 phase_step.BEFORE_ASSERT__MAIN,
                 phase_step.ASSERT__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT),
                 ],
            ))
コード例 #16
0
 def test_success_WHEN_actual_is_expected(self):
     # ARRANGE #
     assertion = sut.is_fail__with_arbitrary_message()
     expected_err_msg = 'expected error message'
     cases = [
         NameAndValue(
             'fail',
             pfh.new_pfh_fail(
                 asrt_text_doc.new_single_string_text_for_test(
                     expected_err_msg)),
         ),
         NameAndValue(
             'fail/const msg',
             pfh.new_pfh_fail__str(expected_err_msg),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assertion.apply_without_message(self, case.value)
コード例 #17
0
    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))
コード例 #18
0
 def test_success_WHEN_actual_is_expected(self):
     # ARRANGE #
     expected_err_msg = 'expected error message'
     cases = [
         NEA(
             'fail',
             sut.failure_message_is(
                 asrt_text_doc.is_string_for_test(
                     asrt.equals(expected_err_msg))),
             pfh.new_pfh_fail(
                 asrt_text_doc.new_single_string_text_for_test(
                     expected_err_msg)),
         ),
         NEA(
             'fail/const msg',
             sut.failure_message_is(
                 asrt_text_doc.is_string_for_test(
                     asrt.equals(expected_err_msg))),
             pfh.new_pfh_fail__str(expected_err_msg),
         ),
         NEA(
             'hard error',
             sut.failure_message_is(
                 asrt_text_doc.is_string_for_test(
                     asrt.equals(expected_err_msg))),
             pfh.new_pfh_hard_error(
                 asrt_text_doc.new_single_string_text_for_test(
                     expected_err_msg)),
         ),
         NEA(
             'hard error/const msg',
             sut.failure_message_is(
                 asrt_text_doc.is_string_for_test(
                     asrt.equals(expected_err_msg))),
             pfh.new_pfh_hard_error__str(expected_err_msg),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             case.expected.apply_without_message(self, case.actual)
コード例 #19
0
 def test_success_WHEN_actual_is_not_pass(self):
     # ARRANGE #
     cases = [
         NameAndValue(
             'fail',
             pfh.new_pfh_fail(
                 asrt_text_doc.new_single_string_text_for_test(
                     'failure msg'))),
         NameAndValue('fail/const msg',
                      pfh.new_pfh_fail__str('failure msg')),
         NameAndValue(
             'hard error',
             pfh.new_pfh_hard_error(
                 asrt_text_doc.new_single_string_text_for_test(
                     'hard error msg'))),
         NameAndValue('hard error/const msg',
                      pfh.new_pfh_hard_error__str('hard error msg')),
     ]
     assertion = sut.is_pass()
     for case in cases:
         with self.subTest(case.name):
             # ACT #
             assert_that_assertion_fails(assertion, case.value)
コード例 #20
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)
コード例 #21
0
ファイル: error_info.py プロジェクト: emilkarlen/exactly
 def as_pfh_fail(self) -> pfh.PassOrFailOrHardError:
     return pfh.new_pfh_fail(self.error_message())
コード例 #22
0
ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY__NAME = 'ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY'


def test_suite_definition_with_single_conf_instruction(name: str,
                                                       instruction: ConfigurationSectionInstruction
                                                       ) -> TestSuiteDefinition:
    configuration_section_instructions = {
        name: single_instruction_setup(name, instruction)

    }
    return test_suite_definition_with_instructions(configuration_section_instructions)


ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY = assert_phase_instruction_that(
    main=do_return(pfh.new_pfh_fail('unconditional failure')))


def assert_phase_instruction_that_pass_iff_stdout_is_success_indicator_string(expected: str) -> AssertPhaseInstruction:
    return AssertPhaseInstructionThatPassIffStdoutEqualsString(expected)


class AssertPhaseInstructionThatPassIffStdoutEqualsString(AssertPhaseInstruction):
    def __init__(self, expected: str):
        self.expected = expected

    def main(self,
             environment: InstructionEnvironmentForPostSdsStep,
             os_services: OsServices) -> pfh.PassOrFailOrHardError:
        actual_contents = environment.sds.result.stdout_file.read_text()
        if actual_contents == self.expected: