def __init__( self, validation_post_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), validation_pre_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_result: Assertion[pfh.PassOrFailOrHardError] = pfh_assertions.is_pass(), symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence, main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(), main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(), source: Assertion[ParseSource] = asrt.anything_goes(), main_raises_hard_error: bool = False, proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt.is_instance(InstructionSettings) ): super().__init__( symbol_usages, ExecutionExpectation( validation_post_sds, validation_pre_sds, main_result, main_raises_hard_error, main_side_effects_on_sds, main_side_effects_on_tcds, proc_exe_settings, instruction_settings, ) ) self.source = source self.symbol_usages = symbol_usages
def __new__(cls, validation_post_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), validation_pre_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_result: Assertion[pfh.PassOrFailOrHardError] = pfh_assertions.is_pass(), main_raises_hard_error: bool = False, main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(), main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(), proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt.is_instance(InstructionSettings) ): return tuple.__new__(cls, ( validation_post_sds, validation_pre_sds, main_result, main_raises_hard_error, main_side_effects_on_sds, main_side_effects_on_tcds, proc_exe_settings, instruction_settings ))
def __init__( self, validation_pre_sds: Assertion = svh_assertions.is_success(), validation_post_setup: Assertion = svh_assertions.is_success(), main_result: Assertion[ sh.SuccessOrHardError] = sh_assertions.is_success(), symbol_usages: Assertion = asrt.is_empty_sequence, main_side_effects_on_sds: Assertion = asrt.anything_goes(), main_side_effects_on_tcds: Assertion = asrt.anything_goes(), source: Assertion = asrt.anything_goes(), proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt. is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt. is_instance(InstructionSettings), ): super().__init__( validation_pre_sds, validation_post_setup, main_result, symbol_usages, main_side_effects_on_sds, main_side_effects_on_tcds, proc_exe_settings, instruction_settings, ) self.source = source
def __init__(self, validation_pre_sds: ValueAssertion = svh_assertions.is_success(), validation_post_setup: ValueAssertion = svh_assertions.is_success(), main_result: ValueAssertion = sh_assertions.is_success(), symbol_usages: ValueAssertion = asrt.is_empty_sequence, main_side_effects_on_sds: ValueAssertion = asrt.anything_goes(), main_side_effects_on_home_and_sds: ValueAssertion = asrt.anything_goes(), source: ValueAssertion = asrt.anything_goes(), ): super().__init__(validation_pre_sds, main_side_effects_on_sds, main_side_effects_on_home_and_sds, symbol_usages) self.validation_post_setup = validation_post_setup self.main_result = sh_assertions.is_sh_and(main_result) self.source = source
def hard_error__post_sds( error_message: Assertion[TextRenderer] = asrt_text_doc.is_any_text( )) -> 'ValidationExpectationSvh': return ValidationExpectationSvh( pre_sds=asrt_svh.is_success(), post_sds=asrt_svh.is_hard_error(error_message), )
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')
def test_WHEN_a_successful_validator_is_given_THEN_validation_SHOULD_succeed(self): # ARRANGE # assertion_part_without_validation = PartForValidation(ConstantSuccessValidator()) instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_without_validation, 'custom environment', lambda env: 'argument to assertion_part') with self.subTest(name='pre sds validation'): # ACT # actual = instruction.validate_pre_sds(self.environment) # ASSERT # asrt_svh.is_success().apply_without_message(self, actual) with self.subTest(name='post setup validation'): # ACT # actual = instruction.validate_post_setup(self.environment) # ASSERT # asrt_svh.is_success().apply_without_message(self, actual)
def test_success(self): # ARRANGE # error_message = 'validation error' # ACT # actual = sut.translate_svh_exception_to_svh(test_action, DO_SUCCESS, error_message) # ASSERT # expectation = asrt_svh.is_success() expectation.apply_without_message(self, actual)
def test_success(self): # ARRANGE # error_message = 'validation error' # ACT # actual = sut.translate_svh_exception_to_svh(test_action, DO_SUCCESS, error_message) # ASSERT # expectation = asrt_svh.is_success() expectation.apply_without_message(self, actual)
def test_WHEN_given_validator_fails_post_setup_THEN_validation_SHOULD_fail_post_setup(self): # ARRANGE # the_error_message = 'the error message' assertion_part = PartForValidation(ValidatorThat( post_setup_return_value=the_error_message)) instruction = sut.AssertionInstructionFromAssertionPart(assertion_part, 'custom environment', lambda env: 'argument to assertion_part') # ACT # pre_sds_result = instruction.validate_pre_sds(self.environment) post_sds_result = instruction.validate_post_setup(self.environment) # ASSERT # asrt_svh.is_success().apply_with_message(self, pre_sds_result, 'pre sds validation should succeed') assertion = asrt_svh.is_validation_error(asrt.equals(the_error_message)) assertion.apply_with_message(self, post_sds_result, 'post setup validation should fail')
def test_WHEN_a_successful_validator_is_given_THEN_validation_SHOULD_succeed(self): # ARRANGE # environment = fake_post_sds_environment() assertion_part_without_validation = PartForValidation(ConstantSuccessSdvValidator()) instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_without_validation, lambda env: 'argument to assertion_part') with self.subTest(name='pre sds validation'): # ACT # actual = instruction.validate_pre_sds(environment) # ASSERT # asrt_svh.is_success().apply_without_message(self, actual) with self.subTest(name='post setup validation'): # ACT # actual = instruction.validate_post_setup(environment) # ASSERT # asrt_svh.is_success().apply_without_message(self, actual)
def test_validation_pre_sds(self): the_instruction_environment = instruction_environment.fake_pre_sds_environment() cases = [ ( 'validation should succeed when both operands succeed', asrt_svh.is_success(), operand_resolver_that(), operand_resolver_that(), ), ( 'validation exception in left operand', asrt_svh.is_validation_error(asrt.equals('error in left op')), operand_resolver_that( validate_pre_sds=actions.do_raise(SvhValidationException('error in left op'))), operand_resolver_that(), ), ( 'validation exception in right operand', asrt_svh.is_validation_error(asrt.equals('error in right op')), operand_resolver_that(), operand_resolver_that( validate_pre_sds=actions.do_raise(SvhValidationException('error in right op'))), ), ( 'hard error exception in left operand', asrt_svh.is_hard_error(asrt.equals('error in left op')), operand_resolver_that( validate_pre_sds=actions.do_raise(SvhHardErrorException('error in left op'))), operand_resolver_that(), ), ( 'hard error exception in right operand', asrt_svh.is_hard_error(asrt.equals('error in right op')), operand_resolver_that(), operand_resolver_that( validate_pre_sds=actions.do_raise(SvhHardErrorException('error in right op'))), ), ] for name, result_assertion, l_op, r_op in cases: instruction_to_check = sut.Instruction(cmp_setup(l_op, r_op)) with self.subTest(name=name): # ACT # actual = instruction_to_check.validate_pre_sds(the_instruction_environment) # ASSERT # result_assertion.apply_without_message(self, actual)
def runTest(self): path_argument_str = 'path-argument' self._check( syntax_for_assignment_of(path_argument_str), Arrangement( root_dir_contents=DirContents([Dir.empty(path_argument_str)])), Expectation( main_result=svh_assertions.is_success(), path_rel_root_2_conf=self.conf_prop_equals( lambda path_rel_root: path_rel_root / path_argument_str)))
def __init__(self, pre_validation_result: ValueAssertion = svh_assertions.is_success(), main_result: ValueAssertion = sh_assertions.is_success(), post_validation_result: ValueAssertion = svh_assertions.is_success(), symbol_usages: ValueAssertion = asrt.is_empty_sequence, main_side_effects_on_sds: ValueAssertion = asrt.anything_goes(), main_side_effects_on_home_and_sds: ValueAssertion = asrt.anything_goes(), settings_builder: ValueAssertion = asrt.anything_goes(), source: ValueAssertion = asrt.anything_goes(), symbols_after_main: ValueAssertion = asrt.anything_goes(), ): self.pre_validation_result = pre_validation_result self.main_result = main_result self.main_side_effects_on_sds = main_side_effects_on_sds self.post_validation_result = post_validation_result self.settings_builder = settings_builder self.main_side_effects_on_home_and_sds = main_side_effects_on_home_and_sds self.source = source self.symbol_usages = symbol_usages self.symbols_after_main = symbols_after_main
def __init__( self, validation_post_sds: ValueAssertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), validation_pre_sds: ValueAssertion[svh.SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_result: ValueAssertion[pfh.PassOrFailOrHardError] = pfh_assertions.is_pass(), symbol_usages: ValueAssertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence, main_side_effects_on_sds: ValueAssertion[SandboxDirectoryStructure] = asrt.anything_goes(), main_side_effects_on_home_and_sds: ValueAssertion[HomeAndSds] = asrt.anything_goes(), source: ValueAssertion[ParseSource] = asrt.anything_goes(), ): self.validation_post_sds = validation_post_sds self.validation_pre_sds = validation_pre_sds self.main_result = main_result self.main_side_effects_on_sds = main_side_effects_on_sds self.main_side_effects_on_home_and_sds = main_side_effects_on_home_and_sds self.source = source self.symbol_usages = symbol_usages
def __init__( self, pre_validation_result: Assertion[ svh. SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_result: Assertion[ sh.SuccessOrHardError] = sh_assertions.is_success(), post_validation_result: Assertion[ svh. SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), symbol_usages: Assertion[ Sequence[SymbolUsage]] = asrt.is_empty_sequence, main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(), main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes( ), settings_builder: Assertion[ SettingsBuilderAssertionModel] = asrt_settings. stdin_is_not_present(), source: Assertion[ParseSource] = asrt.anything_goes(), symbols_after_main: Assertion[ Sequence[SymbolUsage]] = asrt.anything_goes(), proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt. is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt. is_instance(InstructionSettings)): super().__init__( ValidationExpectationSvh(pre_validation_result, post_validation_result), main_result, symbol_usages, main_side_effects_on_sds, main_side_effects_on_tcds, settings_builder, symbols_after_main, proc_exe_settings, instruction_settings, ) self.source = source self.pre_validation_result = pre_validation_result self.post_validation_result = post_validation_result
def __init__(self, result_of_validate_pre_sds: ValueAssertion = svh_assertions.is_success(), result_of_prepare: ValueAssertion = sh_assertions.is_success(), result_of_execute: ValueAssertion = eh_assertions.is_any_exit_code, symbol_usages: ValueAssertion = asrt.is_empty_sequence, side_effects_on_files_after_execute: ValueAssertion = asrt.anything_goes(), side_effects_on_files_after_prepare: ValueAssertion = asrt.anything_goes(), sub_process_result_from_execute: ValueAssertion = asrt.anything_goes()): self.result_of_validate_pre_sds = result_of_validate_pre_sds self.symbol_usages = symbol_usages self.side_effects_on_files_after_prepare = side_effects_on_files_after_prepare self.side_effects_on_files_after_execute = side_effects_on_files_after_execute self.result_of_prepare = result_of_prepare self.result_of_execute = result_of_execute self.sub_process_result_from_execute = sub_process_result_from_execute
def __init__( self, validation_pre_sds: Assertion[ svh. SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(), main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes( ), symbol_usages: Assertion[ Sequence[SymbolUsage]] = asrt.is_empty_sequence, proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt. is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt. is_instance(InstructionSettings), ): self._validation_pre_sds = svh_assertions.is_svh_and( validation_pre_sds) self._main_side_effects_on_sds = main_side_effects_on_sds self._main_side_effects_on_tcds = main_side_effects_on_tcds self._symbol_usages = symbol_usages self._proc_exe_settings = proc_exe_settings self._instruction_settings = instruction_settings
def __init__( self, act_result: SubProcessResult = SubProcessResult(), validate_pre_sds_result: Assertion[ svh. SuccessOrValidationErrorOrHardError] = svh_assertions.is_success(), main_result: Assertion[ sh.SuccessOrHardError] = sh_assertions.is_success(), symbol_usages: Assertion[ Sequence[SymbolUsage]] = asrt.is_empty_sequence, main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(), main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes( ), proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt. is_instance(ProcessExecutionSettings), instruction_settings: Assertion[InstructionSettings] = asrt. is_instance(InstructionSettings), ): super().__init__(validate_pre_sds_result, main_side_effects_on_sds, main_side_effects_on_tcds, symbol_usages, proc_exe_settings, instruction_settings) self._act_result = act_result self._main_result = main_result
def test_success_WHEN_actual_is_not_success(self): # ARRANGE # cases = [ NameAndValue( 'VALIDATION_ERROR', svh.new_svh_validation_error( asrt_text_doc.new_single_string_text_for_test( 'failure msg'))), NameAndValue('VALIDATION_ERROR/const msg', svh.new_svh_validation_error__str('failure msg')), NameAndValue( 'HARD_ERROR', svh.new_svh_hard_error( asrt_text_doc.new_single_string_text_for_test( 'hard error msg'))), NameAndValue('HARD_ERROR/const msg', svh.new_svh_hard_error__str('hard error msg')), ] assertion = sut.is_success() for case in cases: with self.subTest(case.name): # ACT # assert_that_assertion_fails(assertion, case.value)
def _mk_validation_assertion( passes: bool) -> Assertion[svh.SuccessOrValidationErrorOrHardError]: return (asrt_svh.is_success() if passes else asrt_svh.is_validation_error())
def passes() -> 'ValidationExpectationSvh': return ValidationExpectationSvh( pre_sds=asrt_svh.is_success(), post_sds=asrt_svh.is_success(), )
def test_success_WHEN_actual_is_success(self): # ARRANGE # assertion = sut.is_success() actual = svh.new_svh_success() # ACT # assertion.apply_without_message(self, actual)
def _svh_from_actual_for_test_err_msg( actual: Optional[str] ) -> Assertion[svh.SuccessOrValidationErrorOrHardError]: return (asrt_svh.is_success() if actual is None else asrt_svh.is_validation_error( asrt_text_doc.is_string_for_test_that_equals(actual)))
def all_validations_passes__svh() -> ValidationExpectationSvh: return ValidationExpectationSvh( pre_sds=asrt_svh.is_success(), post_sds=asrt_svh.is_success(), )
def post_sds_validation_fails__svh(error_message: ValueAssertion[str] = asrt.is_instance(str) ) -> ValidationExpectationSvh: return ValidationExpectationSvh( pre_sds=asrt_svh.is_success(), post_sds=asrt_svh.is_validation_error(error_message), )
def _svh_from_bool( passes_validation: bool ) -> Assertion[svh.SuccessOrValidationErrorOrHardError]: return (asrt_svh.is_success() if passes_validation else asrt_svh.is_validation_error())