def test(self): # ARRANGE # reg_ex_pattern = 'const_pattern' arguments = st_args.syntax_for_filter_transformer(str( lm_args.Contents(sm_args.Matches(reg_ex_pattern))) ) lines = [ reg_ex_pattern + '\n', 'non matching line', ] expected_lines = [ reg_ex_pattern + '\n', ] # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants( self, Arguments(arguments), model_constructor.of_lines(self, lines), arrangement_w_tcds(), expectation_of_successful_filter_execution( output_lines=expected_lines, symbol_references=asrt.is_empty_sequence, ) )
def runTest(self): # ARRANGE # for result in [False, True]: string_matcher = StringMatcherSymbolContextOfPrimitiveConstant( 'STRING_MATCHER', result, ) # ACT & ASSERT # with self.subTest(string_matcher_result=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_value__w_header( asrt.equals(string_matcher.result_value), header=TRACE_HEADER_EXPECTATION, ))), )
def runTest(self): string_matcher = StringMatcherSymbolContextOfPrimitiveConstant( 'STRING_MATCHER', True, ) after_bin_op = 'after bin op' integration_check.CHECKER__PARSE_SIMPLE.check( self, source=lm_args.Contents( sm_args2.conjunction([ sm_args2.SymbolReference(string_matcher.name), sm_args2.Custom(after_bin_op), ]), ).as_remaining_source, input_=models.ARBITRARY_MODEL, arrangement=arrangement_wo_tcds( symbols=string_matcher.symbol_table, ), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=logic.AND_OPERATOR_NAME + ' ' + after_bin_op), symbol_references=string_matcher.references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value__w_header( asrt.equals(string_matcher.result_value), header=TRACE_HEADER_EXPECTATION, ))), )
def test_disjunction(self): # ARRANGE # model = [ '1st\n', '2nd\n', '3rd\n', ] arguments = tr.filter_lm__within_parens( arg_rend.disjunction([ lm_arg.Contents(sm_args.Equals(FileOrString.of_string('2nd'))), lm_arg.Contents(sm_args.Equals(FileOrString.of_string('3rd'))), ])) # ACT & ASSET # tr.check( self, Case(model, arguments, [], [model[1], model[2]], len(model)), )
def test_non_complex(self): # ARRANGE # model = [ '1st\n', '2nd\n', '3rd\n', ] arguments = tr.filter_lm( lm_arg.Contents(sm_args.Equals(FileOrString.of_string('2nd')))) # ACT & ASSET # tr.check( self, Case(model, arguments, [], [model[1]], len(model)), )
def test_negation(self): # ARRANGE # model = [ '1st\n', '2nd\n', '3rd\n', ] arguments = tr.filter_lm( arg_rend.negation( lm_arg.Contents(sm_args.Equals( FileOrString.of_string('2nd'))))) # ACT & ASSET # tr.check( self, Case(model, arguments, [], [model[0], model[2]], len(model)), )
def runTest(self): for case in validation_cases.failing_validation_cases(): symbol_context = case.value.symbol_context with self.subTest(case.name): integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants( self, arguments=lm_args.Contents( sm_args2.SymbolReferenceWReferenceSyntax( symbol_context.name)).as_arguments, input_=models.ARBITRARY_MODEL, arrangement=arrangement_w_tcds( symbols=symbol_context.symbol_table, ), expectation=Expectation( ParseExpectation(symbol_references=symbol_context. references_assertion, ), ExecutionExpectation( validation=case.value.expectation, ), ), )
def test_negation_of_disjunction(self): # ARRANGE # model = [ '1st\n', '2nd\n', '3rd\n', ] neg_open_lower_limit = IntSymbol('lower_limit') arguments = tr.filter_lm( arg_rend.negation( arg_rend.within_paren( arg_rend.disjunction([ lm_arg.Contents( sm_args.Equals(FileOrString.of_string('2nd'))), lm_arg.LineNum2( im_args.comparison( comparators.GT, SymbolReferenceWReferenceSyntax( neg_open_lower_limit.name))), ])))) model_and_args = ModelAndArguments(model, arguments) # ACT & ASSET # tr.check_cases__named( self, [ model_and_args.case__n( [neg_open_lower_limit.value(1)], max_num_lines_from_iter=3, expected_output_lines=[1], ), model_and_args.case__n( [neg_open_lower_limit.value(2)], max_num_lines_from_iter=3, expected_output_lines=[1], ), model_and_args.case__n( [neg_open_lower_limit.value(3)], max_num_lines_from_iter=3, expected_output_lines=[1, 3], ), ], )
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 test_disjunction(self): # ARRANGE # model = [ '1st\n', '2nd\n', '3rd\n', ] num_model_elements = len(model) upper_limit = IntSymbol('upper_limit') arguments = tr.filter_lm__within_parens( arg_rend.disjunction([ lm_arg.Contents(sm_args.Equals(FileOrString.of_string('2nd'))), lm_arg.LineNum2( im_args.comparison( comparators.LTE, SymbolReferenceWReferenceSyntax(upper_limit.name))), ])) model_and_args = ModelAndArguments(model, arguments) # ACT & ASSET # tr.check_cases__named( self, [ model_and_args.case__n( [upper_limit.value(-3)], max_num_lines_from_iter=num_model_elements, expected_output_lines=[2], ), model_and_args.case__n( [upper_limit.value(2)], max_num_lines_from_iter=num_model_elements, expected_output_lines=_from_to(1, 2), ), model_and_args.case__n( [upper_limit.value(10)], max_num_lines_from_iter=num_model_elements, expected_output_lines=_from_to(1, 3), ), ], )
def runTest(self): # ARRANGE # line_contents = 'the line contents' def get_string_matcher_model_as_single_string( model: StringSource) -> str: return model.contents().as_str matching_result = True string_matcher = StringMatcherSymbolContext.of_primitive( 'STRING_MATCHER', matcher_w_init_action.matcher_that_applies_assertion( self, assertion=asrt.equals(line_contents), get_actual=get_string_matcher_model_as_single_string, message_builder=asrt.MessageBuilder.new( 'string-matcher-model'), result=matching_result, ), ) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants( self, arguments=lm_args.Contents( sm_args2.SymbolReferenceWReferenceSyntax( string_matcher.name), ).as_arguments, input_=models.constant((1, line_contents)), 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_value__w_header( asrt.equals(matching_result), header=asrt.equals(MATCHER_NAME), ))), )
def runTest(self): self._check_cases([ NArrEx( '! >= (within line-num-range)', arg_rend.negation( args.LineNum2(im_args.comparison2(comparators.GTE, 4))), asrt_interval.matches_upper_limit(4 - 1)), NArrEx( '! >= (outside line-num-range)', arg_rend.negation( args.LineNum2( im_args.comparison2(comparators.LTE, FIRST_LINE_NUMBER - 1))), asrt_interval.matches_unlimited()), NArrEx('negation contents', arg_rend.negation(args.Contents(sm_args.Empty())), asrt_interval.matches_unlimited()), NArrEx('negation constant False', arg_rend.negation(arg_rend.constant(False)), asrt_interval.matches_unlimited()), NArrEx('negation constant True', arg_rend.negation(arg_rend.constant(True)), asrt_interval.matches_empty()), NArrEx( '> && <= (within line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), ])), asrt_interval.matches_finite(7 + 1, 12)), NArrEx( '> && contents (within line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 7)), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_lower_limit(7 + 1)), NArrEx( 'contents && contents', arg_rend.within_paren( arg_rend.conjunction([ args.Contents(sm_args.Empty()), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( '> && <= (partly outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), ])), asrt_interval.matches_upper_limit(12)), NArrEx( '> && <= (completely outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, -2)), ])), asrt_interval.matches_empty()), NArrEx( '> && <= && <= (outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), args.LineNum2(im_args.comparison2(comparators.LTE, 15)), ])), asrt_interval.matches_upper_limit(12)), NArrEx( '== || <= (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.EQ, 17)), args.LineNum2(im_args.comparison2(comparators.LTE, 10)), ])), asrt_interval.matches_upper_limit(17)), NArrEx( '== || contents (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.EQ, 17)), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( 'contents || contents', arg_rend.within_paren( arg_rend.disjunction([ args.Contents(sm_args.Empty()), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( '> || == (outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 5)), args.LineNum2(im_args.comparison2(comparators.EQ, -12)), ])), asrt_interval.matches_lower_limit(5 + 1)), NArrEx( '< || <= (completely outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LT, -5)), args.LineNum2(im_args.comparison2(comparators.LTE, -3)), ])), asrt_interval.matches_empty()), NArrEx( '<= || > || == (outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LTE, 0)), args.LineNum2(im_args.comparison2(comparators.GT, 5)), args.LineNum2(im_args.comparison2(comparators.EQ, 3)), ])), asrt_interval.matches_lower_limit(3)), NArrEx( '<= || contents || == (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LTE, 12)), args.Contents(sm_args.Empty()), args.LineNum2(im_args.comparison2(comparators.EQ, 15)), ])), asrt_interval.matches_unlimited()), ])
def make_arguments(matcher_argument: str) -> ArgumentElementsRenderer: return lm_args.Contents( argument_renderer.Singleton(matcher_argument))
def syntax_for_regex_matcher(regex_token_str: str) -> str: return lm_args.Contents(sm_args.Matches(regex_token_str)).as_str