示例#1
0
    def test_no_symbol_references(self):
        # ARRANGE #
        option_cases = [
            option_case_for_no_option(asrt.anything_goes()),
            option_case_for_ignore_case(asrt.anything_goes()),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments('*'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars inside valid regex',
                       Arguments('before**after'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=validation.ValidationAssertions.pre_sds_fails__w_any_msg(),
                   ),
                   option_cases,
                   )
示例#2
0
    def runTest(self):
        # ARRANGE #

        files_matcher_name = 'the_files_matcher'
        checked_dir_location = RelOptionType.REL_ACT
        checked_dir = Dir.empty('checked-dir')

        matcher_argument = SymbolReferenceArgument(files_matcher_name).as_str

        tcds = TcdsArrangementPostAct(
            TcdsPopulatorForRelOptionType(checked_dir_location,
                                          DirContents([checked_dir])))

        source_cases = [
            NameAndValue(
                'All arguments on separate lines',
                Arguments(checked_dir.name, [
                    reserved_words.COLON, args.RECURSION_OPTION_STR,
                    matcher_argument
                ]),
            ),
            NameAndValue(
                'Empty lines between arguments',
                Arguments(checked_dir.name, [
                    '',
                    reserved_words.COLON,
                    '',
                    args.RECURSION_OPTION_STR,
                    '',
                    matcher_argument,
                ]),
            ),
        ]

        execution_cases = [
            NExArr(
                'matcher gives ' + str(matcher_result),
                ExecutionExpectation(
                    main_result=asrt_pfh.is_non_hard_error(matcher_result)),
                ArrangementPostAct2(
                    tcds,
                    symbols=FilesMatcherSymbolContext.of_primitive_constant(
                        files_matcher_name, matcher_result).symbol_table))
            for matcher_result in [False, True]
        ]
        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case=source_case.name):
                INSTRUCTION_CHECKER.check_multi__with_source_variants(
                    self,
                    SourceArrangement.new_w_arbitrary_fs_location(
                        source_case.value),
                    symbol_usages=asrt.matches_singleton_sequence(
                        is_reference_to_files_matcher__usage(
                            files_matcher_name)),
                    execution=execution_cases,
                )
示例#3
0
    def test_quoted_tokens(self):
        # ARRANGE #
        regex_str = '.* regex'

        matches_for_case_sensitive = [' regex', 'before regex after']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string=' REGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='regex')
            ),
        ]

        text_on_following_line = 'text on following line'

        source_cases = [
            SourceCase(
                'soft quotes',

                source=
                Arguments('{regex}'.format(
                    regex=surrounded_by_soft_quotes(regex_str),
                )),

                source_assertion=
                assert_token_stream(is_null=asrt.is_true),
            ),
            SourceCase(
                'hard quotes, and text on following line',

                source=
                Arguments('{regex}'.format(
                    regex=surrounded_by_hard_quotes(regex_str),
                ),
                    following_lines=[text_on_following_line]),

                source_assertion=
                assert_token_stream(
                    remaining_source=asrt.equals('\n' + text_on_following_line)),
            ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=ValidationAssertions.all_passes()
                   ),
                   option_cases,
                   )
示例#4
0
    def test_symbol_references(self):
        # ARRANGE #
        star_string_symbol = StringSymbolContext.of_constant('STAR_SYMBOL', '* ')

        regex_str = '.* regex'

        regex_arg_str = '.{star}regex'.format(
            star=symbol_reference_syntax_for_name(star_string_symbol.name),
        )

        matches_for_case_sensitive = [' regex', 'before regex after']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string=' REGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='regex')
            ),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments(regex_arg_str),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars at start of regex',
                       Arguments(surrounded_by_soft_quotes(regex_arg_str)),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]

        arrangement = Arrangement(
            symbols=star_string_symbol.symbol_table
        )

        expectation = ExpectationExceptPattern(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(star_string_symbol.name),
            ]),
            validation=ValidationAssertions.all_passes(),
        )

        # ACT & ASSERT #

        check_many(self,
                   arrangement,
                   source_cases,
                   expectation,
                   option_cases,
                   )
示例#5
0
def _source_variants_with_accepted_following_content_on_same_line(
        num_source_lines: int
) -> List[Tuple[Arguments, Assertion[ParseSource]]]:
    return [
        (Arguments('', []), asrt_source.is_at_end_of_line(num_source_lines)),
        (Arguments('', ['following line']),
         asrt_source.is_at_end_of_line(num_source_lines)),
        (Arguments('',
                   ['  ']), asrt_source.is_at_end_of_line(num_source_lines)),
    ]
    def runTest(self):
        def model(
            environment: FullResolvingEnvironment
        ) -> string_sources.StringSource:
            return string_sources.of_lines__w_check_for_validity(
                self,
                with_appended_new_lines([
                    str(environment.tcds.hds.case_dir),
                    str(environment.tcds.hds.act_dir),
                    str(environment.tcds.sds.act_dir),
                    str(environment.tcds.sds.user_tmp_dir),
                ]),
                environment.application_environment.tmp_files_space.
                sub_dir_space())

        expected = with_appended_new_lines([
            path.EXACTLY_DIR__REL_HDS_CASE,
            path.EXACTLY_DIR__REL_HDS_ACT,
            path.EXACTLY_DIR__REL_ACT,
            path.EXACTLY_DIR__REL_TMP,
        ])

        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
            self, Arguments(args.tcds_path_replacement()), model,
            arrangement_w_tcds(),
            expectation_of_successful_execution_2(
                symbol_references=asrt.is_empty_sequence,
                output_lines=expected,
                may_depend_on_external_resources=False,
                is_identity_transformer=False,
                adv=freeze_check.
                first_invoked_method_of_source_model__is_freeze,
            ))
示例#7
0
    def runTest(self):
        # ARRANGE #
        arguments = names.IDENTITY_TRANSFORMER_NAME

        model_content_lines = ['the model contents line 1']

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            Arguments(arguments),
            model_constructor.of_lines(self, model_content_lines),
            arrangement_w_tcds(),
            Expectation(
                ParseExpectation(
                    symbol_references=asrt.is_empty_sequence,
                ),
                ExecutionExpectation(
                    main_result=asrt_string_source.pre_post_freeze__matches_lines__identical(
                        asrt.equals(model_content_lines),
                        may_depend_on_external_resources=asrt.equals(False),
                    )
                ),
                prim_asrt__constant(is_identity_transformer(True)),
                adv=freeze_check.first_invoked_method_of_source_model__is_freeze,
            )
        )
示例#8
0
    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,
            )
        )
示例#9
0
    def test_SHOULD_not_be_identity_transformer(self):
        # ARRANGE #

        matcher = LineMatcherSymbolContext.of_primitive_constant(
            'line_matcher_symbol',
            False,
        )
        line_matcher_arg = lm_args.SymbolReference(matcher.name)

        arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
            self,
            Arguments(arguments),
            model_constructor.of_lines(self, []),
            arrangement_w_tcds(
                symbols=matcher.symbol_table
            ),
            expectation_of_successful_filter_execution(
                symbol_references=asrt.matches_singleton_sequence(
                    matcher.reference_assertion
                ),
                output_lines=[],
            )
        )
示例#10
0
    def runTest(self):
        # ARRANGE #
        for case in validation_cases.failing_validation_cases():
            line_matcher_symbol_context = case.value.symbol_context
            line_matcher_arg = lm_args.SymbolReference(line_matcher_symbol_context.name)

            arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))

            with self.subTest(case.name):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                    self,
                    Arguments(arguments),
                    model_constructor.of_lines(self, []),
                    arrangement_wo_tcds(
                        symbols=line_matcher_symbol_context.symbol_table
                    ),
                    Expectation(
                        ParseExpectation(
                            symbol_references=line_matcher_symbol_context.references_assertion
                        ),
                        ExecutionExpectation(
                            validation=case.value.expectation,
                        )
                    )
                )
    def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: FilesMatcherArgumentsConstructor,
        model_constructor: ModelConstructorFromRelOptConf,
        default_relativity: RelOptionType,
        non_default_relativity: RelOptionType,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        rel_opt_configs = [
            rel_opt_conf.default_conf_rel_any(default_relativity),
            rel_opt_conf.conf_rel_any(non_default_relativity),
        ]

        for rel_opt_config in rel_opt_configs:
            for expectation_type_of_test_case in ExpectationType:
                etc = expectation_type_config__non_is_success(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(etc)

                for source in equivalent_source_variants__for_expression_parser(
                        self.put, Arguments(instruction_arguments)):
                    self._check_(
                        source,
                        model_constructor(rel_opt_config),
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
示例#12
0
 def test_invalid_arguments_with_symbol_references(self):
     symbol_name = SymbolWithReferenceSyntax('symbol_name')
     operand_arg_with_symbol_ref_list = [
         ' {op} {sym}'.format(op=comparators.EQ.name, sym=symbol_name),
     ]
     invalid_symbol_values = [
         'not_a_number',
         '1.5',
         '72 87',
     ]
     for invalid_symbol_value in invalid_symbol_values:
         symbol = StringConstantSymbolContext(symbol_name.name,
                                              invalid_symbol_value)
         for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list:
             arguments = self._conf().arguments_constructor.apply(
                 operand_arg_with_symbol_ref)
             with self.subTest(argument=arguments,
                               invalid_symbol_value=invalid_symbol_value):
                 for source in equivalent_source_variants__for_expression_parser(
                         self, Arguments(arguments)):
                     self._check(
                         source,
                         Arrangement(symbols=symbol.symbol_table),
                         Expectation(
                             ParseExpectation(
                                 symbol_references=asrt.matches_sequence([
                                     symbol.
                                     reference_assertion__string__w_all_indirect_refs_are_strings
                                 ]), ),
                             ExecutionExpectation(
                                 validation=asrt_validation.
                                 ValidationAssertions.
                                 pre_sds_fails__w_any_msg(), ),
                         ),
                     )
示例#13
0
def _source_variants_with__for_expression_parser(
    num_expression_lines: int = 1
) -> List[Tuple[Arguments, Assertion[ParseSource]]]:
    space = '  '
    following_argument = 'argumentOfOthers'
    return [
        (Arguments('',
                   []), asrt_source.is_at_end_of_line(num_expression_lines)),
        (Arguments(space, ['following line']),
         asrt_source.assert_source(
             current_line_number=asrt.equals(num_expression_lines),
             remaining_part_of_current_line=asrt.equals(space[1:]))),
        (Arguments(space + following_argument, ['  ']),
         asrt_source.assert_source(
             current_line_number=asrt.equals(num_expression_lines),
             remaining_part_of_current_line=asrt.equals(space[1:] +
                                                        following_argument))),
    ]
示例#14
0
def syntax_for_replace_transformer__custom(arguments: Arguments,
                                           preserve_new_lines: bool = False
                                           ) -> Arguments:
    matcher = names.REPLACE_TRANSFORMER_NAME
    if preserve_new_lines:
        matcher = ' '.join(
            (matcher, option_syntax(names.PRESERVE_NEW_LINES_OPTION_NAME)))

    return Arguments(matcher).followed_by(arguments)
示例#15
0
 def test_failing_parse(self):
     cases = [
         NameAndValue(
             'no arguments',
             Arguments(''),
         ),
         NameAndValue(
             'invalid quoting of string',
             Arguments('"missing end quote'),
         ),
     ]
     parser = sut.ParserOfRegex()
     for source_case in cases:
         for option in OPTION_CASES:
             arguments = source_case.value.prepend_to_first_line(option)
             with self.subTest(case_name=source_case.name,
                               option=option):
                 source = remaining_source_lines(arguments.lines)
                 with self.assertRaises(SingleInstructionInvalidArgumentException):
                     parser.parse_from_token_parser(source)
示例#16
0
    def test_symbol_references_without_dir_dependencies(self):
        # ARRANGE #

        option_cases = [
            option_case_for_no_option(asrt.anything_goes()),
            option_case_for_ignore_case(asrt.anything_goes()),
        ]

        sym_ref_to_star = symbol_reference_syntax_for_name(self.STAR_STRING_SYMBOL.name)

        source_cases = [
            SourceCase('single invalid star',
                       Arguments(sym_ref_to_star),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars at start of regex',
                       Arguments(sym_ref_to_star +
                                 'after'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]

        arrangement = Arrangement(
            symbols=self.STAR_STRING_SYMBOL.symbol_table
        )

        expectation = ExpectationExceptPattern(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(self.STAR_STRING_SYMBOL.name),
            ]),
            validation=validation.ValidationAssertions.pre_sds_fails__w_any_msg(),
        )

        # ACT & ASSERT #

        check_many(self,
                   arrangement,
                   source_cases,
                   expectation,
                   option_cases,
                   )
示例#17
0
 def test_referenced_symbol_SHOULD_be_validated(self):
     symbol_name = 'fc_symbol'
     for symbol_ref_syntax in symbol_ref_syntax_cases(symbol_name):
         with self.subTest(symbol_ref_syntax=symbol_ref_syntax.name):
             CHECKER.check_multi__w_source_variants(
                 self,
                 arguments=Arguments(symbol_ref_syntax.value),
                 symbol_references=asrt.matches_singleton_sequence(
                     is_reference_to_files_condition(symbol_name)),
                 input_=None,
                 execution=failing_validation_cases__multi_exe(symbol_name),
             )
示例#18
0
 def test_every_line_SHOULD_be_filtered(self):
     matcher = LineMatcherSymbolContext.of_primitive(
         'line_matcher_symbol',
         sub_string_line_matcher('MATCH'),
     )
     line_matcher_arg = lm_args.SymbolReference(matcher.name)
     cases = [
         NEA('no lines',
             [],
             [],
             ),
         NEA('single line that matches',
             ['a MATCH'],
             ['a MATCH'],
             ),
         NEA('single line that matches, ended by new-line',
             ['a MATCH\n'],
             ['a MATCH\n'],
             ),
         NEA('single line that does not match',
             actual=['not a match'],
             expected=[],
             ),
         NEA('some lines matches',
             actual=with_appended_new_lines([
                 'first line is a MATCH',
                 'second line is not a match',
                 'third line MATCH:es',
                 'fourth line not',
             ]),
             expected=with_appended_new_lines([
                 'first line is a MATCH',
                 'third line MATCH:es',
             ]),
             ),
     ]
     for case in cases:
         with self.subTest(case_name=case.name):
             arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))
             integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                 self,
                 Arguments(arguments),
                 model_constructor.of_lines(self, case.actual),
                 arrangement_w_tcds(
                     symbols=matcher.symbol_table
                 ),
                 expectation_of_successful_filter_execution(
                     output_lines=case.expected,
                     symbol_references=asrt.matches_singleton_sequence(
                         references.is_reference_to_line_matcher(matcher.name)
                     ),
                 )
             )
示例#19
0
 def test_no_lines(self):
     integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
         self, Arguments(self.config.arguments),
         model_constructor.of_lines(self, []), arrangement_w_tcds(),
         expectation_of_successful_execution_2(
             symbol_references=asrt.is_empty_sequence,
             output_lines=[],
             may_depend_on_external_resources=False,
             is_identity_transformer=False,
             adv=freeze_check.
             first_invoked_method_of_source_model__is_freeze,
         ))
示例#20
0
    def runTest(self):
        # ARRANGE #
        symbol_1 = NameAndValue('symbol_1_name', 'added by 1st transformer')
        symbol_2 = NameAndValue('symbol_2_name', 'added by 2nd transformer')
        symbol_3 = NameAndValue('symbol_3_name', 'added by 3rd transformer')

        cases = [
            NameAndValue('2 transformers', [
                symbol_1,
                symbol_2,
            ]),
            NameAndValue('3 transformers', [
                symbol_1,
                symbol_2,
                symbol_3,
            ]),
        ]
        for case in cases:
            sequenced_transformer_symbols = case.value

            arguments = st_args.syntax_for_sequence_of_transformers(
                [symbol.name for symbol in sequenced_transformer_symbols])

            initial_line = 'initial line\n'
            initial_model_lines = [initial_line]

            expected_output_lines = [initial_line] + [
                symbol.value + '\n' for symbol in sequenced_transformer_symbols
            ]

            symbol_contexts = [
                StringTransformerSymbolContext.of_primitive(
                    symbol.name, string_transformers.add_line(symbol.value))
                for symbol in sequenced_transformer_symbols
            ]
            # ACT & ASSERT #

            with self.subTest(case.name):
                integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
                    self, Arguments(arguments),
                    model_constructor.of_lines(self, initial_model_lines),
                    arrangement_w_tcds(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            symbol_contexts)),
                    expectation_of_successful_execution_2(
                        output_lines=expected_output_lines,
                        symbol_references=SymbolContext.
                        references_assertion_of_contexts(symbol_contexts),
                        may_depend_on_external_resources=False,
                        is_identity_transformer=False,
                    ))
示例#21
0
def _check(
    put: unittest.TestCase,
    input_lines: List[str],
    expected_lines: List[str],
):
    integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
        put, Arguments(args.strip_space()),
        model_constructor.of_lines(put, input_lines), arrangement_w_tcds(),
        expectation_of_successful_execution_2(
            symbol_references=asrt.is_empty_sequence,
            output_lines=expected_lines,
            may_depend_on_external_resources=False,
            is_identity_transformer=False,
            adv=freeze_check.first_invoked_method_of_source_model__is_freeze,
        ))
示例#22
0
    def runTest(self):
        successful_transformer = StringTransformerSymbolContext.of_identity(
            'successful_transformer')
        for case in validation_cases.failing_validation_cases(
                'failing_transformer'):
            failing_symbol_context = case.value.symbol_context

            symbols = SymbolContext.symbol_table_of_contexts([
                failing_symbol_context,
                successful_transformer,
            ])

            order_cases = [
                NameAndValue(
                    '1st transformer fails',
                    [failing_symbol_context.name, successful_transformer.name
                     ]),
                NameAndValue(
                    '2nd transformer fails',
                    [successful_transformer.name, failing_symbol_context.name
                     ]),
            ]
            for order_case in order_cases:
                arguments = st_args.syntax_for_sequence_of_transformers(
                    order_case.value)
                expected_symbol_references = asrt.matches_sequence([
                    is_reference_to_string_transformer(symbol_name)
                    for symbol_name in order_case.value
                ])

                with self.subTest(validation_case=case.name,
                                  order_case=order_case.name):
                    integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
                        self, Arguments(arguments),
                        model_constructor.of_lines(self, []),
                        arrangement_w_tcds(symbols=symbols),
                        Expectation(
                            ParseExpectation(
                                symbol_references=expected_symbol_references),
                            ExecutionExpectation(
                                validation=case.value.expectation, ),
                            prim_asrt__constant(
                                is_identity_transformer(False)),
                        ))
示例#23
0
    def check(self,
              cases_with_same_number_of_operands: List[Case],
              ):
        self._assert_cases_list_is_valid(cases_with_same_number_of_operands)

        operand_symbol_names = self._operand_symbol_names(cases_with_same_number_of_operands)

        source = Arguments(self._operator_in_source().join(operand_symbol_names))

        execution_cases = self._execution_cases(
            operand_symbol_names,
            cases_with_same_number_of_operands,
        )

        self.conf.checker_for_parser_of_full_expr().check_multi__w_source_variants(
            self.put,
            source,
            self.helper.is_sym_refs_to(operand_symbol_names),
            self.conf.arbitrary_model,
            execution_cases,
        )
示例#24
0
 def test_every_line_SHOULD_be_transformed(self):
     # ARRANGE #
     trans_fun = self.config.str_transformer
     input_lines = [
         'I object!',
         'Object Oriented',
         'Unidentified FLYING Object',
     ]
     expected_lines = [trans_fun(line) for line in input_lines]
     # ACT & ASSERT #
     integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
         self, Arguments(self.config.arguments),
         model_constructor.of_lines_wo_nl(self, input_lines),
         arrangement_w_tcds(),
         expectation_of_successful_execution_2(
             symbol_references=asrt.is_empty_sequence,
             output_lines=with_appended_new_lines(expected_lines),
             may_depend_on_external_resources=False,
             is_identity_transformer=False,
             adv=freeze_check.
             first_invoked_method_of_source_model__is_freeze,
         ))
示例#25
0
 def test_invalid_arguments_without_symbol_references(self):
     test_cases = [
         ' {op} a'.format(op=comparators.EQ.name),
         '{op} 1.5'.format(op=comparators.GT.name),
     ]
     for condition_str in test_cases:
         with self.subTest(msg=condition_str):
             instr_arg = self._conf().arguments_constructor.apply(
                 condition_str)
             for source in equivalent_source_variants__for_expression_parser(
                     self, Arguments(instr_arg)):
                 self._check(
                     source,
                     Arrangement(),
                     Expectation(
                         ParseExpectation(
                             symbol_references=asrt.is_empty_sequence, ),
                         ExecutionExpectation(
                             validation=asrt_validation.ValidationAssertions
                             .pre_sds_fails__w_any_msg(), ),
                     ),
                 )
示例#26
0
    def test_referenced_symbol_SHOULD_be_validated(self):
        # ARRANGE #

        conf = self.configuration
        helper = self._asrt_helper

        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        # ACT & ASSERT #

        for symbol_ref_syntax in symbol_ref_syntax_cases(symbol_name):
            with self.subTest(symbol_ref_syntax=symbol_ref_syntax.name):
                conf.checker_for_parser_of_full_expr(
                ).check_multi__w_source_variants(
                    self,
                    arguments=Arguments(symbol_ref_syntax.value),
                    symbol_references=asrt.matches_singleton_sequence(
                        helper.is_sym_ref_to(symbol_name)),
                    input_=conf.arbitrary_model,
                    execution=helper.failing_validation_cases(symbol_name),
                )
示例#27
0
    def test_unquoted_tokens(self):
        # ARRANGE #
        regex_str = 'a.*regex'

        matches_for_case_sensitive = ['aBCregex', 'aBCregex and more']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string='AbcREGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='Abc')
            ),
        ]

        text_on_following_line = 'text on following line'

        def _arg(format_string: str) -> str:
            return format_string.format(
                regex=regex_str)

        source_cases = [
            SourceCase(
                'REG-EX is only source',
                source=
                Arguments(_arg('{regex}')),
                source_assertion=
                assert_token_stream(is_null=asrt.is_true),
            ),
            SourceCase(
                'REG-EX is followed by a token',
                source=
                Arguments(_arg('{regex} following_token')),
                source_assertion=
                assert_token_stream(
                    is_null=asrt.is_false,
                    remaining_part_of_current_line=asrt.equals('following_token')),
            ),
            SourceCase(
                'REG-EX is only element on current line, but followed by more lines',
                source=
                Arguments(_arg('{regex}'),
                          following_lines=[text_on_following_line]),
                source_assertion=
                assert_token_stream(
                    is_null=asrt.is_false,
                    remaining_part_of_current_line=asrt.equals(''),
                    remaining_source=asrt.equals('\n' + text_on_following_line)),
            ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=ValidationAssertions.all_passes()
                   ),
                   option_cases,
                   )
示例#28
0
 def as_arguments(self) -> Arguments:
     return Arguments(str(self))
示例#29
0
    def test_other_scenarios(self):
        cases = [
            NameAndValue(
                'trailing new lines should be removed from line matcher model, but not from transformer output',
                (line_matcher_from_predicates(line_contents_predicate=lambda x: x == 'X'),
                 ['X\n'],
                 ['X\n'])
            ),
            NameAndValue(
                'line numbers should be paired with lines in order of iterator (1)',
                (is_identical_to(1, 'i'),
                 with_appended_new_lines([
                     'i',
                     'ii',
                 ]),
                 with_appended_new_lines(['i'])
                 )
            ),
            NameAndValue(
                'line numbers should be paired with lines in order of iterator (2)',
                (is_identical_to(2, 'ii'),
                 with_appended_new_lines([
                     'i',
                     'ii',
                 ]),
                 with_appended_new_lines(['ii'])
                 )
            ),
            NameAndValue(
                'line numbers should be propagated to line matcher',
                (line_matcher_from_predicates(line_num_predicate=lambda x: x in {1, 3}),
                 with_appended_new_lines([
                     'i',
                     'ii',
                     'iii',
                     'iv',
                 ]),
                 with_appended_new_lines([
                     'i',
                     'iii',
                 ])
                 )
            ),
        ]
        line_matcher_name = 'the_line_matcher_symbol_name'
        line_matcher_arg = lm_args.SymbolReference(line_matcher_name)
        arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))

        for case in cases:
            matcher, input_lines, expected_output_lines = case.value
            with self.subTest(case_name=case.name):
                # ACT & ASSERT #

                integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                    self,
                    Arguments(arguments),
                    model_constructor.of_lines(self, input_lines),
                    arrangement_w_tcds(
                        symbols=LineMatcherSymbolContext.of_primitive(
                            line_matcher_name,
                            matcher,
                        ).symbol_table,
                    ),
                    expectation_of_successful_filter_execution(
                        output_lines=expected_output_lines,
                        symbol_references=asrt.matches_singleton_sequence(
                            references.is_reference_to_line_matcher(line_matcher_name)
                        )
                    )
                )
示例#30
0
def empty_arguments() -> Arguments:
    return Arguments('')