Beispiel #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,
                   )
Beispiel #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,
                )
Beispiel #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,
                   )
Beispiel #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,
                   )
Beispiel #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)),
    ]
Beispiel #6
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,
                        )
                    )
                )
Beispiel #7
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,
            )
        )
Beispiel #8
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=[],
            )
        )
    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)
    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,
            ))
Beispiel #11
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,
            )
        )
Beispiel #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(), ),
                         ),
                     )
Beispiel #13
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)
Beispiel #14
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))),
    ]
Beispiel #15
0
def equivalent_source_variants_for_consume_until_end_of_last_line(
        arguments: Arguments) -> List[Tuple[SourceCase]]:
    return [
        SourceCase(
            arguments.followed_by_lines(extra_lines).as_remaining_source,
            assertion,
        ) for extra_lines, assertion in
        _equivalent_source_variants_for_consume_until_end_of_last_line(
            arguments.num_lines)
    ]
Beispiel #16
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)
Beispiel #17
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,
                   )
Beispiel #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)
                     ),
                 )
             )
Beispiel #19
0
def equivalent_source_variants__with_source_check__for_full_line_expression_parser(
    original_arguments: Arguments,
) -> List[NEA[Assertion[ParseSource], ParseSource]]:
    num_lines = original_arguments.num_lines
    return [
        NEA(name='following_lines={}'.format(repr(following_lines), ),
            expected=source_assertion,
            actual=original_arguments.followed_by_lines(
                following_lines).as_remaining_source)
        for following_lines, source_assertion in
        _source_variants_with__for_full_line_expression_parser(num_lines)
    ]
Beispiel #20
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),
             )
Beispiel #21
0
def equivalent_source_variants_for_consume_until_end_of_last_line2(
        arguments: Arguments
) -> List[NIE[ParseSource, Assertion[ParseSource]]]:
    return [
        NIE(
            repr(extra_lines),
            assertion,
            arguments.followed_by_lines(extra_lines).as_remaining_source,
        ) for extra_lines, assertion in
        _equivalent_source_variants_for_consume_until_end_of_last_line(
            arguments.num_lines)
    ]
Beispiel #22
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,
         ))
Beispiel #23
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,
                    ))
Beispiel #24
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,
        ))
Beispiel #25
0
def equivalent_source_variants__with_source_check__multi_line(
    put: unittest.TestCase,
    instruction_argument: Arguments,
) -> Iterator[ParseSource]:
    """
    Checks that the first line of the source has been consumed.

    Assumes that the body of the loop parses using the given source.
    """
    for following_lines, source_assertion in _source_variant_test_cases__multi_line(
            instruction_argument.num_lines):
        with put.subTest(following_lines=repr(following_lines)):
            source = instruction_argument.followed_by_lines(
                following_lines).as_remaining_source
            yield source
            source_assertion.apply_with_message(put, source,
                                                'source after parse')
Beispiel #26
0
def equivalent_source_variants__for_expression_parser_2(
    original_arguments: Arguments,
) -> List[NEA[Assertion[ParseSource], ParseSource]]:
    num_lines = original_arguments.num_lines
    return [
        NEA(name='additional_arguments_on_same_line={}, additional_lines={}'.
            format(
                repr(following_arguments.first_line),
                repr(following_arguments.following_lines),
            ),
            expected=source_assertion,
            actual=original_arguments.last_line_followed_by(
                following_arguments,
                first_line_separator='').as_remaining_source)
        for following_arguments, source_assertion in
        _source_variants_with__for_expression_parser(num_lines)
    ]
Beispiel #27
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)),
                        ))
Beispiel #28
0
def equivalent_source_variants__for_expression_parser(
    put: unittest.TestCase,
    original_arguments: Arguments,
) -> Iterator[ParseSource]:
    """
    Assumes that the body of the loop parses using the given source.
    """
    for following_arguments, source_assertion in _source_variants_with__for_expression_parser(
            original_arguments.num_lines):
        with put.subTest(additional_arguments_on_same_line=repr(
                following_arguments.first_line),
                         additional_lines=repr(
                             following_arguments.following_lines)):
            source = original_arguments.last_line_followed_by(
                following_arguments,
                first_line_separator='').as_remaining_source
            yield source
            source_assertion.apply_with_message(put, source,
                                                'source after parse')
Beispiel #29
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,
        )
Beispiel #30
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,
         ))