def _check( self, arguments: ArgumentElements, expected_result: bool, all_symbols: Sequence[NameAndValue[MatcherWTrace[MODEL]]], expected_trace: tree.Node[bool], ): conf = self.configuration helper = self._asrt_helper conf.checker_for_parser_of_full_expr().check__w_source_variants( self, arguments.as_arguments, conf.arbitrary_model, Arrangement(symbols=SymbolContext.symbol_table_of_contexts([ conf.mk_logic_type_context_of_primitive(sym.name, sym.value) for sym in all_symbols ]), ), Expectation( ParseExpectation(symbol_references=helper.is_sym_refs_to( [sym.name for sym in all_symbols]), ), ExecutionExpectation(main_result=asrt_matching_result.matches( value=asrt.equals(expected_result), trace=trace_equals(expected_trace)))), )
def test_success_WHEN_actual_is_valid(self): assertion = sut.matches() for result_case in False, True: renderer = NodeRendererForTest(Node('header', result_case, [], [])) actual = MatchingResult(result_case, renderer) with self.subTest(case=result_case): assertion.apply_without_message(self, actual)
def test_succeed(self): actual_value = False trace = NodeRendererForTest(_trace_for(actual_value)) actual_result = MatchingResult(actual_value, trace) assertion = sut.matches(value=asrt.equals(actual_value)) assertion.apply_without_message(self, actual_result)
def test_fail(self): actual_value = False trace = NodeRendererForTest(_trace_for(actual_value)) actual_result = MatchingResult(actual_value, trace) assertion = sut.matches(value=asrt.equals(not actual_value)) assert_that_assertion_fails(assertion, actual_result)
def test_succeed(self): actual_rendered_node = _trace_for(False) actual_result = MatchingResult( actual_rendered_node.data, NodeRendererForTest(actual_rendered_node)) renderer_assertion = asrt_trace_rendering.matches_node_renderer( rendered_node=asrt_d_tree.matches_node( header=asrt.equals(actual_rendered_node.header))) assertion = sut.matches(trace=renderer_assertion) assertion.apply_without_message(self, actual_result)
def test_fail(self): actual_rendered_node = Node('actual header', False, [], []) actual_result = MatchingResult( actual_rendered_node.data, NodeRendererForTest(actual_rendered_node)) renderer_assertion = asrt_trace_rendering.matches_node_renderer( rendered_node=asrt_d_tree.matches_node( header=asrt.equals('expected header'))) assertion = sut.matches(trace=renderer_assertion) assert_that_assertion_fails(assertion, actual_result)
def test_application(self): conf = self.configuration for value in [False, True]: conf.checker_for_parser_of_full_expr().check__w_source_variants( self, arguments=matcher_argument.Constant(value).as_arguments, input_=conf.arbitrary_model, arrangement=arrangement_wo_tcds(), expectation=Expectation(execution=ExecutionExpectation( main_result=asrt_matching_result.matches( asrt.equals(value), trace=_utils.trace_equals( tree.Node.leaf(logic.CONSTANT_MATCHER, value, ( tree.StringDetail(logic.BOOLEANS[value]), )))))))
def execution_case_for(result: bool) -> NExArr: referenced_matcher = matchers.ConstantMatcherWithCustomTrace(mk_trace, result) return NExArr( 'matcher that gives ' + str(result), PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches( value=asrt.equals(result), trace=trace_equals(mk_trace(result)) ) ), Arrangement( symbols=helper.logic_type_symbol_context_from_primitive(symbol_name, referenced_matcher).symbol_table ) )
def execution_case_for( operand_result: bool ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL], MatchingResult], Arrangement]: operand_matcher = helper.logic_type_symbol_context_from_primitive( symbol_name, matchers.ConstantMatcherWithCustomTrace( mk_operand_trace, operand_result)) trace = tree.Node(logic.NOT_OPERATOR_NAME, not operand_result, (), [mk_operand_trace(operand_result)]) return NExArr( 'operand that gives ' + str(operand_result), PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches( value=asrt.equals(not operand_result), trace=trace_equals(trace))), Arrangement(symbols=operand_matcher.symbol_table))
def test_fail_WHEN_invalid_type(self): # ARRANGE # assertion = sut.matches() cases = [ NameAndValue('invalid type of object', 'not a' + str(MatchingResult)), NameAndValue( 'invalid type of result', MatchingResult('not a bool', NodeRendererForTest(_ARBITRARY_VALID_NODE))), NameAndValue( 'invalid type of renderer', MatchingResult(False, 'not a ' + str(sut.NodeRenderer))), NameAndValue('result of rendering is object of invalid type', NodeRendererForTest('not a Node')), ] for case in cases: with self.subTest(case.name): # ACT & ASSERT # assert_that_assertion_fails(assertion, case.value)
def runTest(self): # ARRANGE # def get_trace(data: T) -> tree.Node[T]: return tree.Node.empty('name of string matcher', data) for string_matcher_result in [False, True]: string_matcher = StringMatcherSymbolContext.of_primitive( 'STRING_MATCHER', ConstantMatcherWithCustomTrace(get_trace, string_matcher_result), ) expected_trace = tree.Node( MATCHER_NAME, string_matcher_result, (), [get_trace(string_matcher_result)], ) # ACT & ASSERT # with self.subTest(string_matcher_result=string_matcher_result): integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants( self, arguments=lm_args.Contents( sm_args2.SymbolReferenceWReferenceSyntax( string_matcher.name), ).as_arguments, input_=models.ARBITRARY_MODEL, arrangement=arrangement_wo_tcds( symbols=string_matcher.symbol_table, ), expectation=Expectation( ParseExpectation(symbol_references=string_matcher. references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches( asrt.equals(string_matcher_result), trace=asrt_trace_rendering. matches_node_renderer( asrt_d_tree.equals_node(expected_trace)), ))), )
] def _execution_case(self, operand_symbol_names: List[str], case: Case, ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL], MatchingResult], Arrangement]: operands = [ NameAndValue(sym_and_behaviour[0], sym_and_behaviour[1]) for sym_and_behaviour in zip(operand_symbol_names, case.operands) ] return NExArr( case.name, PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches( value=asrt.equals(case.expected_result), trace=trace_equals(self._expected_trace_for(case.expected_result, operands)) ) ), Arrangement( symbols=self._symbols_for(operands) ), ) def _expected_trace_for(self, expected_result: bool, operands: List[NameAndValue[MatcherBehaviour]], ) -> tree.Node[bool]: operand_nodes = filter(lambda x: x is not None, [ operand.value.accept(_ApplicationTraceConstructor(operand.name))
def new_execution_checker( self ) -> WithNodeDescriptionExecutionPropertiesChecker[MatcherWTrace, MatchingResult]: return WithNodeDescriptionExecutionPropertiesChecker( MatcherDdv, MatcherWTrace, asrt_matching_result.matches())
model=model_info.description_of_model): integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants( self, Arguments.of_preformatted(case.source), input_=integration_check.constant(model_info.model), arrangement=arrangement_wo_tcds( symbols=case.symbols, ), expectation=Expectation( ParseExpectation( symbol_references=case.references, ), ExecutionExpectation( main_result=asrt_matching_result.matches( value=asrt.equals(expected_result.value), trace=asrt_trace_rendering.matches_node_renderer( asrt_d_tree.equals_node(expected_result.trace.render()), ) ) ), prim_asrt__constant( asrt_w_interval.is_with_interval( case.interval.pos, case.interval.neg, ) ), ) ) def test_failing_validation(self): # ARRANGE # symbol_not_an_int = StringSymbolContext.of_constant('SYMBOL_NOT_AN_INT', 'notAnInt')