def test_evaluation_of_comparison(self): the_instruction_environment = instruction_environment.fake_post_sds_environment() the_os_services = os_services.new_default() cases = [ ( 'expectation type is positive: pass WHEN comparison succeeds', asrt_pfh.is_pass(), ExpectationType.POSITIVE, 1, comparators.LT, 2, ), ( 'expectation type is positive: fail WHEN comparison does not succeeds', asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING), ExpectationType.POSITIVE, 1, comparators.LT, 1, ), ( 'expectation type is negative: fail WHEN comparison succeeds', asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING), ExpectationType.NEGATIVE, 1, comparators.LT, 2, ), ( 'expectation type is negative: pass WHEN comparison does not succeeds', asrt_pfh.is_pass(), ExpectationType.NEGATIVE, 1, comparators.LT, 1, ), ] for name, result_assertion, expectation_type, l_op, op, r_op in cases: # ARRANGE # instruction_to_check = sut.Instruction( ComparisonHandler(THE_PROPERTY_DESCRIPTOR, expectation_type, operand_resolver_that( resolve_return_value_action=do_return(l_op)), op, operand_resolver_that( resolve_return_value_action=do_return(r_op)))) with self.subTest(name=name): # ACT # actual = instruction_to_check.main(the_instruction_environment, the_os_services) # ASSERT # result_assertion.apply_without_message(self, actual)
def runTest(self): sb = SB.new_with(constant_transformation_arguments=argument_syntax.syntax_for_transformer_option( argument_syntax.syntax_for_replace_transformer('a', 'A') )) cases = [ Case('CONTENTS-MATCHER on separate line', source= self.configuration.source_for_lines( sb.format_lines(['', '{empty}'])), source_assertion= asrt_source.source_is_at_end, main_result_assertion= pfh_assertions.is_pass(), ), Case('transformation and CONTENTS-MATCHER on separate line', source= self.configuration.source_for_lines( sb.format_lines(['', '{constant_transformation_arguments}', '{empty}'])), source_assertion= asrt_source.source_is_at_end, main_result_assertion= pfh_assertions.is_pass(), ), Case('negation and CONTENTS-MATCHER on separate line', source= self.configuration.source_for_lines( sb.format_lines(['', '{not}', '{empty}'])), source_assertion= asrt_source.source_is_at_end, main_result_assertion= pfh_assertions.is_fail(), ), ] for case in cases: with self.subTest(case.name): self._check( case.source, self.configuration.arrangement_for_contents( actual_contents='', post_sds_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY), Expectation(main_result=case.main_result_assertion, source=case.source_assertion), )
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 test_stdin_is_contents_of_string_source_WHEN_program_defines_single_stdin( self): # ARRANGE # test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): all_symbols = list( pgm_and_args_case.symbols) + [CONST_TRUE_INT_MATCHER_SYMBOL] with self.subTest(pgm_and_args_case.name): # ACT & ASSERT # CHECKER.check__abs_stx__source_variants( self, InstructionArguments( test_setup.program_w_stdin_syntax( pgm_and_args_case.pgm_and_args), CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts( all_symbols), process_execution=test_setup. proc_exe_env__w_stdin_check, tcds=TcdsArrangementPostAct( tcds_contents=pgm_and_args_case.tcds, ), ), MultiSourceExpectation( symbol_usages=SymbolContext. usages_assertion_of_contexts(all_symbols), execution=ExecutionExpectation( main_result=asrt_pfh.is_pass()), ), )
def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin( self): # ARRANGE # test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0) all_symbols = [ test_setup.program_symbol, CONST_TRUE_INT_MATCHER_SYMBOL ] # ACT & ASSERT # CHECKER.check__abs_stx__source_variants( self, InstructionArguments( test_setup.program_w_stdin_syntax, CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=test_setup.proc_exe_env__w_stdin_check, ), MultiSourceExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()), ), )
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 test_pass(self): # ARRANGE # error_message = 'should not be raised error' # ACT # actual = sut.translate_pfh_exception_to_pfh(test_action, DO_SUCCESS, error_message) # ASSERT # expectation = asrt_pfh.is_pass() expectation.apply_without_message(self, actual)
def test_return_pfh_pass_WHEN_no_exception_is_raised(self): # ARRANGE # assertion_part_that_not_raises = SuccessfulPartThatReturnsConstructorArgPlusOne() # ACT # actual = assertion_part_that_not_raises.check_and_return_pfh(self.environment, self.the_os_services, 1) # ASSERT # assertion = asrt_pfh.is_pass() assertion.apply_without_message(self, actual)
def test_return_pfh_pass_WHEN_no_exception_is_raised(self): # ARRANGE # assertion_part_that_not_raises = SuccessfulPartThatReturnsConstructorArgPlusOne() instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_that_not_raises, 'custom environment', lambda env: 0) # ACT # actual = instruction.main(self.environment, self.the_os_services) # ASSERT # assertion = asrt_pfh.is_pass() assertion.apply_without_message(self, actual)
def test_return_pfh_pass_WHEN_no_exception_is_raised(self): # ARRANGE # assertion_part_that_not_raises = SuccessfulPartThatReturnsConstructorArgPlusOne() # ACT # actual = assertion_part_that_not_raises.check_and_return_pfh(self.environment, self.the_os_services, 'custom environment', 1) # ASSERT # assertion = asrt_pfh.is_pass() assertion.apply_without_message(self, actual)
def runTest(self): self.configuration.checker.check__abs_stx__source_variants( self, self.configuration.syntax_for_matcher(EmptyAbsStx()), self.configuration.arrangement_for_contents( '', post_sds_population_action= MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, ).as_arrangement_2(), MultiSourceExpectation(execution=ExecutionExpectation( main_result=asrt_pfh.is_pass(), )), )
def test_return_pfh_pass_WHEN_no_exception_is_raised(self): # ARRANGE # environment = fake_post_sds_environment() assertion_part_that_not_raises = SuccessfulPartThatReturnsConstructorArgPlusOne() instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_that_not_raises, lambda env: 0) # ACT # actual = instruction.main(environment, optionally_from_proc_exe_settings(None, environment.proc_exe_settings), self.the_os_services) # ASSERT # assertion = asrt_pfh.is_pass() assertion.apply_without_message(self, actual)
def test_with_symbol_references(self): symbol_1_name = 'symbol_1_name' symbol_2_name = 'symbol_2_name' test_cases = [ CaseWithSymbols( 'two argument form with a symbol that is a single integer', argument=' {op} {sym_ref}'.format(op=comparators.EQ.name, sym_ref=symbol_reference_syntax_for_name(symbol_1_name)), symbol_name_and_value_list=[NameAndValue(symbol_1_name, '72')], actual_value_for_pass=72, actual_value_for_fail=87, ), CaseWithSymbols( 'two argument form with two symbols that makes up the expected value when concatenated', argument=' {op} {sym_ref1}{sym_ref2}'.format( op=comparators.EQ.name, sym_ref1=symbol_reference_syntax_for_name(symbol_1_name), sym_ref2=symbol_reference_syntax_for_name(symbol_2_name)), symbol_name_and_value_list=[NameAndValue(symbol_1_name, '7'), NameAndValue(symbol_2_name, '2')], actual_value_for_pass=72, actual_value_for_fail=87, ), ] for case in test_cases: for sub_name, actual_value, result_expectation in [('pass', case.actual_value_for_pass, pfh_assertions.is_pass()), ('fail', case.actual_value_for_fail, pfh_assertions.is_fail())]: with self.subTest(name=case.name, sub_name=sub_name): self._run( remaining_source(case.argument, ['following line']), ArrangementPostAct( act_result_producer=act_result_of(actual_value), symbols=symbol_table_with_string_constant_symbols(case.symbol_name_and_value_list), ), Expectation( source=is_at_beginning_of_line(2), main_result=result_expectation, symbol_usages=equals_symbol_references( string_symbol_references_of(case.symbol_name_and_value_list)) ), )
def expectation( validation: ValidationExpectationSvh = all_validations_passes__svh(), 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(), ) -> Expectation: return Expectation( validation_pre_sds=validation.pre_sds, validation_post_sds=validation.post_sds, main_result=main_result, symbol_usages=symbol_usages, main_side_effects_on_sds=main_side_effects_on_sds, main_side_effects_on_home_and_sds=main_side_effects_on_home_and_sds, source=source, )
def runTest(self): test_setup = test_setups__proc_exe_set.TimeoutTestSetup( self, expected_timeout=72) # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( test_setup.valid_program_wo_sym_refs(), CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax, ), ArrangementPostAct2( symbols=CONST_TRUE_INT_MATCHER_SYMBOL.symbol_table, process_execution=test_setup.proc_exe_arr__w_settings_check, ), Expectation2( ParseExpectation(symbol_usages=CONST_TRUE_INT_MATCHER_SYMBOL. usages_assertion), ExecutionExpectation(main_result=asrt_pfh.is_pass()), ))
def expectation( validation: ValidationExpectationSvh = ValidationExpectationSvh.passes(), 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(), instruction_settings: Assertion[InstructionSettings] = asrt.is_instance(InstructionSettings) ) -> Expectation: return Expectation( validation_pre_sds=validation.pre_sds, validation_post_sds=validation.post_sds, main_result=main_result, symbol_usages=symbol_usages, main_side_effects_on_sds=main_side_effects_on_sds, main_side_effects_on_tcds=main_side_effects_on_tcds, instruction_settings=instruction_settings, source=source, )
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 runTest(self): # ARRANGE # test_setup = StdinCheckWithProgramWExitCode0ForSuccess() # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( test_setup.program_that_checks_stdin__syntax( 'the contents of stdin'), CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax, ), ArrangementPostAct2( symbols=CONST_TRUE_INT_MATCHER_SYMBOL.symbol_table, tcds=TcdsArrangementPostAct( tcds_contents=test_setup.tcds_contents, )), Expectation2( ParseExpectation(symbol_usages=CONST_TRUE_INT_MATCHER_SYMBOL. usages_assertion, ), execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()), ), )
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value( 'PROGRAM_SYMBOL') const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant( 'CONST_TRUE_INT_MATCHER', result=True, ) string_transformer_that_reports_failure_if_applied = StringTransformerSymbolContext.of_primitive( 'STRING_TRANSFORMER_THAT_MUST_NOT_BE_USED', StringTransformerThatFailsTestIfApplied(self)) all_symbols = [ program_symbol, string_transformer_that_reports_failure_if_applied, const_true_int_matcher_symbol, ] # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( FullProgramAbsStx( program_symbol.abstract_syntax, transformation= string_transformer_that_reports_failure_if_applied. abstract_syntax), const_true_int_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services_access.new_for_cmd_exe( CommandExecutorThatJustReturnsConstant(1), ), ), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), ), ExecutionExpectation(main_result=asrt_pfh.is_pass()), ))
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)
expectation_type = from_is_negated(is_negated) return ExpectationTypeConfigForPfh(expectation_type) def pfh_expectation_type_config(expectation_type_of_test_case: ExpectationType) -> ExpectationTypeConfigForPfh: return ExpectationTypeConfigForPfh(expectation_type_of_test_case) def expectation_type_config__non_is_success(expectation_type_of_test_case: ExpectationType ) -> ExpectationTypeConfigForNoneIsSuccess: return ExpectationTypeConfigForNoneIsSuccess(expectation_type_of_test_case) _MAIN_RESULT_ASSERTION_FOR_PFH = { ExpectationType.POSITIVE: { PassOrFail.PASS: asrt_pfh.is_pass(), PassOrFail.FAIL: asrt_pfh.is_fail(), }, ExpectationType.NEGATIVE: { PassOrFail.PASS: asrt_pfh.is_fail(), PassOrFail.FAIL: asrt_pfh.is_pass(), }, } _ASSERT_IS_FAILURE_FOR_ERR_MSG = asrt.is_instance(str) _MAIN_RESULT_ASSERTION_ERR_MSG_FOR_FAIL = { ExpectationType.POSITIVE: { PassOrFail.PASS: None, PassOrFail.FAIL: _ASSERT_IS_FAILURE_FOR_ERR_MSG, },
def expectation_for_zero_exitcode(self) -> Expectation: return Expectation(main_result=pfh_assertions.is_pass())
def test_success_WHEN_actual_is_pass(self): # ARRANGE # assertion = sut.is_pass() actual = pfh.new_pfh_pass() # ACT # assertion.apply_without_message(self, actual)
def pfh_expectation_type_config( expectation_type_of_test_case: ExpectationType ) -> ExpectationTypeConfigForPfh: return ExpectationTypeConfigForPfh(expectation_type_of_test_case) def expectation_type_config__non_is_success( expectation_type_of_test_case: ExpectationType ) -> ExpectationTypeConfigForNoneIsSuccess: return ExpectationTypeConfigForNoneIsSuccess(expectation_type_of_test_case) _MAIN_RESULT_ASSERTION_FOR_PFH = { ExpectationType.POSITIVE: { PassOrFail.PASS: asrt_pfh.is_pass(), PassOrFail.FAIL: asrt_pfh.is_fail__with_arbitrary_message(), }, ExpectationType.NEGATIVE: { PassOrFail.PASS: asrt_pfh.is_fail__with_arbitrary_message(), PassOrFail.FAIL: asrt_pfh.is_pass(), }, } _ASSERT_IS_FAILURE_FOR_ERR_MSG = asrt.is_instance(str) _MAIN_RESULT_ASSERTION__FROM_PASS_OR_FAIL = { ExpectationType.POSITIVE: { PassOrFail.PASS: asrt_matching_result.matches_value(True), PassOrFail.FAIL: asrt_matching_result.matches_value(False), },