Пример #1
0
    def test(self):
        # ARRANGE #
        detail = sut.StringDetail('a detail')
        child = sut.Node('child header', False, (), ())
        root_header = 'root header'
        root_data = True
        root = sut.Node(root_header, root_data, (detail,), (child,))

        # ACT & ASSERT #

        self.assertEqual(root_header,
                         root.header,
                         'root header')

        self.assertEqual(root_data,
                         root.data,
                         'root data')

        expected_root_details = asrt.matches_singleton_sequence(
            asrt.is_(detail)
        )

        expected_root_details.apply_with_message(self,
                                                 root.details,
                                                 'root details')

        expected_root_children = asrt.matches_singleton_sequence(
            asrt.is_(child)
        )

        expected_root_children.apply_with_message(self,
                                                  root.children,
                                                  'root children')
 def expected_program(
         env: AssertionResolvingEnvironment) -> Assertion[Program]:
     return asrt_pgm_val.matches_program(
         asrt_command.matches_command(
             driver=pgm_and_args_case.expected_command_driver(env),
             arguments=asrt.equals(arguments),
         ),
         stdin=asrt.matches_singleton_sequence(
             asrt_str_src.matches__str(
                 asrt.equals(str_src_contents), )),
         transformer=asrt.matches_singleton_sequence(
             asrt.is_(transformer_symbol.primitive)),
     )
Пример #3
0
    def test_symbol_reference_on_command_line_SHOULD_be_reported_and_used_in_execution(
            self):
        symbol = StringConstantSymbolContext('symbol_name', 'symbol value')

        string_to_print_template = 'constant and {symbol}'
        expected_output_template = string_to_print_template + '\n'

        shell_source_line = shell_commands.command_that_prints_to_stdout(
            string_to_print_template.format(
                symbol=symbol.name__sym_ref_syntax))
        act_phase_instructions = [
            instr([shell_command_source_line_for(shell_source_line)])
        ]

        check_execution(
            self,
            sut.actor(),
            act_phase_instructions,
            arrangement_w_tcds(symbol_table=symbol.symbol_table),
            Expectation(symbol_usages=asrt.matches_singleton_sequence(
                symbol.reference_assertion__w_str_rendering),
                        post_sds=PostSdsExpectation.constant(
                            sub_process_result_from_execute=pr.stdout(
                                asrt.equals(
                                    expected_output_template.format(
                                        symbol=symbol.str_value))))),
        )
Пример #4
0
    def runTest(self):
        # ARRANGE #

        source_file = fs.File.empty('source-file.src')

        python_interpreter_symbol = PathSymbolContext.of_sdv(
            'PYTHON_INTERPRETER_SYMBOL',
            path_sdvs.constant(
                path_ddvs.absolute_path(pathlib.Path(sys.executable))))

        interpreter_with_symbol_reference = command_sdvs.for_executable_file(
            python_interpreter_symbol.reference_sdv__path_or_string(
                relativity_configurations.INTERPRETER_FILE.relativity))

        arrangement = arrangement_w_tcds(
            symbol_table=python_interpreter_symbol.symbol_table,
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([source_file])))
        expectation = Expectation(
            symbol_usages=asrt.matches_singleton_sequence(
                python_interpreter_symbol.reference_assertion__path_or_string),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=asrt_pr.sub_process_result(
                    exitcode=asrt.equals(0),
                    stdout=asrt.equals(''),
                    stderr=asrt.equals(''),
                )),
        )
        # ACT & ASSERT #
        check_execution(self, sut.actor(interpreter_with_symbol_reference),
                        [instr([])], arrangement, expectation)
Пример #5
0
    def runTest(self):
        # ARRANGE #
        exit_code_from_program = 0
        exe_file_in_path = fs.python_executable_file(
            'the-program',
            lines_content(py_program.exit_with_code(exit_code_from_program)),
        )
        program_symbol = StringConstantSymbolContext(
            'PROGRAM_NAME_SYMBOL',
            exe_file_in_path.name,
        )
        program_line = args.system_program_command_line(
            program_symbol.name__sym_ref_syntax).as_str

        with tmp_dir_in_path_with_files(DirContents([exe_file_in_path
                                                     ])) as environ:
            for source_case in valid_source_variants(program_line):
                with self.subTest(source_case.name):
                    # ACT & ASSERT #
                    integration_check.check_execution(
                        self,
                        sut.actor(),
                        [instr([program_line])],
                        arrangement_w_tcds(
                            symbol_table=program_symbol.symbol_table,
                            act_exe_input=AtcExeInputArr(environ=environ),
                        ),
                        Expectation(
                            symbol_usages=asrt.matches_singleton_sequence(
                                program_symbol.
                                reference_assertion__string__w_all_indirect_refs_are_strings
                            ),
                            execute=asrt_eh.is_exit_code(
                                exit_code_from_program)),
                    )
Пример #6
0
    def test_symbol_reference_in_dst_file_argument(self):
        dst_path_symbol = ConstantSuffixPathDdvSymbolContext(
            'dst_path_symbol', RelOptionType.REL_ACT, 'dst-file.txt',
            ACCEPTED_DST_RELATIVITY_VARIANTS)
        string_value = rich_str_abs_stx.HereDocAbsStx(
            'single line in here doc\n')
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_path_symbol.abstract_syntax,
            string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
        )

        expected_file = fs.File(dst_path_symbol.path_suffix,
                                string_value.value)
        integration_check.CHECKER__BEFORE_ACT.check__abs_stx(
            self, instruction_syntax,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    pre_population_action=
                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                symbols=dst_path_symbol.symbol_table,
            ),
            Expectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_singleton_sequence(
                    dst_path_symbol.reference_assertion),
                main_side_effects_on_sds=dir_contains_exactly(
                    dst_path_symbol.rel_option_type,
                    fs.DirContents([expected_file])),
            ))
Пример #7
0
    def test_possibility_to_have_sds_path_references_in_argument(self):
        file_name_of_referenced_file = 'file-name.txt'
        symbol = ConstantSuffixPathDdvSymbolContext(
            'symbol_name', RelOptionType.REL_TMP, file_name_of_referenced_file)

        executable = 'the-executable'

        command_line = '{executable} {symbol}'.format(
            executable=executable,
            symbol=symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = Expectation(
            execute=eh_assertions.is_exit_code(0),
            symbol_usages=asrt.matches_singleton_sequence(
                symbol.reference_assertion__w_str_rendering),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(
                    str_asrt.contains(file_name_of_referenced_file))),
        )

        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Пример #8
0
    def test_transformation_SHOULD_apply_only_to_matcher_argument(self):
        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'the_to_upper_transformer', string_transformers.to_uppercase())

        model = contents_transformation.TransformedContentsSetup(
            original='text',
            transformed='TEXT',
        )

        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            args2.conjunction([
                args2.Parentheses(
                    args2.Transformed(
                        to_upper_transformer.name,
                        args2.Equals.eq_string(model.transformed)), ),
                args2.Equals.eq_string(model.original),
            ]).as_arguments, model_constructor.of_str(self, model.original),
            arrangement_w_tcds(symbols=to_upper_transformer.symbol_table),
            Expectation(
                ParseExpectation(
                    symbol_references=asrt.matches_singleton_sequence(
                        is_reference_to_string_transformer(
                            to_upper_transformer.name))),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True))))
Пример #9
0
    def runTest(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 #
        for may_depend_on_external_resources in [False, True]:
            with self.subTest(may_depend_on_external_resources=may_depend_on_external_resources):
                integration_check.CHECKER__PARSE_SIMPLE.check(
                    self,
                    remaining_source(arguments),
                    model_constructor.empty(self,
                                            may_depend_on_external_resources=may_depend_on_external_resources),
                    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):
        unconditionally_constant_true = FilesMatcherSymbolContext.of_primitive_constant(
            'unconditionally_constant_true', True)
        symbols = unconditionally_constant_true.symbol_table

        location = RelSdsOptionType.REL_TMP
        model_file_name = 'the-checked-file'

        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments=args.DirContents(
                args.SymbolReference(
                    unconditionally_constant_true.name)).as_arguments,
            symbol_references=asrt.matches_singleton_sequence(
                unconditionally_constant_true.reference_assertion),
            input_=integration_check.file_in_sds(location, model_file_name),
            execution=[
                NExArr(
                    invalid_file_case.name,
                    PrimAndExeExpectation.of_exe(
                        is_hard_error=asrt_renderer.
                        is_renderer_of_major_blocks()),
                    arrangement_w_tcds(
                        symbols=symbols,
                        non_hds_contents=sds_populator.contents_in(
                            location, invalid_file_case.value)))
                for invalid_file_case in invalid_model.cases(model_file_name)
            ])
Пример #11
0
    def test_node_with_detail_and_child(self):
        # ARRANGE #

        for child_data in [False, True]:
            with self.subTest(data=child_data):
                child = Node('the child', child_data, (), ())
                detail = StringDetail('the detail')
                root = Node('the root', False, [detail], [child])

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_sequence([
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_sequence([
                                matches_header_line_element(root),
                                matches_string_detail_line_element(detail,
                                                                   depth=0),
                            ]),
                            properties=matches_node_properties(depth=0),
                        ),
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_singleton_sequence(
                                matches_header_line_element(child)),
                            properties=matches_node_properties(depth=1),
                        ),
                    ]))

                # ACT & ASSERT #

                _check(self, root, expectation)
Пример #12
0
    def test(self):

        expected_defined_symbol = ConstantSuffixPathDdvSymbolContext(
            'name', RelOptionType.REL_ACT, 'component')
        argument_cases = [
            NameAndValue('value on same line', '{rel_act} {suffix}'),
            NameAndValue('value on following line',
                         '{new_line} {rel_act} {suffix}'),
        ]

        for argument_case in argument_cases:
            with self.subTest(arguments=argument_case.name):
                instruction_argument = src2(
                    ValueType.PATH,
                    expected_defined_symbol.name,
                    argument_case.value,
                    suffix=expected_defined_symbol.path_suffix)
                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self, instruction_argument):
                    INSTRUCTION_CHECKER.check(
                        self, source, Arrangement.phase_agnostic(),
                        Expectation.phase_agnostic(
                            symbol_usages=asrt.matches_singleton_sequence(
                                expected_defined_symbol.
                                assert_matches_definition_of_sdv),
                            symbols_after_main=assert_symbol_table_is_singleton(
                                expected_defined_symbol.name,
                                expected_defined_symbol.value.
                                assert_matches_container_of_sdv)))
Пример #13
0
    def runTest(self):
        # ARRANGE #
        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'a-dir')

        unconditionally_hard_error_file_matcher = FileMatcherSymbolContext.of_primitive(
            'unconditionally_hard_error_file_matcher',
            matchers.MatcherThatReportsHardError())
        file_in_model = 'a-file'
        # ACT & ASSERT #
        check_non_full_and_full(
            self,
            fc_args.FilesCondition([
                fc_args.FileCondition(
                    file_in_model,
                    fm_args.SymbolReferenceWReferenceSyntax(
                        unconditionally_hard_error_file_matcher.name)),
            ]),
            model_constructor__non_recursive(checked_dir.path_sdv),
            Arrangement(
                symbols=unconditionally_hard_error_file_matcher.symbol_table,
                tcds=checked_dir.tcds_arrangement_dir_with_contents(
                    [File.empty(file_in_model)])),
            Expectation(
                ParseExpectation(
                    symbol_references=asrt.matches_singleton_sequence(
                        unconditionally_hard_error_file_matcher.
                        reference_assertion)),
                ExecutionExpectation(
                    is_hard_error=asrt_text_doc.is_any_text())),
        )
Пример #14
0
    def test_transformation_only_as_source_argument(self):
        # ARRANGE #
        transformer = StringTransformerPrimitiveSymbolContext(
            'STRING_TRANSFORMER', string_transformers.to_uppercase())

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            program_w_transformer = FullProgramAbsStx(
                pgm_and_args_case.pgm_and_args,
                transformation=transformer.abstract_syntax)

            symbols = list(pgm_and_args_case.symbols) + [transformer]

            with self.subTest(command=pgm_and_args_case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self, equivalent_source_variants__for_expr_parse__s__nsc,
                    program_w_transformer,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    MultiSourceExpectation(
                        symbol_references=SymbolContext.
                        references_assertion_of_contexts(symbols),
                        primitive=lambda env: (asrt_pgm_val.matches_program(
                            asrt_command.
                            matches_command(driver=pgm_and_args_case.
                                            expected_command_driver(env),
                                            arguments=asrt.is_empty_sequence),
                            stdin=asrt_pgm_val.is_no_stdin(),
                            transformer=asrt.matches_singleton_sequence(
                                asrt.is_(transformer.primitive)),
                        ))))
Пример #15
0
    def runTest(self):
        # ARRANGE #

        files_matcher_name = 'the_files_matcher'
        checked_dir_location = RelSdsOptionType.REL_TMP
        checked_dir = Dir.empty('checked-dir')

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments=args.DirContents(
                fsm_args.SymbolReference(files_matcher_name)).as_arguments,
            input_=integration_check.file_in_sds(checked_dir_location,
                                                 checked_dir.name),
            symbol_references=asrt.matches_singleton_sequence(
                is_reference_to_files_matcher(files_matcher_name)),
            execution=[
                NExArr(
                    'checked dir is empty',
                    PrimAndExeExpectation.of_exe(
                        main_result=asrt_matching_result.matches_value(
                            matcher_result)),
                    arrangement_w_tcds(
                        non_hds_contents=sds_populator.contents_in(
                            checked_dir_location, DirContents([checked_dir])),
                        symbols=FilesMatcherSymbolContext.
                        of_primitive_constant(files_matcher_name,
                                              matcher_result).symbol_table,
                    ),
                ) for matcher_result in [False, True]
            ],
        )
Пример #16
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=[],
            )
        )
Пример #17
0
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(
                 abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src2(ValueType.PATH, 'name',
                                     '{rel_source_file} component')
         for source in equivalent_source_variants__with_source_check__consume_last_line(
                 self, instruction_argument):
             expected_path_sdv = path_sdvs.constant(
                 path_ddvs.rel_abs_path(
                     abs_path_of_dir_containing_last_file_base_name,
                     path_ddvs.constant_path_part('component')))
             expected_symbol_value = PathSymbolValueContext.of_sdv(
                 expected_path_sdv)
             expected_symbol = PathSymbolContext('name',
                                                 expected_symbol_value)
             INSTRUCTION_CHECKER.check(
                 self, source,
                 Arrangement.phase_agnostic(
                     fs_location_info=fs_location_info),
                 Expectation.phase_agnostic(
                     symbol_usages=asrt.matches_singleton_sequence(
                         expected_symbol.assert_matches_definition_of_sdv),
                     symbols_after_main=assert_symbol_table_is_singleton(
                         'name', expected_symbol_value.
                         assert_matches_container_of_sdv)))
Пример #18
0
 def expectation(self) -> Expectation:
     return Expectation(
         symbol_usages=asrt.matches_singleton_sequence(
             is_reference_to_files_matcher__usage(
                 self.name_of_referenced_symbol)),
         main_result=asrt_pfh.is_hard_error(
             is_string_for_test_that_equals(self.error_message)),
     )
Пример #19
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,
                )
Пример #20
0
 def test_matches(self):
     command = system_program_command('program', [])
     stdin_data = ()
     transformer = IdentityStringTransformer()
     sut.matches_program(
         command=asrt.is_(command),
         stdin=asrt.is_(stdin_data),
         transformer=asrt.matches_singleton_sequence(asrt.is_(transformer)),
     )
Пример #21
0
    def test_result_of_execution_SHOULD_be_negation_of_negated_expr(self):
        # ARRANGE #
        conf = self.configuration
        helper = self._asrt_helper
        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        mk_operand_trace = get_mk_operand_trace('the_operand')

        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))

        execution_cases = [
            execution_case_for(operand_result)
            for operand_result in [False, True]
        ]

        source_cases = [
            NameAndValue(
                'operand on same line',
                ArgumentElements([logic.NOT_OPERATOR_NAME, symbol_name], )),
            NameAndValue(
                'operand on following line',
                ArgumentElements([logic.NOT_OPERATOR_NAME], [
                    [symbol_name],
                ])),
        ]

        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case.name):
                conf.checker_for_parser_of_full_expr(
                ).check_multi__w_source_variants(
                    self,
                    arguments=source_case.value.as_arguments,
                    symbol_references=asrt.matches_singleton_sequence(
                        helper.is_sym_ref_to(symbol_name)),
                    input_=conf.arbitrary_model,
                    execution=execution_cases,
                )
 def test_matches(self):
     # ARRANGE #
     expected_detail = StringDetail('the string detail')
     actual = sut.IndentedDetail([expected_detail])
     # EXPECTATION #
     assertion = sut.is_indented_detail(
         details=asrt.matches_singleton_sequence(asrt.is_(expected_detail))
     )
     # ACT & ASSERT #
     assertion.apply_without_message(self, actual)
Пример #23
0
 def test_should_have_exactly_one_references(self):
     # ARRANGE #
     symbol_reference = TypeWithStrRenderingSymbolReference(
         'the_symbol_name', is_any_type_w_str_rendering())
     fragment = impl.SymbolStringFragmentSdv(symbol_reference.reference)
     # ACT #
     actual = list(fragment.references)
     # ASSERT #
     assertion = asrt.matches_singleton_sequence(
         symbol_reference.reference_assertion)
     assertion.apply_without_message(self, actual)
Пример #24
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),
             )
Пример #25
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)
                     ),
                 )
             )
Пример #26
0
def matches_trace_with_details(
    tree: Node[bool],
    details: Sequence[Assertion[s.LineElement]],
) -> Assertion[s.MajorBlock]:
    expected_line_elements = asrt.matches_sequence(
        [matches_header_line_element(tree)] + list(details))
    return asrt_struct.matches_major_block__w_plain_properties(
        minor_blocks=asrt.matches_singleton_sequence(
            asrt_struct.matches_minor_block(
                line_elements=expected_line_elements,
                properties=matches_node_properties(depth=0),
            )))
Пример #27
0
 def test_expression_inside_parentheses_SHOULD_be_validated(self):
     symbol_name = 'fc_symbol'
     CHECKER.check_multi__w_source_variants(
         self,
         arguments=args.Parentheses(
             args.SymbolReferenceWReferenceSyntax(
                 symbol_name)).as_arguments,
         symbol_references=asrt.matches_singleton_sequence(
             is_reference_to_files_condition(symbol_name)),
         input_=None,
         execution=failing_validation_cases__multi_exe(symbol_name),
     )
Пример #28
0
 def runTest(self):
     fsm_symbol_name = 'the_files_matcher'
     integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
         self,
         args.DirContents(
             args.SymbolReference(fsm_symbol_name)).as_arguments,
         symbol_references=asrt.matches_singleton_sequence(
             is_reference_to_files_matcher(fsm_symbol_name)),
         input_=integration_check.constant_relative_file_name(
             'arbitrary-file-argument'),
         execution=instruction_validation_cases.
         failing_validation_cases__multi_exe(fsm_symbol_name))
Пример #29
0
    def test_header(self):
        # ARRANGE #
        for data in [False, True]:
            with self.subTest(data=data):
                root = Node('header', data, (), ())
                renderer = ConstantNodeRendererTestImpl(root)

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_singleton_sequence(
                        asrt_struct.matches_minor_block__w_plain_properties(
                            line_elements=asrt.matches_singleton_sequence(
                                _matches_header_line_element(root)
                            ),
                        )
                    )
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Пример #30
0
    def runTest(self):
        # ARRANGE #
        transformer = StringTransformerPrimitiveSymbolContext(
            'STRING_TRANSFORMER', string_transformers.to_uppercase())
        after_bin_op = 'after bin op'
        after_bin_op_syntax = CustomStringTransformerAbsStx.of_str(
            after_bin_op)
        composition_string_transformer = StringTransformerCompositionAbsStx(
            [transformer.abstract_syntax, after_bin_op_syntax],
            within_parens=False,
            allow_elements_on_separate_lines=False,
        )
        expected_source_after_parse = asrt_source.is_at_line(
            current_line_number=2,
            remaining_part_of_current_line=' '.join(
                [composition_string_transformer.operator_name(),
                 after_bin_op]),
        )
        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            command_followed_by_transformer = FullProgramAbsStx(
                pgm_and_args_case.pgm_and_args,
                transformation=composition_string_transformer,
            )
            symbols = list(pgm_and_args_case.symbols) + [transformer]

            with self.subTest(command=pgm_and_args_case.name):
                source = remaining_source(
                    command_followed_by_transformer.tokenization().layout(
                        LayoutSpec.of_default()))
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check(
                    self, source, None,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    Expectation(
                        ParseExpectation(
                            source=expected_source_after_parse,
                            symbol_references=SymbolContext.
                            references_assertion_of_contexts(symbols),
                        ),
                        primitive=lambda env: (asrt_pgm_val.matches_program(
                            asrt_command.
                            matches_command(driver=pgm_and_args_case.
                                            expected_command_driver(env),
                                            arguments=asrt.is_empty_sequence),
                            stdin=asrt_pgm_val.is_no_stdin(),
                            transformer=asrt.matches_singleton_sequence(
                                asrt.is_(transformer.primitive)),
                        ))))