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)
def test_unsuccessful_WHEN_actual_is_not_expected(self): # ARRANGE # assertion = sut.is_fail__with_arbitrary_message() cases = [ NameAndValue( 'pass', pfh.new_pfh_pass(), ), NameAndValue( 'hard error', pfh.new_pfh_hard_error__str('error message'), ), ] for case in cases: with self.subTest(case.name): # ACT & ASSERT # assert_that_assertion_fails(assertion, case.value)
def test_success_WHEN_actual_is_expected(self): # ARRANGE # assertion = sut.is_hard_error__with_arbitrary_message() expected_err_msg = 'expected error message' cases = [ NameAndValue( 'hard error', pfh.new_pfh_hard_error( asrt_text_doc.new_single_string_text_for_test( expected_err_msg)), ), NameAndValue( 'hard error/const msg', pfh.new_pfh_hard_error__str(expected_err_msg), ), ] for case in cases: with self.subTest(case.name): # ACT & ASSERT # assertion.apply_without_message(self, case.value)
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)
def test_hard_error(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.ASSERT, test.assert_phase_instruction_that( main=do_return(pfh.new_pfh_hard_error__str('hard error msg from ASSERT')))) self._check( Arrangement(test_case, atc_execute=execute_action_that_returns_exit_code(72)), Expectation( asrt_result.matches2( ExecutionFailureStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(72), ExpectedFailureForInstructionFailure.new_with_message( phase_step.ASSERT__MAIN, test_case.the_extra(PartialPhase.ASSERT)[0].source, 'hard error 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), ], ))
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)
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)
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 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)
def translate_for_assertion( self, error_message: str) -> pfh.PassOrFailOrHardError: return (pfh.new_pfh_pass() if error_message is None else pfh.new_pfh_hard_error__str(error_message))