Beispiel #1
0
 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__INTERNAL_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__str('fail msg'))),
             EXECUTION__HARD_ERROR:
             assert_phase_instruction_that(main=do_return(
                 pfh.new_pfh_hard_error__str('hard error msg'))),
             EXECUTION__INTERNAL_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)
Beispiel #2
0
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__str('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)
Beispiel #3
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)
Beispiel #4
0
 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__str('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),
             ],
         ))
 def runTest(self):
     # ARRANGE #
     the_error_message = 'the error message'
     parts = instruction_parts.InstructionParts(
         SdvValidatorThat(),
         MainStepExecutorThat(
             assertion_return_value=pfh.new_pfh_fail__str(
                 the_error_message),
             non_assertion_return_value=sh.new_sh_hard_error__str(
                 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_text_doc.
             is_single_pre_formatted_text_that_equals(the_error_message)))
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
 def test_fail(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.ASSERT,
              test.assert_phase_instruction_that(
                  main=do_return(pfh.new_pfh_fail__str('fail msg from ASSERT'))))
     self._check(
         Arrangement(test_case,
                     atc_execute=execute_action_that_returns_exit_code(5)),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.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__VALIDATE_EXE_INPUT,
                 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),
             ],
         ))
Beispiel #9
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 #10
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)
Beispiel #11
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)
Beispiel #12
0
 def test_unsuccessful_WHEN_actual_is_not_expected(self):
     # ARRANGE #
     expected_err_msg = 'expected error message'
     actual_err_msg = 'actual 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__str(actual_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__str(actual_err_msg),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assert_that_assertion_fails(case.expected, case.actual)
Beispiel #13
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__str('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,
             settings: InstructionSettings,
             os_services: OsServices) -> pfh.PassOrFailOrHardError:
        actual_contents = environment.sds.result.stdout_file.read_text()