def test_hard_error_in_setup_main_step(self):
     py_pgm_setup = PyProgramSetup('some output to stdout',
                                   'some output to stderr', 72)
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr(
         act_phase_source=py_pgm_setup.as_line_sequence()) \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error__str('hard error msg from setup'))))
     self._check(
         arr_for_py3_source(test_case),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             atc_stdout_output=asrt.equals(''),
             atc_stderr_output=asrt.equals(''),
             step_recordings=[phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE + [
                 phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
             ],
         ))
Beispiel #2
0
 def test_pass(self):
     the_error_message = 'error message'
     cases = [
         NEA('no assertion on error message',
             asrt.anything_goes(),
             sh.new_sh_hard_error__str(the_error_message),
             ),
         NEA('assertion on error message',
             asrt_text_doc.is_single_pre_formatted_text_that_equals(the_error_message),
             sh.new_sh_hard_error__str(the_error_message),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ARRANGE #
             assertion = sut.is_hard_error(case.expected)
             # ACT #
             assertion.apply_without_message(self, case.actual)
 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 #4
0
 def test_fail(self):
     the_error_message = 'error message'
     cases = [
         NEA('is success',
             asrt.anything_goes(),
             sh.new_sh_success(),
             ),
         NEA('assertion on error message fails',
             asrt_text_doc.is_single_pre_formatted_text_that_equals(
                 the_error_message + ' - part of message not in actual'
             ),
             sh.new_sh_hard_error__str(the_error_message),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ARRANGE #
             assertion = sut.is_hard_error(case.expected)
             # ACT #
             assert_that_assertion_fails(assertion, case.actual)
Beispiel #5
0
 def test_hard_error(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.CLEANUP,
              test.cleanup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error__str('hard error msg from CLEANUP'))))
     self._check(
         Arrangement(test_case,
                     atc_execute=execute_action_that_returns_exit_code(3)),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_action_to_check_outcome_with_exit_code(3),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.CLEANUP__MAIN,
                     test_case.the_extra(PartialPhase.CLEANUP)[0].source,
                     'hard error msg from CLEANUP'),
             ),
             [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.ASSERT__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT),
             ],
         ))
Beispiel #6
0
 def test_hard_error(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error__str('hard error msg from setup'))))
     self._check(
         Arrangement(test_case),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE + [
                 phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
             ],
         ))
Beispiel #7
0
 def translate_for_non_assertion(
         self, error_message: str) -> sh.SuccessOrHardError:
     return (sh.new_sh_success() if error_message is None else
             sh.new_sh_hard_error__str(error_message))
Beispiel #8
0
        len(lines) > 0,
        'There should be at least one line (found {})'.format(len(lines)))

    first_line = lines[0]

    put.assertEqual(expected_exit_value.exit_identifier, first_line,
                    'first line')


DO_RAISES_EXCEPTION = do_raise(ValueError('implementation error msg'))

SVH_VALIDATION_ERROR = do_return(
    svh.new_svh_validation_error__str('validation error msg'))
SVH_HARD_ERROR = do_return(svh.new_svh_hard_error__str('hard error msg'))

SH_HARD_ERROR = do_return(sh.new_sh_hard_error__str('hard error msg'))


def output_is_sds_which_should_be_preserved(
        sds_dir_name: str) -> Assertion[str]:
    return asrt.and_([
        IsExistingDir(sds_dir_name),
        asrt.equals(sds_dir_name + '\n'),
    ])


def output_is_empty(sds_dir_name: str) -> Assertion[str]:
    return asrt.equals('')


class IsExistingDir(AssertionBase[Any]):
Beispiel #9
0
 def test_fail(self):
     # ARRANGE #
     actual = sh.new_sh_hard_error__str('failure msg')
     assertion = sut.is_success()
     # ACT #
     assert_that_assertion_fails(assertion, actual)