Exemplo n.º 1
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(
             'VALIDATION - SUCCESS/any error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.
                 VALIDATION_ERROR),
             svh.new_svh_success(),
         ),
         NEA(
             'VALIDATION - VALIDATION/non-matching error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.
                 VALIDATION_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_validation_error(_renderer_of_str(actual_err_msg)),
         ),
         NEA(
             'VALIDATION - VALIDATION/non-matching error message/const msg',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.
                 VALIDATION_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_validation_error__str(actual_err_msg),
         ),
         NEA(
             'HARD_ERROR - SUCCESS/any error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.HARD_ERROR),
             svh.new_svh_success(),
         ),
         NEA(
             'HARD_ERROR - HARD_ERROR/non-matching error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.HARD_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_hard_error(_renderer_of_str(actual_err_msg)),
         ),
         NEA(
             'HARD_ERROR - HARD_ERROR/non-matching error message/const msg',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.HARD_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_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)
Exemplo n.º 2
0
    def test_WHEN_given_validator_fails_post_setup_THEN_main_SHOULD_report_hard_error(self):
        # ARRANGE #
        environment = fake_post_sds_environment()

        the_error_message = 'the error message'
        assertion_part = PartForValidation(SdvValidatorThat(
            post_setup_return_value=asrt_text_doc.new_single_string_text_for_test(the_error_message))
        )
        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part,
                                                                lambda env: 'argument to assertion_part')
        is_validation_success = asrt_svh.is_success()
        main_result_is_hard_error = asrt_pfh.is_hard_error(
            asrt_text_doc.is_single_pre_formatted_text_that_equals(the_error_message)
        )

        # ACT & ASSERT #

        pre_sds_result = instruction.validate_pre_sds(environment)
        is_validation_success.apply_with_message(self, pre_sds_result,
                                                 'pre sds validation should succeed')
        post_sds_result = instruction.validate_post_setup(environment)
        is_validation_success.apply_with_message(self, post_sds_result,
                                                 'post setup validation should succeed')
        main_result = instruction.main(environment,
                                       optionally_from_proc_exe_settings(None, environment.proc_exe_settings),
                                       self.the_os_services)

        main_result_is_hard_error.apply_with_message(self,
                                                     main_result,
                                                     'main should fail')
Exemplo n.º 3
0
 def test_hard_error(self):
     # ARRANGE #
     error_message = 'hard error'
     # ACT #
     actual = sut.translate_svh_exception_to_svh(test_action, DO_HARD_ERROR,
                                                 error_message)
     # ASSERT #
     expectation = asrt_svh.is_hard_error(
         asrt_text_doc.is_single_pre_formatted_text_that_equals(
             error_message))
     expectation.apply_without_message(self, actual)
Exemplo n.º 4
0
 def test_success_WHEN_actual_is_expected(self):
     # ARRANGE #
     expected_err_msg = 'expected error message'
     cases = [
         NEA(
             'VALIDATION/any error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.
                 VALIDATION_ERROR),
             svh.new_svh_validation_error__str(expected_err_msg),
         ),
         NEA(
             'VALIDATION/matching error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.
                 VALIDATION_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_validation_error__str(expected_err_msg),
         ),
         NEA(
             'HARD_ERROR/any error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.HARD_ERROR),
             svh.new_svh_hard_error__str(expected_err_msg),
         ),
         NEA(
             'HARD_ERROR/matching error message',
             sut.status_is_not_success(
                 svh.SuccessOrValidationErrorOrHardErrorEnum.HARD_ERROR,
                 asrt_text_doc.is_single_pre_formatted_text_that_equals(
                     expected_err_msg)),
             svh.new_svh_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)
Exemplo n.º 5
0
    def test_WHEN_given_validator_fails_pre_sds_THEN_validation_SHOULD_fail_pre_sds(self):
        # ARRANGE #
        environment = fake_post_sds_environment()

        the_error_message = 'the error message'
        assertion_part = PartForValidation(SdvValidatorThat(
            pre_sds_return_value=asrt_text_doc.new_single_string_text_for_test(the_error_message))
        )
        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part,
                                                                lambda env: 'argument to assertion_part')
        # ACT #
        actual = instruction.validate_pre_sds(environment)
        # ASSERT #
        assertion = asrt_svh.is_validation_error(
            asrt_text_doc.is_single_pre_formatted_text_that_equals(the_error_message)
        )
        assertion.apply_without_message(self, actual)
Exemplo n.º 6
0
 def test_WHEN_a_failing_assertion_part_SHOULD_stop_execution_and_report_the_failure(self):
     # ARRANGE #
     assertion_part = sut.SequenceOfCooperativeAssertionParts([
         SuccessfulPartThatReturnsConstructorArgPlusOne(),
         PartThatRaisesFailureExceptionIfArgumentIsEqualToOne(),
         SuccessfulPartThatReturnsConstructorArgPlusOne(),
     ])
     # ACT & ASSERT #
     with self.assertRaises(pfh_exception.PfhFailException) as cm:
         assertion_part.check(self.environment, self.the_os_services, 0)
     assertion = asrt_text_doc.is_single_pre_formatted_text_that_equals(
         PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE
     )
     assertion.apply_with_message(
         self,
         cm.exception.err_msg,
         'error message from failing assertion_part should appear in PFH exception'
     )
Exemplo n.º 7
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)
Exemplo n.º 8
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)