Example #1
0
    def test_multiple_prune_SHOULD_be_prune_dirs_matching_any_matcher(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        # ACT & ASSERT #

        _check_multi(
            self,
            helper,
            arguments=fsm_args.Prune(
                fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
                fsm_args.Prune(
                    fm_args.SymbolReference(NAME_STARTS_WITH__P2.name),
                    helper.files_matcher_sym_ref_arg(),
                ),
            ),
            symbols_common_to_all_cases=[
                NAME_STARTS_WITH__P1,
                NAME_STARTS_WITH__P2,
            ],
            symbol_references=asrt.matches_sequence([
                NAME_STARTS_WITH__P1.reference_assertion,
                NAME_STARTS_WITH__P2.reference_assertion,
                helper.symbol_reference_assertion,
            ]),
            execution_cases=MULTIPLE_PRUNE_CASES,
        )
Example #2
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)
            ])
Example #3
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,
                            ),
                        ),
                    )
Example #4
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,
            ))
Example #5
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,
                            ]), )),
                )
Example #6
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, ),
                    ),
                )
Example #7
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))
Example #8
0
    def runTest(self):
        # ARRANGE #

        path_symbol_name = 'the_path_symbol'
        file_matcher_symbol_name = 'the_file_matcher_symbol'

        expected_path_symbol_ref = asrt_sym_ref.symbol_usage_equals_data_type_symbol_reference(
            SymbolReference(path_symbol_name,
                            path_or_string_reference_restrictions(
                                EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS))
        )

        expected_file_matcher_ref = fm_references.is_reference_to_file_matcher(file_matcher_symbol_name)

        cases = [
            NEA('no symbols',
                asrt.matches_sequence([]),
                args.WithOptionalNegation(path_argument('plain-file-name'))
                ),
            NEA('path symbol',
                asrt.matches_sequence([
                    expected_path_symbol_ref,
                ]),
                args.WithOptionalNegation(symbol_path_argument(path_symbol_name))
                ),
            NEA('path symbol and file matcher symbol',
                asrt.matches_sequence([
                    expected_path_symbol_ref,
                    expected_file_matcher_ref,
                ]),
                args.WithOptionalNegation(symbol_path_argument(path_symbol_name),
                                          fm_args.SymbolReference(file_matcher_symbol_name))
                ),
        ]

        for case in cases:
            for expectation_type in ExpectationType:
                arguments = case.actual.get(expectation_type)
                source = remaining_source(str(arguments))
                with self.subTest(case=case.name,
                                  expectation_type=expectation_type):
                    # ACT #
                    instruction = sut.setup('the-instruction-name').parse(ARBITRARY_FS_LOCATION_INFO, source)
                    # ASSERT #
                    self.assertIsInstance(instruction, AssertPhaseInstruction)
                    case.expected.apply_without_message(self,
                                                        instruction.symbol_usages())
Example #9
0
    def runTest(self):
        # ARRANGE #
        checked_dir_rel_conf = relativity_options.conf_rel_any(RelOptionType.REL_ACT)
        checked_dir_populator = checked_dir_rel_conf.populator_for_relativity_option_root(
            DirContents([
                File.empty('a-file-so-that-checked-dir-is-not-empty')
            ]
            )
        )

        file_matcher = FileMatcherSymbolContextOfPrimitiveConstant(
            'MATCHER',
            True,
        )
        after_bin_op = 'after bin op'
        fm_argument = fm_args.conjunction([
            fm_args.SymbolReference(file_matcher.name),
            fm_args.Custom(after_bin_op),
        ])
        # ACT & ASSERT #
        for quantifier in Quantifier:
            arguments = args.Quantification(quantifier, fm_argument)
            with self.subTest(quantifier):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_SIMPLE.check(
                    self,
                    source=arguments.as_remaining_source,
                    input_=model.model_constructor__non_recursive(
                        path_sdvs.of_rel_option(checked_dir_rel_conf.relativity)
                    ),
                    arrangement=arrangement_w_tcds(
                        symbols=file_matcher.symbol_table,
                        tcds_contents=checked_dir_populator
                    ),
                    expectation=Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_line(
                                current_line_number=1,
                                remaining_part_of_current_line=fm_argument.operator + ' ' + after_bin_op),
                            symbol_references=file_matcher.references_assertion
                        ),
                        ExecutionExpectation(
                            main_result=asrt_matching_result.matches_value(file_matcher.result_value)
                        )
                    ),
                )
Example #10
0
    def test_single_prune(self):
        # ARRANGE #

        helper = IntegrationCheckHelper()

        # ACT & ASSERT #

        _check_multi(
            self,
            helper,
            arguments=fsm_args.Prune(
                fm_args.SymbolReference(NAME_STARTS_WITH__P1.name),
                helper.files_matcher_sym_ref_arg()),
            symbols_common_to_all_cases=[NAME_STARTS_WITH__P1],
            symbol_references=asrt.matches_sequence([
                NAME_STARTS_WITH__P1.reference_assertion,
                helper.symbol_reference_assertion,
            ]),
            execution_cases=SINGLE_PRUNE_CASES,
        )
Example #11
0
    def runTest(self):
        # ARRANGE #
        helper = IntegrationCheckHelper()

        test_fails_if_applied__matcher_symbol_context = test_fails_if_applied(
            self)

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

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check(
            self,
            source=arguments.as_remaining_source,
            input_=helper.model_constructor_for_checked_dir__non_recursive(),
            arrangement=helper.arrangement_for_contents_of_model(
                checked_dir_contents=NON_RECURSIVE__ACTUAL,
                files_matcher_symbol_value=model_checker.matcher(
                    self,
                    helper.dir_arg.path_sdv,
                    test_data.strip_file_type_info(
                        test_data.expected_is_actual_down_to_max_depth(
                            0, NON_RECURSIVE__ACTUAL).expected),
                ),
                additional_symbols=[
                    test_fails_if_applied__matcher_symbol_context
                ],
            ),
            expectation=Expectation(
                ParseExpectation(symbol_references=asrt.matches_sequence([
                    test_fails_if_applied__matcher_symbol_context.
                    reference_assertion,
                    helper.symbol_reference_assertion,
                ])),
                EXECUTION_IS_PASS,
            ))
Example #12
0
    def runTest(self):
        # ARRANGE #

        error_message = 'error message from file matcher'
        file_matcher_that_raises_hard_error = FileMatcherSymbolContext.of_primitive(
            'file_matcher_that_raises_hard_error',
            matchers.MatcherThatReportsHardError(error_message)
        )

        path_relativity = conf_rel_sds(RelSdsOptionType.REL_ACT)

        checked_file = File.empty('checked-file.txt')

        argument = args.CompleteInstructionArg(
            ExpectationType.POSITIVE,
            path_relativity.path_argument_of_rel_name(checked_file.name),
            fm_args.SymbolReference(file_matcher_that_raises_hard_error.name))

        # ACT & ASSERT #

        CHECKER.check(
            self,
            remaining_source(str(argument)),
            ArrangementPostAct(
                symbols=file_matcher_that_raises_hard_error.symbol_table,
                sds_contents=path_relativity.populator_for_relativity_option_root__sds(
                    DirContents([checked_file])
                )
            ),
            instruction_check.expectation(
                main_result=pfh_assertions.is_hard_error(
                    asrt_text_doc.rendered_text_matches(asrt_str.contains(error_message))
                ),
                symbol_usages=asrt.matches_sequence([
                    file_matcher_that_raises_hard_error.reference_assertion
                ])
            ))
Example #13
0
    def runTest(self):
        # ARRANGE #

        for failing_file_matcher_case in failing_validation_cases__svh():
            failing_symbol_context = failing_file_matcher_case.value.symbol_context

            argument = args.CompleteInstructionArg(
                ExpectationType.POSITIVE,
                path_argument('ignored-file'),
                fm_args.SymbolReference(failing_symbol_context.name))

            with self.subTest(failing_file_matcher_case.name):
                # ACT & ASSERT #

                CHECKER.check(
                    self,
                    remaining_source(str(argument)),
                    ArrangementPostAct(
                        symbols=failing_symbol_context.symbol_table,
                    ),
                    instruction_check.expectation(
                        validation=failing_file_matcher_case.value.expectation,
                        symbol_usages=failing_symbol_context.references_assertion
                    ))
Example #14
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, )),
                )