示例#1
0
 def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
     for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES:
         with self.subTest(
                 maybe_with_transformer_option=maybe_with_transformer_option
         ):
             self._check_with_source_variants(
                 test_configuration.arguments_for(
                     args(
                         '{maybe_with_transformer_option} {maybe_not} {empty}',
                         maybe_with_transformer_option=
                         maybe_with_transformer_option,
                         maybe_not=maybe_not.
                         nothing__if_positive__not_option__if_negative)),
                 model_constructor.of_str(
                     self, 'contents that makes the file non-empty'),
                 arrangement_w_tcds(
                     post_population_action=
                     MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY),
                 Expectation(execution=ExecutionExpectation(
                     main_result=maybe_not.
                     fail__if_positive__pass_if_negative), ),
             )
示例#2
0
    def runTest(self):
        # ARRANGE #
        input_lines = [
            '1st',
            '2nd',
            '3rd',
        ]
        expected_line_matcher_models = line_matcher_models.models_for_lines__validated(input_lines)
        string_transformer_model = model_constructor.of_lines_wo_nl(self, input_lines)

        models_output = []
        line_matcher = LineMatcherSymbolContext.of_primitive(
            'MATCHER',
            LineMatcherThatCollectsModels(models_output, True),
        )

        line_matcher_arg = lm_args.SymbolReference(line_matcher.name)
        arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            source=remaining_source(arguments),
            input_=string_transformer_model,
            arrangement=arrangement_w_tcds(
                symbols=line_matcher.symbol_table,
            ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=line_matcher.references_assertion
                ),
                ExecutionExpectation(
                    main_result=asrt.anything_goes(),
                ),
                prim_asrt__any
            ),
        )
        self.assertEqual(expected_line_matcher_models,
                         models_output,
                         'models given to line matcher')
示例#3
0
 def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
     actual_contents = lines_content(['123'])
     here_doc = here_document_as_elements(['1.3'])
     for transformer_option_arguments in TRANSFORMER_OPTION_ALTERNATIVES_ELEMENTS:
         with self.subTest(maybe_with_transformer_option=transformer_option_arguments):
             argument_elements = ArgumentElements(transformer_option_arguments +
                                                  maybe_not.empty__if_positive__not_option__if_negative +
                                                  [matcher_options.MATCHES_ARGUMENT]
                                                  ).followed_by(here_doc)
             self._check(
                 argument_elements.as_remaining_source,
                 model_constructor.of_str(self, actual_contents),
                 arrangement_w_tcds(),
                 Expectation(
                     ParseExpectation(
                         source=asrt_source.is_at_end_of_line(1 + len(here_doc.following_lines)),
                     ),
                     ExecutionExpectation(
                         main_result=maybe_not.pass__if_positive__fail__if_negative
                     ),
                 ),
             )
示例#4
0
 def runTest(self):
     self._check_with_source_variants(
         test_configuration.arguments_for(
             args('{maybe_not} {equals} {file_option} {relativity_option} expected.txt',
                  maybe_not=self.not_opt.nothing__if_positive__not_option__if_negative,
                  relativity_option=self.rel_opt.option_argument)),
         model_constructor.of_str(self, 'expected'),
         arrangement_w_tcds(
             self.rel_opt.populator_for_relativity_option_root(
                 DirContents([File('expected.txt', 'expected')])),
             post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
             symbols=self.rel_opt.symbols.in_arrangement(),
         ),
         Expectation(
             ParseExpectation(
                 symbol_references=self.rel_opt.symbols.usages_expectation(),
             ),
             ExecutionExpectation(
                 main_result=self.not_opt.pass__if_positive__fail__if_negative,
             ),
         ),
     )
示例#5
0
    def runTest(self):
        any_char_glob_pattern_string_symbol = StringSymbolContext.of_constant(
            'glob_pattern_string_symbol', '*')
        arguments = arg.Name(
            arg.NameGlobPatternVariant(
                'AB' +
                any_char_glob_pattern_string_symbol.name__sym_ref_syntax))

        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            arguments=arguments.as_arguments,
            input_=integration_check.constant_relative_file_name('ABC'),
            arrangement=arrangement_w_tcds(
                symbols=any_char_glob_pattern_string_symbol.symbol_table),
            expectation=Expectation(
                ParseExpectation(symbol_references=asrt.matches_sequence([
                    is_reference_to__regex_string_part(
                        any_char_glob_pattern_string_symbol.name),
                ]), ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True)),
            ))
示例#6
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(), ),
                     ),
                 )
示例#7
0
    def runTest(self):
        # ARRANGE #
        def get_trace(data: T) -> tree.Node[T]:
            return tree.Node.empty('name of string matcher', data)

        for string_matcher_result in [False, True]:
            string_matcher = StringMatcherSymbolContext.of_primitive(
                'STRING_MATCHER',
                ConstantMatcherWithCustomTrace(get_trace,
                                               string_matcher_result),
            )
            expected_trace = tree.Node(
                MATCHER_NAME,
                string_matcher_result,
                (),
                [get_trace(string_matcher_result)],
            )

            # ACT & ASSERT #
            with self.subTest(string_matcher_result=string_matcher_result):
                integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                    self,
                    arguments=lm_args.Contents(
                        sm_args2.SymbolReferenceWReferenceSyntax(
                            string_matcher.name), ).as_arguments,
                    input_=models.ARBITRARY_MODEL,
                    arrangement=arrangement_wo_tcds(
                        symbols=string_matcher.symbol_table, ),
                    expectation=Expectation(
                        ParseExpectation(symbol_references=string_matcher.
                                         references_assertion),
                        ExecutionExpectation(
                            main_result=asrt_matching_result.matches(
                                asrt.equals(string_matcher_result),
                                trace=asrt_trace_rendering.
                                matches_node_renderer(
                                    asrt_d_tree.equals_node(expected_trace)),
                            ))),
                )
示例#8
0
    def runTest(self):
        # ARRANGE #
        line_contents = 'the line contents'

        def get_string_matcher_model_as_single_string(
                model: StringSource) -> str:
            return model.contents().as_str

        matching_result = True
        string_matcher = StringMatcherSymbolContext.of_primitive(
            'STRING_MATCHER',
            matcher_w_init_action.matcher_that_applies_assertion(
                self,
                assertion=asrt.equals(line_contents),
                get_actual=get_string_matcher_model_as_single_string,
                message_builder=asrt.MessageBuilder.new(
                    'string-matcher-model'),
                result=matching_result,
            ),
        )
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
            self,
            arguments=lm_args.Contents(
                sm_args2.SymbolReferenceWReferenceSyntax(
                    string_matcher.name), ).as_arguments,
            input_=models.constant((1, line_contents)),
            arrangement=arrangement_wo_tcds(
                symbols=string_matcher.symbol_table, ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=string_matcher.references_assertion),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value__w_header(
                        asrt.equals(matching_result),
                        header=asrt.equals(MATCHER_NAME),
                    ))),
        )
示例#9
0
def check_regex(put: unittest.TestCase,
                conf: Configuration,
                pattern: str,
                ignore_case: bool,
                model: ModelConstructor,
                expected_result: bool,
                ):
    pattern_string_symbol = StringSymbolContext.of_constant(
        'PATTERN_SYMBOL',
        pattern,
        default_restrictions=is_reference_restrictions__regex()
    )
    arguments = conf.arguments(
        NameRegexVariant.of(pattern_string_symbol.name__sym_ref_syntax,
                            ignore_case=ignore_case)
    )

    integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
        put,
        arguments=arguments.as_arguments,
        input_=model,
        arrangement=arrangement_wo_tcds(
            symbols=pattern_string_symbol.symbol_table
        ),
        expectation=Expectation(
            ParseExpectation(
                symbol_references=asrt.matches_sequence([
                    pattern_string_symbol.reference_assertion,
                ]),
            ),
            ExecutionExpectation(
                main_result=asrt_matching_result.matches_value__w_header(
                    asrt.equals(expected_result),
                    asrt.equals(conf.node_name)
                )
            ),
        )
    )
 def test_dir(self):
     file_name = 'destination'
     file_name_syntax = StringLiteralAbsStx(file_name, QuoteType.HARD)
     explicit_dir_contents = LiteralFilesSourceAbsStx(())
     file_spec_syntax = dir_spec(
         file_name_syntax,
         DirContentsExplicitAbsStx(ModificationType.APPEND,
                                   explicit_dir_contents),
     )
     for dir_contents_case in file_must_exist_as_dir(file_name):
         with self.subTest(dir_contents=dir_contents_case.name):
             integration_check.CHECKER.check__abs_stx(
                 self,
                 LiteralFilesSourceAbsStx([file_spec_syntax]),
                 dir_contents_case.value,
                 arrangement_w_tcds(),
                 Expectation(
                     parse=IS_AT_END_OF_1ST_LNE,
                     execution=ExecutionExpectation(
                         is_hard_error=asrt_text_doc.is_any_text(),
                     )
                 ),
             )
示例#11
0
 def runTest(self):
     # ARRANGE #
     model_contents = 'the contents of the model'
     test_setup = StdinCheckViaCopyToOutputFileTestSetup(
         ProcOutputFile.STDOUT)
     # ACT & ASSERT #
     integration_check.CHECKER__PARSE_FULL.check__abs_stx(
         self,
         RunProgramAbsStx(test_setup.program_that_copies_stdin_syntax(), ),
         model_constructor.of_str(self, model_contents),
         arrangement_w_tcds(symbols=SymbolContext.symbol_table_of_contexts(
             test_setup.symbols), ),
         Expectation(
             parse=ParseExpectation(
                 symbol_references=SymbolContext.
                 references_assertion_of_contexts(test_setup.symbols)),
             execution=ExecutionExpectation(
                 main_result=asrt_string_source.pre_post_freeze__identical(
                     asrt_contents.matches__str(asrt.equals(
                         model_contents)))),
             primitive=PRIMITIVE_IS_NOT_IDENTITY_TRANSFORMATION,
         ),
     )
 def test_recursive_model(self):
     # ARRANGE #
     file_in_sub_dir = File.empty('file-in-sub-dir')
     dir_in_checked_dir = Dir(
         'top-level-dir',
         [file_in_sub_dir],
     )
     checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'the-dir')
     # ACT & ASSERT #
     check_non_full_and_full(
         self,
         fc_args.FilesCondition([
             fc_args.FileCondition(dir_in_checked_dir.name),
             fc_args.FileCondition(file_in_sub_dir.name),
         ]),
         model_constructor__recursive(checked_dir.path_sdv),
         Arrangement(tcds=checked_dir.tcds_arrangement_dir_with_contents(
             [dir_in_checked_dir])),
         Expectation(
             ParseExpectation(symbol_references=asrt.is_empty_sequence),
             ExecutionExpectation(main_result=asrt.equals(False)),
         ),
     )
示例#13
0
    def test_just_symbol_reference(self):
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'symbol value contents',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        string_source_syntax = StringSourceOfStringAbsStx.of_plain(
            str_abs_stx.StringSymbolAbsStx(contents_symbol.name))

        CHECKER.check__abs_stx(
            self, string_source_syntax, None,
            arrangement_w_tcds(symbols=contents_symbol.symbol_table, ),
            Expectation.of_prim__const(
                primitive=asrt_string_source.
                pre_post_freeze__matches_str__const(
                    contents_symbol.str_value,
                    may_depend_on_external_resources=False),
                parse=ParseExpectation(
                    symbol_references=asrt.matches_singleton_sequence(
                        references.is_reference_to__string_source_or_string(
                            contents_symbol.name)), ),
            ))
示例#14
0
    def test_failure_to_execute_program(self):
        # ARRANGE #

        for with_ignored_exit_code in [False, True]:
            with self.subTest(with_ignored_exit_code=with_ignored_exit_code):
                # ACT && ASSERT #

                integration_check.CHECKER__PARSE_FULL.check(
                    self,
                    args.syntax_for_run(
                        program_args.system_program_argument_elements(
                            NON_EXISTING_SYSTEM_PROGRAM),
                        ignore_exit_code=with_ignored_exit_code,
                    ).as_remaining_source,
                    model_constructor.arbitrary(self),
                    arrangement_w_tcds(),
                    Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_end_of_line(1), ),
                        ExecutionExpectation(
                            is_hard_error=asrt_text_doc.is_any_text()),
                    ),
                )
示例#15
0
 def _check(self,
            expected_contents: str,
            actual_contents: str,
            may_depend_on_external_resources: bool,
            expected_result: bool,
            ):
     string_symbol_with_expected = StringSymbolContext.of_constant(
         'EXPECTED_CONTENTS_SYMBOL',
         expected_contents,
     )
     integration_check.CHECKER__PARSE_SIMPLE.check(
         self,
         args2.Equals.eq_string(
             string_symbol_with_expected.name__sym_ref_syntax
         ).as_remaining_source,
         model_constructor.of_str(
             self,
             actual_contents,
             may_depend_on_external_resources=may_depend_on_external_resources,
         ),
         arrangement_w_tcds(
             symbols=string_symbol_with_expected.symbol_table
         ),
         Expectation(
             ParseExpectation(
                 symbol_references=
                 asrt.matches_singleton_sequence(
                     references.is_reference_to__string_source_or_string(string_symbol_with_expected.name)
                 )
             ),
             execution=ExecutionExpectation(
                 main_result=asrt_matching_result.matches_value(
                     expected_result
                 )
             ),
         ),
     )
示例#16
0
    def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
        # ARRANGE #

        named_transformer = StringTransformerSymbolContext.of_primitive(
            'the_transformer', every_line_empty())

        checked_file = File('actual.txt', 'some\ntext')

        symbols = named_transformer.symbol_table

        expected_symbol_reference_to_transformer = is_reference_to_string_transformer(
            named_transformer.name)

        expected_symbol_usages = asrt.matches_sequence(
            [expected_symbol_reference_to_transformer])

        # ACT & ASSERT #

        self._check_with_source_variants(
            arguments=arguments_for(
                sm_args.args(
                    '{transform_option} {the_transformer} {maybe_not} {empty}',
                    the_transformer=named_transformer.name,
                    maybe_not=maybe_not.
                    nothing__if_positive__not_option__if_negative)),
            model_constructor=integration_check.constant_relative_file_name(
                checked_file.name),
            arrangement=arrangement_w_tcds(
                non_hds_contents=single_file_in_current_dir(checked_file),
                symbols=symbols,
            ),
            expectation=Expectation(
                ParseExpectation(symbol_references=expected_symbol_usages),
                ExecutionExpectation(
                    main_result=maybe_not.pass__if_positive__fail__if_negative,
                ),
            ))
示例#17
0
    def test_populate_result_dir_with_act_result(self):
        act_result = SubProcessResult(
            exitcode=72,
            stdout='the stdout',
            stderr='the stderr',
        )

        result_dir_contains_files_corresponding_to_act_result = asrt_tcds_contents.dir_contains_exactly(
            RelOptionType.REL_RESULT,
            DirContents([
                File(sds.RESULT_FILE__EXITCODE, str(act_result.exitcode)),
                File(sds.RESULT_FILE__STDOUT, str(act_result.stdout)),
                File(sds.RESULT_FILE__STDERR, str(act_result.stderr)),
            ])
        )

        all_tcds_dirs_but_result_dir_are_empty = asrt.and_([
            dir_is_empty(tcds_dir)
            for tcds_dir in RelOptionType if tcds_dir is not RelOptionType.REL_RESULT
        ])

        self._check___single_and_multi(
            utils.single_line_arguments(),
            ARBITRARY_MODEL,
            parser_of_matcher_that_is_an_assertion_on_tcds(
                self,
                asrt.and_([
                    result_dir_contains_files_corresponding_to_act_result,
                    all_tcds_dirs_but_result_dir_are_empty,
                ]
                )
            ),
            arrangement_w_tcds(
                act_result=ActResultProducerFromActResult(act_result)
            ),
            Expectation(),
        )
示例#18
0
    def runTest(self):
        model__original = 'the model text'
        the_model_constructor = model_constructor.of_str(self, model__original)

        string_transformer = StringTransformerSymbolContext.of_primitive(
            'THE_STRING_TRANSFORMER', string_transformers.to_uppercase())
        sm_equals = StringMatcherSymbolContext.of_primitive(
            'STRING_MATCHER_1',
            string_matchers.EqualsConstant(model__original.upper()))
        symbol = [
            string_transformer,
            sm_equals,
        ]

        after_bin_op = 'after bin op'
        sm_conjunction = args2.conjunction([
            args2.SymbolReference(sm_equals.name),
            args2.Custom(after_bin_op),
        ])
        arguments = args2.Transformed(string_transformer.name__sym_ref_syntax,
                                      sm_conjunction)
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            source=arguments.as_remaining_source,
            input_=the_model_constructor,
            arrangement=arrangement_w_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbol), ),
            expectation=Expectation(
                ParseExpectation(source=asrt_source.is_at_line(
                    current_line_number=1,
                    remaining_part_of_current_line=' '.join(
                        [sm_conjunction.operator, after_bin_op])),
                                 symbol_references=SymbolContext.
                                 references_assertion_of_contexts(symbol)),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True))),
        )
示例#19
0
    def test_symbols_from_comparison_SHOULD_be_reported(self):
        # ARRANGE #
        checked_dir_contents = DirContents([File.empty('1'), File.empty('2')])
        checked_path = rel_opts.conf_rel_sds(RelSdsOptionType.REL_ACT)

        operand_sym_ref = StringIntConstantSymbolContext(
            'operand_symbol_name',
            len(checked_dir_contents.file_system_elements),
            default_restrictions=symbol_reference.
            is_reference_restrictions__integer_expression(),
        )

        matcher_arguments = im_args.comparison(comparators.EQ,
                                               operand_sym_ref.argument)

        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            args.NumFiles(
                matcher_arguments.as_str,
                int_expr_on_new_line=True,
            ).as_remaining_source,
            model.model_with_rel_root_as_source_path(checked_path),
            arrangement_w_tcds(
                symbols=operand_sym_ref.symbol_table,
                tcds_contents=checked_path.
                populator_for_relativity_option_root(checked_dir_contents),
            ),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(2),
                    symbol_references=operand_sym_ref.references_assertion,
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True)),
            ))
示例#20
0
    def test_matcher_symbol_should_be_reported(self):
        # ARRANGE #
        matcher_symbol = IntegerMatcherSymbolContextOfPrimitiveConstant(
            'MATCHER_SYMBOL',
            True,
        )

        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            args.NumFiles(
                matcher_symbol.name__sym_ref_syntax,
                int_expr_on_new_line=True,
            ).as_remaining_source, model.arbitrary_model(),
            arrangement_w_tcds(symbols=matcher_symbol.symbol_table, ),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(2),
                    symbol_references=matcher_symbol.references_assertion,
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(
                        matcher_symbol.result_value)),
            ))
示例#21
0
    def runTest(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        argument_cases = [
            NIE(
                'prune followed by selection',
                input_value=fsm_args.Prune(
                    fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
                    fsm_args.Selection(
                        fm_args.SymbolReference(NAME_STARTS_WITH__S1.name),
                        helper.files_matcher_sym_ref_arg(),
                    ),
                ),
                expected_value=asrt.matches_sequence([
                    NAME_STARTS_WITH__P1.reference_assertion,
                    NAME_STARTS_WITH__S1.reference_assertion,
                    helper.symbol_reference_assertion,
                ]),
            ),
            NIE(
                'selection followed by prune',
                input_value=fsm_args.Selection(
                    fm_args.SymbolReference(NAME_STARTS_WITH__S1.name),
                    fsm_args.Prune(
                        fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
                        helper.files_matcher_sym_ref_arg(),
                    ),
                ),
                expected_value=asrt.matches_sequence([
                    NAME_STARTS_WITH__S1.reference_assertion,
                    NAME_STARTS_WITH__P1.reference_assertion,
                    helper.symbol_reference_assertion,
                ]),
            ),
        ]

        contents_case = COMBINATION_OF_PRUNE_AND_SELECTION

        # ACT & ASSERT #

        for argument_case in argument_cases:
            with self.subTest(argument_case.name):
                integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
                    self,
                    arguments=argument_case.input_value.as_arguments,
                    input_=helper.model_constructor_for_checked_dir__recursive(
                    ),
                    arrangement=helper.arrangement_for_contents_of_model(
                        checked_dir_contents=contents_case.actual,
                        files_matcher_symbol_value=model_checker.matcher(
                            self,
                            helper.dir_arg.path_sdv,
                            contents_case.expected,
                        ),
                        additional_symbols=[
                            NAME_STARTS_WITH__P1,
                            NAME_STARTS_WITH__S1,
                        ],
                    ),
                    expectation=Expectation(
                        ParseExpectation(
                            symbol_references=argument_case.expected_value, )),
                )
示例#22
0
    def test_string_transformer_should_be_parsed_as_simple_expression(self):
        the_layout = LayoutSpec.of_default()

        output_from_program = 'untransformed output from the program'

        sym_ref_program_syntax = ProgramOfSymbolReferenceAbsStx(
            'PROGRAM_THAT_EXECUTES_PY_FILE')

        str_trans__unused = StringTransformerSymbolReferenceAbsStx(
            'UNUSED_TRANSFORMER')

        program_w_complex_str_trans_wo_parentheses = program_abs_stx.FullProgramAbsStx(
            ProgramOfSymbolReferenceAbsStx(sym_ref_program_syntax.symbol_name),
            transformation=str_trans_abs_stx.
            StringTransformerCompositionAbsStx(
                [
                    TO_UPPER_TRANSFORMER_SYMBOL.abstract_syntax,
                    str_trans__unused,
                ],
                within_parens=False,
                allow_elements_on_separate_lines=False,
            ))
        expected_remaining_tokens = TokenSequence.concat([
            TokenSequence.singleton(
                str_trans_abs_stx.names.SEQUENCE_OPERATOR_NAME),
            str_trans__unused.tokenization(),
        ])
        expected_remaining_source = expected_remaining_tokens.layout(
            the_layout)

        checker = integration_check.checker__w_arbitrary_file_relativities()

        py_program_file = File(
            'program.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(
                exit_code=0,
                stdout_output=output_from_program,
                stderr_output=output_from_program,
            ),
        )
        py_file_rel_conf = rel_opt.conf_rel_any(RelOptionType.REL_HDS_CASE)
        py_file_conf = py_file_rel_conf.named_file_conf(py_program_file.name)

        program_symbol__that_executes_py_file = ProgramSymbolContext.of_sdv(
            sym_ref_program_syntax.symbol_name,
            program_sdvs.interpret_py_source_file_that_must_exist(
                py_file_conf.path_sdv))
        symbols = [
            program_symbol__that_executes_py_file,
            TO_UPPER_TRANSFORMER_SYMBOL,
        ]

        for output_file in ProcOutputFile:
            for ignore_exit_code in [False, True]:
                syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
                    output_file,
                    program_w_complex_str_trans_wo_parentheses,
                    ignore_exit_code=ignore_exit_code,
                )
                with self.subTest(output_file=output_file,
                                  ignore_exit_code=ignore_exit_code):
                    checker.check__abs_stx__wo_input(
                        self,
                        syntax,
                        arrangement_w_tcds(
                            symbols=SymbolContext.symbol_table_of_contexts(
                                symbols),
                            tcds_contents=py_file_rel_conf.
                            populator_for_relativity_option_root(
                                DirContents([py_program_file]))),
                        Expectation(
                            ParseExpectation(
                                source=asrt_source.source_is_not_at_end(
                                    remaining_source=asrt.equals(
                                        expected_remaining_source)),
                                symbol_references=SymbolContext.
                                references_assertion_of_contexts(symbols),
                            )),
                        the_layout,
                    )
示例#23
0
def check_cases__named(put: unittest.TestCase,
                       cases: Sequence[NameAndValue[Case]]):
    for case in cases:
        with put.subTest(case.name):
            check(put, case.value)


def check(put: unittest.TestCase, case: Case):
    integration_check.CHECKER__PARSE_SIMPLE__WO_IMPLICIT_MODEL_EVALUATION.check(
        put, case.arguments.as_remaining_source,
        _model_w_access_check(put, case.model, case.max_num_lines_from_iter),
        arrangement_wo_tcds(
            symbols=SymbolContext.symbol_table_of_contexts(case.symbols)),
        Expectation(
            parse=ParseExpectation(source=asrt_source.is_at_end_of_line(1),
                                   symbol_references=SymbolContext.
                                   references_assertion_of_contexts(
                                       case.symbols)),
            execution=ExecutionExpectation(main_result=asrt_string_source.
                                           matches__lines__check_just_as_lines(
                                               case.expected_output_lines)),
        ))


class IntSymbol:
    def __init__(self, name: str):
        self.name = name

    def value(self, value: int) -> StringConstantSymbolContext:
        return StringIntConstantSymbolContext(
            self.name,
示例#24
0
def is_expectation_of_execution_result_of(
        expected: bool) -> Expectation[MatcherWTrace[MODEL], MatchingResult]:
    return Expectation(execution=ExecutionExpectation(
        main_result=asrt_matching_result.matches_value(expected)))
    def test_multiple_files(self):
        # ARRANGE #
        name_of_regular_file = 'a-regular-file'
        name_of_dir = 'a-dir'

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP,
                                        'dir-w-multiple-files')

        arrangement = Arrangement(
            IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS,
            checked_dir.tcds_arrangement_dir_with_contents([
                File.empty(name_of_regular_file),
                Dir.empty(name_of_dir),
            ]))
        cases = [
            Case(
                'no file matchers',
                fc_args.FilesCondition([
                    fc_args.FileCondition(name_of_regular_file),
                    fc_args.FileCondition(name_of_dir),
                ]),
                arrangement,
                Expectation(
                    ParseExpectation(symbol_references=asrt.is_empty_sequence),
                    MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
            Case(
                'with matcher on regular file',
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        name_of_regular_file,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_REGULAR_FILE_FILE_MATCHER.name)),
                    fc_args.FileCondition(name_of_dir),
                ]),
                arrangement,
                Expectation(
                    ParseExpectation(
                        symbol_references=asrt.matches_singleton_sequence(
                            IS_REGULAR_FILE_FILE_MATCHER.reference_assertion)),
                    MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
            Case(
                'with matcher on dir',
                fc_args.FilesCondition([
                    fc_args.FileCondition(name_of_regular_file),
                    fc_args.FileCondition(
                        name_of_dir,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_DIR_FILE_MATCHER.name)),
                ]),
                arrangement,
                Expectation(
                    ParseExpectation(
                        symbol_references=asrt.matches_singleton_sequence(
                            IS_DIR_FILE_MATCHER.reference_assertion)),
                    MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
            Case(
                'with matcher on both files',
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        name_of_regular_file,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_REGULAR_FILE_FILE_MATCHER.name)),
                    fc_args.FileCondition(
                        name_of_dir,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_DIR_FILE_MATCHER.name)),
                ]),
                arrangement,
                Expectation(
                    ParseExpectation(symbol_references=asrt.matches_sequence([
                        IS_REGULAR_FILE_FILE_MATCHER.reference_assertion,
                        IS_DIR_FILE_MATCHER.reference_assertion,
                    ])),
                    MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_non_full_and_full(
                    self,
                    case.files_condition,
                    model_constructor__non_recursive(checked_dir.path_sdv),
                    case.arrangement,
                    case.expectation,
                )
    def test_single_file(self):
        # ARRANGE #
        name_of_file_in_model = 'file-in-model'
        name_of_file_not_in_model = 'file-not-in-model'

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP,
                                        'dir-w-single-file')

        cases = [
            Case(
                'no file matcher - different names',
                fc_args.FilesCondition([
                    fc_args.FileCondition(name_of_file_not_in_model),
                ]),
                Arrangement(
                    IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS,
                    checked_dir.tcds_arrangement_dir_with_contents(
                        [File.empty(name_of_file_in_model)])),
                Expectation(
                    ParseExpectation(symbol_references=asrt.is_empty_sequence),
                    NON_MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
            Case(
                'same names - non-matching matcher/actual is dir',
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        name_of_file_in_model,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_REGULAR_FILE_FILE_MATCHER.name)),
                ]),
                Arrangement(
                    IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS,
                    checked_dir.tcds_arrangement_dir_with_contents(
                        [Dir.empty(name_of_file_in_model)])),
                Expectation(
                    ParseExpectation(
                        symbol_references=asrt.matches_singleton_sequence(
                            IS_REGULAR_FILE_FILE_MATCHER.reference_assertion)),
                    NON_MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
            Case(
                'same names - non-matching matcher/actual is regular file',
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        name_of_file_in_model,
                        fm_args.SymbolReferenceWReferenceSyntax(
                            IS_DIR_FILE_MATCHER.name)),
                ]),
                Arrangement(
                    IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS,
                    checked_dir.tcds_arrangement_dir_with_contents(
                        [File.empty(name_of_file_in_model)])),
                Expectation(
                    ParseExpectation(
                        symbol_references=asrt.matches_singleton_sequence(
                            IS_DIR_FILE_MATCHER.reference_assertion)),
                    NON_MATCHING_EXECUTION_EXPECTATION,
                ),
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_non_full_and_full(
                    self,
                    case.files_condition,
                    model_constructor__non_recursive(checked_dir.path_sdv),
                    case.arrangement,
                    case.expectation,
                )
示例#27
0
    def runTest(self):
        # ARRANGE #
        positive_expectation = expectation_type_config__non_is_success(
            ExpectationType.POSITIVE)
        rel_opt_conf = rel_opt_confs.conf_rel_sds(RelSdsOptionType.REL_TMP)
        parser = sut.parsers().full

        # dir contents

        checked_dir = Dir('checked-dir', [
            File.empty('a.x'),
            File.empty('a.y'),
            File.empty('b.x'),
            File.empty('b.y'),
        ])

        # arguments

        file_matcher_arg__begins_with_a = fm_args.file_matcher_arguments(
            name_pattern='a*')

        file_matcher_arg__ends_with_x = fm_args.file_matcher_arguments(
            name_pattern='*.x')

        files_matcher_args__num_files_eq_1 = fsm_args.NumFilesAssertionVariant(
            int_args.int_condition(comparators.EQ, 1))

        files_matcher_args__num_files_ending_with_x_eq_1 = fsm_args.SelectionAndMatcherArgumentsConstructor(
            file_matcher_arg__ends_with_x,
            files_matcher_args__num_files_eq_1,
        )

        files_matcher_source__num_files_ending_with_x_eq_1 = files_matcher_args__num_files_ending_with_x_eq_1.apply(
            positive_expectation)

        symbol_name = 'FILES_MATCHER_SYMBOL'

        files_matcher_args__begins_with_a__symbol = fsm_args.SelectionAndMatcherArgumentsConstructor(
            file_matcher_arg__begins_with_a,
            fsm_args.symbol_reference(symbol_name),
        )
        files_matcher_source__begins_with_a__symbol = files_matcher_args__begins_with_a__symbol.apply(
            positive_expectation)

        num_files_ending_with_x_eq_1_resolver = parser.parse(
            remaining_source(
                files_matcher_source__num_files_ending_with_x_eq_1))

        symbols = FilesMatcherSymbolContext.of_sdv(
            symbol_name,
            num_files_ending_with_x_eq_1_resolver,
        ).symbol_table

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check(
            self,
            remaining_source(files_matcher_source__begins_with_a__symbol),
            model.model_with_source_path_as_sub_dir_of_rel_root(
                checked_dir.name)(rel_opt_conf),
            arrangement_w_tcds(
                non_hds_contents=rel_opt_conf.
                populator_for_relativity_option_root__sds(
                    DirContents([checked_dir])),
                symbols=symbols,
            ),
            Expectation(
                ParseExpectation(symbol_references=asrt.matches_sequence(
                    [is_reference_to_files_matcher(symbol_name)]), ),
                ExecutionExpectation(
                    main_result=matcher_assertions.is_matching_success(), ),
            ))
示例#28
0
 def expectation(self) -> Expectation:
     return Expectation(
         ParseExpectation(symbol_references=asrt.matches_singleton_sequence(
             is_reference_to_files_matcher(self.files_matcher_name)), ),
         ExecutionExpectation(is_hard_error=asrt_matcher.is_hard_error(
             asrt.equals(self.error_message))))
    def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
        # ARRANGE #
        string_to_prepend = '.'

        initial_model_contents = '\n'

        model_after_2_transformations = ''.join(
            [string_to_prepend, string_to_prepend, initial_model_contents])

        initial_model = model_constructor.of_str(self, initial_model_contents)

        equals_expected_matcher = StringMatcherSymbolContext.of_primitive(
            'EQUALS_EXPECTED',
            EqualsMatcherTestImpl(model_after_2_transformations))

        prepend_transformer_symbol = StringTransformerSymbolContext.of_primitive(
            'PREPEND_TRANSFORMER',
            string_transformers.of_line_transformer__w_preserved_line_ending(
                'prepend to each line', lambda line:
                (line + string_to_prepend)))

        prepend_trans_arg = str_trans_syntax.syntax_for_transformer_option(
            prepend_transformer_symbol.name)

        trans_and_eq_expected_matcher_source = remaining_source(
            '{prepend_trans_arg} {equals_expected_matcher}'.format(
                prepend_trans_arg=prepend_trans_arg,
                equals_expected_matcher=equals_expected_matcher.name,
            ))

        # ACT & ASSERT #

        parser = sut.parsers().full
        prepend_and_equals_expected_matcher_sdv = parser.parse(
            trans_and_eq_expected_matcher_source)

        prepend_and_equals_expected_matcher = StringMatcherSymbolContext.of_sdv(
            'PREPEND_AND_EQUALS_EXPECTED',
            prepend_and_equals_expected_matcher_sdv)

        symbols = SymbolContext.symbol_table_of_contexts([
            equals_expected_matcher,
            prepend_transformer_symbol,
            prepend_and_equals_expected_matcher,
        ])
        expected_symbol_references = asrt.matches_sequence([
            is_reference_to_string_transformer(
                prepend_transformer_symbol.name),
            is_reference_to_string_matcher(
                prepend_and_equals_expected_matcher.name),
        ])

        self._check_with_source_variants(
            test_configuration.arguments_for(
                args(
                    '{prepend_trans_arg} {maybe_not} {prepend_and_equals_expected_matcher}',
                    prepend_trans_arg=prepend_trans_arg,
                    maybe_not=maybe_not.
                    nothing__if_positive__not_option__if_negative,
                    prepend_and_equals_expected_matcher=
                    prepend_and_equals_expected_matcher.name)), initial_model,
            arrangement_w_tcds(symbols=symbols),
            Expectation(
                ParseExpectation(
                    symbol_references=expected_symbol_references, ),
                ExecutionExpectation(
                    main_result=maybe_not.pass__if_positive__fail__if_negative,
                ),
            ))
示例#30
0
    def test__exists__SHOULD_consider_only_files_matched_by_the_file_matcher(self):
        # ARRANGE #
        name_of_checked_dir = 'name-of-checked-dir'

        name_starts_with_selected = FileMatcherSymbolContext.of_primitive(
            'a_file_matcher_symbol',
            FileMatcherThatMatchesAnyFileWhosNameStartsWith('selected'))

        files_in_checked_dir = Dir(name_of_checked_dir, [
            File(
                'selected-non-empty-file.txt', 'contents of non-emtpy file'),
            File.empty('un-selected-empty-file.txt'),
            Dir.empty('un-selected-dir'),
            sym_link(
                'un-selected-sym-link-to-dir', 'un-selected-dir'),
            sym_link(
                'un-selected-broken-sym-link', 'non-existing-file'),
        ])

        symbol_table_with_file_matcher = name_starts_with_selected.symbol_table
        relativity_root_conf = AN_ACCEPTED_SDS_REL_OPT_CONFIG

        expected_symbol_references = asrt.matches_sequence([
            is_reference_to_file_matcher(name_starts_with_selected.name)
        ])

        # ACT & ASSERT #

        for file_is_empty_assertion in self.file_content_assertion_variants_that_pass_iff_file_is_empty:
            arguments_constructor = args.complete_arguments_constructor(
                FileQuantificationAssertionVariant(
                    Quantifier.EXISTS,
                    file_contents_arg2(file_is_empty_assertion)),
                file_matcher=name_starts_with_selected.name
            )
            for expectation_type in ExpectationType:
                etc = expectation_type_config__non_is_success(expectation_type)
                arguments = arguments_constructor.apply(etc)
                with self.subTest(
                        expectation_type=expectation_type.name,
                        arguments=arguments):
                    integration_check.CHECKER__PARSE_FULL.check(
                        self,
                        remaining_source(arguments),
                        model.model_with_source_path_as_sub_dir_of_rel_root(name_of_checked_dir)(relativity_root_conf),
                        arrangement=
                        arrangement_w_tcds(
                            tcds_contents=relativity_root_conf.populator_for_relativity_option_root(
                                DirContents([
                                    files_in_checked_dir,
                                ])
                            ),
                            symbols=symbol_table_with_file_matcher
                        ),
                        expectation=
                        Expectation(
                            ParseExpectation(
                                symbol_references=expected_symbol_references
                            ),
                            ExecutionExpectation(
                                main_result=etc.fail__if_positive__pass_if_negative,
                            ),
                        )
                    )