def runTest(self):
        failure_message = 'failure'
        failing_validation_result = asrt_validation.new_single_string_text_for_test(
            failure_message)
        line_matcher_symbol_name = 'line_matcher_with_failing_validation'

        asserted_symbol_references = asrt.matches_sequence(
            [is_reference_to_line_matcher(line_matcher_symbol_name)])

        validation_cases = [
            NEA('failure pre sds',
                expected=Expectation(
                    ParseExpectation(
                        symbol_references=asserted_symbol_references, ),
                    ExecutionExpectation(
                        validation=ValidationAssertions.pre_sds_fails(
                            asrt.equals(failure_message)), ),
                ),
                actual=ConstantDdvValidator(
                    pre_sds_result=failing_validation_result)),
            NEA('failure post sds',
                expected=Expectation(
                    ParseExpectation(
                        symbol_references=asserted_symbol_references, ),
                    ExecutionExpectation(validation=ValidationAssertions.
                                         post_sds_fails__w_any_msg(), ),
                ),
                actual=ConstantDdvValidator(
                    post_sds_result=failing_validation_result)),
        ]
        for case in validation_cases:

            symbols = LineMatcherSymbolContext.of_sdv(
                line_matcher_symbol_name,
                successful_matcher_with_validation(case.actual)).symbol_table
            for quantifier in Quantifier:

                arguments_constructor = arguments_building.ImplicitActualFileArgumentsConstructor(
                    CommonArgumentsConstructor(),
                    arguments_building.
                    LineMatchesAssertionArgumentsConstructor(
                        quantifier, line_matcher_symbol_name))
                for expectation_type in ExpectationType:
                    arguments = arguments_constructor.apply(expectation_type)
                    source = test_configuration.arguments_for(
                        arguments).as_remaining_source
                    with self.subTest(case=case.name,
                                      expectation_type=expectation_type,
                                      quantifier=quantifier):
                        self._check(source=source,
                                    model=model_constructor.arbitrary(self),
                                    arrangement=Arrangement(symbols=symbols),
                                    expectation=case.expected)
Beispiel #2
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,
            )
        )
    def runTest(self):
        # ARRANGE #
        model = model_constructor.of_str(self, 'string with at least one line')

        line_matcher = LineMatcherSymbolContextOfPrimitiveConstant(
            'MATCHER',
            True,
        )
        after_bin_op = 'after bin op'
        lm_argument = lm_args.And([
            lm_args.SymbolReference(line_matcher.name),
            lm_args.Custom(after_bin_op),
        ])
        for quantifier in Quantifier:
            arguments = args2.Quantification(quantifier, lm_argument.as_str)
            with self.subTest(quantifier):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_SIMPLE.check(
                    self,
                    source=arguments.as_remaining_source,
                    input_=model,
                    arrangement=arrangement_w_tcds(
                        symbols=line_matcher.symbol_table, ),
                    expectation=Expectation(
                        ParseExpectation(source=asrt_source.is_at_line(
                            current_line_number=1,
                            remaining_part_of_current_line=lm_argument.
                            operator_name + ' ' + after_bin_op),
                                         symbol_references=line_matcher.
                                         references_assertion),
                        ExecutionExpectation(
                            main_result=asrt_matching_result.matches_value(
                                line_matcher.result_value))),
                )
Beispiel #4
0
    def test_stdin_is_devnull_WHEN_program_do_not_define_stdin(self):
        # ARRANGE #
        test_setup = NoStdinTestSetup(self, exit_code=0)

        for output_file in ProcOutputFile:
            for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
            ):
                for ignore_exit_code in [False, True]:
                    with self.subTest(output_file=output_file,
                                      program=pgm_and_args_case.name,
                                      ignore_exit_code=ignore_exit_code):
                        # ACT & ASSERT #
                        CHECKER.check__abs_stx__wo_input(
                            self,
                            StringSourceOfProgramAbsStx(
                                output_file,
                                pgm_and_args_case.pgm_and_args,
                                ignore_exit_code,
                            ),
                            arrangement_w_tcds(
                                symbols=pgm_and_args_case.symbol_table,
                                process_execution=test_setup.
                                proc_exe_env__w_stdin_check,
                                tcds_contents=pgm_and_args_case.tcds,
                            ),
                            Expectation.of_prim__const(
                                parse=ParseExpectation(
                                    symbol_references=pgm_and_args_case.
                                    references_assertion, ),
                                primitive=IS_EMPTY_STRING_SOURCE,
                            ))
Beispiel #5
0
 def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
     regex_lines = ['1.3',
                    '4.*6']
     here_doc_of_reg_ex = here_document_as_elements(regex_lines)
     actual_contents = lines_content(['123',
                                      '456',
                                      '789'])
     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,
                                                   FULL_MATCH_ARGUMENT]
                                                  ).followed_by(here_doc_of_reg_ex)
             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_of_reg_ex.following_lines))
                     ),
                     ExecutionExpectation(
                         main_result=maybe_not.fail__if_positive__pass_if_negative
                     ),
                 ),
             )
 def test_validation_should_fail_pre_sds_when_regex_is_invalid(self):
     for regex_case in failing_regex_validation_cases():
         arguments = self.conf.arguments(NameRegexVariant.of(regex_case.regex_string))
         for expectation_type in ExpectationType:
             with self.subTest(expectation_type=expectation_type,
                               validation_case=regex_case.case_name):
                 integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                     self,
                     arguments=
                     arguments.as_arguments,
                     input_=
                     ARBITRARY_MODEL,
                     arrangement=
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(regex_case.symbols)
                     ),
                     expectation=
                     Expectation(
                         ParseExpectation(
                             symbol_references=asrt.matches_sequence(regex_case.reference_assertions),
                         ),
                         ExecutionExpectation(
                             validation=regex_case.expectation
                         ),
                     )
                 )
Beispiel #7
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 #8
0
    def _check(
        self,
        arguments: ArgumentElements,
        expected_result: bool,
        all_symbols: Sequence[NameAndValue[MatcherWTrace[MODEL]]],
        expected_trace: tree.Node[bool],
    ):
        conf = self.configuration
        helper = self._asrt_helper

        conf.checker_for_parser_of_full_expr().check__w_source_variants(
            self,
            arguments.as_arguments,
            conf.arbitrary_model,
            Arrangement(symbols=SymbolContext.symbol_table_of_contexts([
                conf.mk_logic_type_context_of_primitive(sym.name, sym.value)
                for sym in all_symbols
            ]), ),
            Expectation(
                ParseExpectation(symbol_references=helper.is_sym_refs_to(
                    [sym.name for sym in all_symbols]), ),
                ExecutionExpectation(main_result=asrt_matching_result.matches(
                    value=asrt.equals(expected_result),
                    trace=trace_equals(expected_trace)))),
        )
Beispiel #9
0
    def runTest(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check(
            self,
            source=fsm_args.Prune(
                fm_args.Type(FileType.SYMLINK),
                helper.files_matcher_sym_ref_arg(),
            ).as_remaining_source,
            input_=helper.model_constructor_for_checked_dir__recursive(),
            arrangement=helper.arrangement_for_contents_of_model(
                checked_dir_contents=PRUNE_TYPE_SYM_LINK.actual,
                files_matcher_symbol_value=model_checker.matcher(
                    self,
                    helper.dir_arg.path_sdv,
                    PRUNE_TYPE_SYM_LINK.expected,
                ),
            ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=helper.symbol_references_expectation(),
                ),
                EXECUTION_IS_PASS,
            ),
        )
Beispiel #10
0
    def runTest(self):
        # ARRANGE #
        for case in validation_cases.failing_validation_cases():
            line_matcher_symbol_context = case.value.symbol_context
            line_matcher_arg = lm_args.SymbolReference(line_matcher_symbol_context.name)

            arguments = st_args.syntax_for_filter_transformer(str(line_matcher_arg))

            with self.subTest(case.name):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                    self,
                    Arguments(arguments),
                    model_constructor.of_lines(self, []),
                    arrangement_wo_tcds(
                        symbols=line_matcher_symbol_context.symbol_table
                    ),
                    Expectation(
                        ParseExpectation(
                            symbol_references=line_matcher_symbol_context.references_assertion
                        ),
                        ExecutionExpectation(
                            validation=case.value.expectation,
                        )
                    )
                )
Beispiel #11
0
    def runTest(self):
        # ARRANGE #

        name_of_referenced_symbol = 'FILE_MATCHER_WITH_VALIDATION_FAILURE'

        selection_is_empty_arguments = fsm_args.Selection(
            fm_args2.SymbolReference(name_of_referenced_symbol), args.Empty())

        for case in validation_cases.failing_validation_cases(
                name_of_referenced_symbol):
            symbol_context = case.value.symbol_context

            selection_is_empty_source = selection_is_empty_arguments.as_remaining_source

            # ACT & ASSERT #
            with self.subTest(case.name):
                integration_check.CHECKER__PARSE_FULL.check(
                    self,
                    selection_is_empty_source,
                    model.arbitrary_model(),
                    arrangement_w_tcds(symbols=symbol_context.symbol_table, ),
                    Expectation(
                        ParseExpectation(symbol_references=symbol_context.
                                         references_assertion, ),
                        ExecutionExpectation(
                            validation=case.value.expectation, ),
                    ),
                )
    def _check_(
        self,
        instruction_source: ParseSource,
        model: ModelConstructor,
        etc: ExpectationTypeConfigForNoneIsSuccess,
        main_result_for_positive_expectation: PassOrFail,
        root_dir_of_dir_contents: RelativityOptionConfiguration,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        test_case_name: str = '',
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        with self.put.subTest(case_name=test_case_name,
                              expectation_type=etc.expectation_type.name,
                              arguments=instruction_source.source_string):
            integration_check.CHECKER__PARSE_FULL.check(
                self.put, instruction_source, model,
                arrangement_w_tcds(
                    pre_population_action=MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                    tcds_contents=root_dir_of_dir_contents.
                    populator_for_relativity_option_root(
                        contents_of_relativity_option_root),
                    symbols=_symbol_table_of(root_dir_of_dir_contents.symbols,
                                             following_symbols_setup),
                ),
                Expectation(
                    ParseExpectation(symbol_references=following_symbols_setup.
                                     expected_references_assertion, ),
                    ExecutionExpectation(main_result=etc.main_result(
                        main_result_for_positive_expectation), ),
                ))
Beispiel #13
0
    def test_stdin_contains_model_contents_WHEN_program_do_not_define_stdin(
            self):
        # ARRANGE #
        test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0)

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            with self.subTest(pgm_and_args_case.name):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_FULL.check__abs_stx(
                    self, RunProgramAbsStx(pgm_and_args_case.pgm_and_args, ),
                    model_constructor.of_str(
                        self, test_setup.STRING_SOURCE_CONTENTS),
                    arrangement_w_tcds(
                        symbols=pgm_and_args_case.symbol_table,
                        process_execution=test_setup.
                        proc_exe_env__w_stdin_check,
                        tcds_contents=pgm_and_args_case.tcds,
                    ),
                    Expectation(
                        ParseExpectation(symbol_references=pgm_and_args_case.
                                         references_assertion, ),
                        execution=EXECUTION_OUTPUT_IS_EMPTY,
                        primitive=PRIMITIVE_IS_NOT_IDENTITY_TRANSFORMATION,
                    ))
Beispiel #14
0
    def _check_variants_with_expectation_type(
            self,
            args_variant_constructor: InstructionArgumentsVariantConstructor,
            expected_result_of_positive_test: PassOrFail,
            actual_file_contents: str,
            symbols: SymbolTable = None,
            expected_symbol_references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence):
        for expectation_type in ExpectationType:
            etc = expectation_type_config__non_is_success(expectation_type)
            with self.subTest(expectation_type=expectation_type):

                args_variant = args_variant_constructor.construct(expectation_type)
                complete_instruction_arguments = test_configuration.arguments_for(args_variant)

                for source in equivalent_source_variants__for_expression_parser(
                        self,
                        complete_instruction_arguments):
                    integration_check.CHECKER__PARSE_FULL.check(
                        self,
                        source,
                        model_constructor.of_str(self, actual_file_contents),
                        Arrangement(
                            tcds=TcdsArrangement(
                                post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY
                            ),
                            symbols=symbols),
                        Expectation(
                            ParseExpectation(
                                symbol_references=expected_symbol_references,
                            ),
                            ExecutionExpectation(
                                main_result=etc.main_result(expected_result_of_positive_test),
                            ),
                        )
                    )
Beispiel #15
0
    def test_access_of_sub_dir_for_failure_message_rendering(self):
        # ARRANGE #
        root_1__file = File.empty('f-1')
        root_2__dir = Dir('d-2', [])

        arguments = args.matches_full(
            fc_args.FilesCondition([fc_args.FileCondition(root_1__file.name)])
        )

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'checked-dir')

        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            arguments.as_arguments,
            input_=model_constructor__recursive(checked_dir.path_sdv),
            arrangement=Arrangement(
                tcds=checked_dir.tcds_arrangement_dir_with_contents([
                    root_1__file,
                    root_2__dir,
                ])
            ),
            expectation=Expectation(
                parse=ParseExpectation(
                    symbol_references=asrt.is_empty_sequence,
                ),
                execution=PRIM_AND_EXE_EXPECTATION__NON_MATCH.execution,
                primitive=PRIM_AND_EXE_EXPECTATION__NON_MATCH.primitive,
            ),
        )
Beispiel #16
0
 def _check(self,
            expected_contents: str,
            actual_contents: str,
            may_depend_on_external_resources: bool,
            expected_result: bool,
            ):
     string_source_symbol_with_expected = StringSourceSymbolContext.of_primitive_constant(
         'EXPECTED_CONTENTS_SYMBOL',
         expected_contents,
     )
     integration_check.CHECKER__PARSE_SIMPLE.check(
         self,
         args2.Equals.eq_string(
             string_source_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_source_symbol_with_expected.symbol_table
         ),
         Expectation(
             ParseExpectation(
                 symbol_references=string_source_symbol_with_expected.references_assertion,
             ),
             execution=ExecutionExpectation(
                 main_result=asrt_matching_result.matches_value(
                     expected_result
                 )
             ),
         ),
     )
Beispiel #17
0
    def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
        expected_content_line_template = 'expected content line, with {symbol} ref'

        def expected_content(symbol_content: str) -> str:
            return expected_content_line_template.format(symbol=symbol_content)

        symbol = StringConstantSymbolContext('symbol_name', 'the symbol value')
        self._check(
            test_configuration.source_for(
                args('{maybe_not} {equals} <<EOF',
                     maybe_not=maybe_not.nothing__if_positive__not_option__if_negative),
                [expected_content(symbol.name__sym_ref_syntax),
                 'EOF',
                 'following line']),
            model_constructor.of_str(self, lines_content([expected_content(symbol.str_value)])),
            arrangement_w_tcds(
                post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                symbols=symbol.symbol_table),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(3),
                    symbol_references=asrt.matches_sequence([
                        symbol.reference_assertion__w_str_rendering
                    ]),
                ),
                ExecutionExpectation(
                    main_result=maybe_not.pass__if_positive__fail__if_negative,
                ),
            ),
        )
Beispiel #18
0
    def runTest(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check(
            self,
            source=fsm_args.Prune(
                matcher_argument.Constant(False),
                helper.files_matcher_sym_ref_arg(),
            ).as_remaining_source,
            input_=helper.model_constructor_for_checked_dir__recursive(),
            arrangement=helper.arrangement_for_contents_of_model(
                checked_dir_contents=
                BROKEN_SYM_LINKS_SHOULD_BE_TREATED_AS_NON_DIR_FILES.actual,
                files_matcher_symbol_value=model_checker.matcher(
                    self,
                    helper.dir_arg.path_sdv,
                    BROKEN_SYM_LINKS_SHOULD_BE_TREATED_AS_NON_DIR_FILES.
                    expected,
                ),
            ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=helper.symbol_references_expectation(),
                ),
                EXECUTION_IS_PASS,
            ),
        )
    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())),
        )
Beispiel #20
0
    def runTest(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        arguments = fsm_args.Prune(
            fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
            helper.files_matcher_sym_ref_arg(),
        ).as_arguments

        # ACT & ASSERT #

        for depth, nie in COMBINATION_OF_PRUNE_AND_DEPTH_LIMITATIONS:
            with self.subTest(data=nie.name, depth=depth):
                integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
                    self,
                    arguments=arguments,
                    input_=helper.model_constructor_for_checked_dir__recursive(
                        min_depth=depth, max_depth=depth),
                    arrangement=helper.arrangement_for_contents_of_model(
                        checked_dir_contents=nie.actual,
                        files_matcher_symbol_value=model_checker.matcher(
                            self,
                            helper.dir_arg.path_sdv,
                            nie.expected,
                        ),
                        additional_symbols=[NAME_STARTS_WITH__P1],
                    ),
                    expectation=Expectation(
                        ParseExpectation(
                            symbol_references=asrt.matches_sequence([
                                NAME_STARTS_WITH__P1.reference_assertion,
                                helper.symbol_reference_assertion,
                            ]), )),
                )
Beispiel #21
0
    def test_stdin_is_devnull_WHEN_program_do_not_define_stdin(self):
        # ARRANGE #
        test_setup = NoStdinTestSetup(self, exit_code=0)

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference():
            with self.subTest(pgm_and_args_case.name):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_FULL.check__abs_stx(
                    self,
                    abstract_syntaxes.RunProgramAbsStx(
                        pgm_and_args_case.pgm_and_args,
                        abstract_syntaxes.PathArgumentPositionLast()
                    ),
                    integration_check.ARBITRARY_MODEL,
                    arrangement_w_tcds(
                        symbols=pgm_and_args_case.symbol_table,
                        process_execution=test_setup.proc_exe_env__w_stdin_check,
                        tcds_contents=pgm_and_args_case.tcds,
                    ),
                    Expectation(
                        ParseExpectation(
                            symbol_references=pgm_and_args_case.references_assertion,
                        ),
                        execution=ExecutionExpectation(
                            main_result=asrt_matching_result.matches_value(True)
                        ),
                    )
                )
Beispiel #22
0
    def runTest(self):
        # ARRANGE #
        helper = IntegrationCheckHelper()

        actual_contents = [
            Dir('P1-matches', [
                File.empty('file-in-pruned-dir'),
            ])
        ]

        arguments = conjunction([
            Parentheses(
                fsm_args.Prune(
                    fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
                    fsm_args.NumFiles(int_condition(comparators.EQ, 1)))),
            fsm_args.NumFiles(int_condition(comparators.EQ, 2)),
        ])

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            arguments=arguments.as_arguments,
            input_=helper.model_constructor_for_checked_dir__recursive(),
            arrangement=Arrangement(
                symbols=NAME_STARTS_WITH__P1.symbol_table,
                tcds=helper.dir_arg.tcds_arrangement_dir_with_contents(
                    actual_contents)),
            expectation=Expectation(
                ParseExpectation(symbol_references=asrt.matches_sequence([
                    NAME_STARTS_WITH__P1.reference_assertion,
                ])),
                EXECUTION_IS_PASS,
            ))
    def test_glob_pattern(self):
        match_anything_glob_pattern_string_symbol = StringSymbolContext.of_constant(
            'glob_pattern_symbol',
            '*',
            default_restrictions=glob_pattern.is_reference_restrictions__glob_pattern_string()
        )
        arguments = self.conf.arguments(
            NameGlobPatternVariant(match_anything_glob_pattern_string_symbol.name__sym_ref_syntax)
        )

        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
            self,
            arguments=
            arguments.as_arguments,
            input_=
            ARBITRARY_MODEL,
            arrangement=arrangement_wo_tcds(
                symbols=match_anything_glob_pattern_string_symbol.symbol_table
            ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=asrt.matches_sequence([
                        match_anything_glob_pattern_string_symbol.reference_assertion,
                    ]),
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value__w_header(
                        asrt.equals(True),
                        asrt.equals(self.conf.node_name)
                    )
                ),
            )
        )
Beispiel #24
0
    def test(self):
        symbol_name = 'the_string_matcher'
        for quantifier in Quantifier:
            arguments = args.Quantification(
                quantifier,
                fm_args.SymbolReference(symbol_name))

            for case in validation_cases.failing_validation_cases(symbol_name):
                symbol_context = case.value.symbol_context

                with self.subTest(quantifier=quantifier,
                                  validation_case=case.name):
                    integration_check.CHECKER__PARSE_FULL.check(
                        self,
                        source=remaining_source(str(arguments)),
                        input_=arbitrary_model(),
                        arrangement=
                        Arrangement(
                            symbols=symbol_context.symbol_table
                        ),
                        expectation=
                        Expectation(
                            ParseExpectation(
                                symbol_references=symbol_context.references_assertion,
                            ),
                            ExecutionExpectation(
                                validation=case.value.expectation,
                            ),
                        ),
                    )
Beispiel #25
0
 def runTest(self):
     # ARRANGE #
     model_contents = 'the contents of stdin of program'
     stdin_string_source_syntax = string_source_abs_stx.StringSourceOfStringAbsStx.of_str_hard(
         model_contents, )
     for output_file in ProcOutputFile:
         for ignore_exit_code in [False, True]:
             with self.subTest(output_file=output_file,
                               ignore_exit_code=ignore_exit_code):
                 test_setup = StdinCheckViaCopyToOutputFileTestSetup(
                     output_file)
                 # ACT & ASSERT #
                 CHECKER.check__abs_stx__wo_input(
                     self,
                     StringSourceOfProgramAbsStx(
                         output_file,
                         FullProgramAbsStx(
                             test_setup.program_that_copies_stdin_syntax(),
                             stdin=stdin_string_source_syntax),
                         ignore_exit_code,
                     ),
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(
                             test_setup.symbols), ),
                     Expectation.of_prim__const(
                         parse=ParseExpectation(
                             symbol_references=SymbolContext.
                             references_assertion_of_contexts(
                                 test_setup.symbols)),
                         primitive=asrt_string_source.
                         pre_post_freeze__identical(
                             asrt_contents.matches__str(
                                 asrt.equals(model_contents))),
                     ),
                 )
Beispiel #26
0
    def test_result_SHOULD_be_true_iff_exit_code_is_0(self):
        # ARRANGE #
        program_symbol_name = 'PROGRAM_THAT_EXECUTES_PY_FILE'
        exit_code_symbol_name = 'EXIT_CODE_SYMBOL'

        # ACT && ASSERT #

        integration_check.CHECKER__PARSE_FULL.check_multi(
            self,
            args.RunProgram(
                program_args.symbol_ref_command_elements(
                    program_symbol_name,
                    arguments=[
                        symbol_reference_syntax_for_name(exit_code_symbol_name)
                    ],
                )).as_arguments,
            ParseExpectation(
                source=asrt_source.is_at_end_of_line(1),
                symbol_references=asrt.matches_sequence([
                    is_reference_to_program(program_symbol_name),
                    is_reference_to__w_str_rendering(exit_code_symbol_name),
                ]),
            ),
            integration_check.ARBITRARY_MODEL,
            test_cases.exit_code_exe_cases(
                program_symbol_name,
                exit_code_symbol_name,
            ),
        )
Beispiel #27
0
 def runTest(self):
     # ARRANGE #
     files_matcher = FilesMatcherSymbolContextOfPrimitiveConstant(
         'MATCHER',
         True,
     )
     after_bin_op = 'after bin op'
     # ACT & ASSERT #
     fsm_argument = fsm_args.conjunction([
         fsm_args.SymbolReference(files_matcher.name),
         fsm_args.Custom(after_bin_op),
     ])
     integration_check.CHECKER__PARSE_SIMPLE.check(
         self,
         source=args.DirContents(fsm_argument, ).as_remaining_source,
         input_=integration_check.current_directory(),
         arrangement=arrangement_w_tcds(
             symbols=files_matcher.symbol_table, ),
         expectation=Expectation(
             ParseExpectation(
                 source=asrt_source.is_at_line(
                     current_line_number=1,
                     remaining_part_of_current_line=fsm_argument.operator +
                     ' ' + after_bin_op),
                 symbol_references=files_matcher.references_assertion),
             ExecutionExpectation(
                 main_result=asrt_matching_result.matches_value(
                     files_matcher.result_value))),
     )
    def runTest(self):
        lines = ['1', '2', '3']
        actual_number_of_lines = len(lines)

        integer_matcher = IntegerMatcherSymbolContext.of_primitive(
            'INTEGER_MATCHER',
            matchers.matcher(
                comparators.EQ,
                actual_number_of_lines,
            ))
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            args.NumLines(
                integer_matcher.name__sym_ref_syntax).as_remaining_source,
            model_constructor.of_str(self, lines_content(lines)),
            arrangement_w_tcds(symbols=integer_matcher.symbol_table, ),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(1),
                    symbol_references=integer_matcher.references_assertion,
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True)),
            ),
        )
 def runTest(self):
     after_lhs_expression = logic.AND_OPERATOR_NAME + ' after bin op'
     integer_matcher = IntegerMatcherSymbolContextOfPrimitiveConstant(
         'MATCHER_SYMBOL',
         True,
     )
     complex_expression = ' '.join(
         (integer_matcher.name__sym_ref_syntax, after_lhs_expression))
     integration_check.CHECKER__PARSE_SIMPLE.check(
         self,
         args.NumLines(complex_expression).as_remaining_source,
         model_constructor.arbitrary(self),
         arrangement_w_tcds(symbols=integer_matcher.symbol_table, ),
         Expectation(
             ParseExpectation(
                 source=asrt_source.is_at_line(
                     current_line_number=1,
                     remaining_part_of_current_line=after_lhs_expression,
                 ),
                 symbol_references=integer_matcher.references_assertion,
             ),
             ExecutionExpectation(
                 main_result=asrt_matching_result.matches_value(
                     integer_matcher.result_value)),
         ),
     )
Beispiel #30
0
    def test_file_matcher_SHOULD_be_parsed_as_full_expression(self):
        # ARRANGE #
        file_name = 'file-name'
        fm_1 = FileMatcherSymbolContextOfPrimitiveConstant(
            'file_matcher_1', False)
        fm_2 = FileMatcherSymbolContextOfPrimitiveConstant(
            'file_matcher_2', True)
        symbols = [fm_1, fm_2]

        arguments = args.FilesCondition([
            args.FileCondition(
                file_name, fm_args.disjunction([fm_1.argument, fm_2.argument]))
        ])
        expected_result = fm_1.result_value or fm_2.result_value
        # ACT & ASSERT #
        CHECKER.check__w_source_variants(
            self,
            arguments=arguments.as_arguments,
            input_=None,
            arrangement=arrangement_wo_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbols)),
            expectation=Expectation(
                ParseExpectation(symbol_references=SymbolContext.
                                 references_assertion_of_contexts(symbols)),
                primitive=prim_asrt__constant(
                    asrt_primitive.files_matches({
                        PurePosixPath(file_name):
                        asrt_primitive.is_matcher_that_gives(expected_result)
                    }))))