コード例 #1
0
ファイル: selections.py プロジェクト: emilkarlen/exactly
    def runTest(self):
        # ARRANGE #

        name_of_referenced_selector = 'SELECTOR'
        name_of_referenced_files_matcher = 'FILES_MATCHER'

        expected_symbol_usages = asrt.matches_sequence([
            is_reference_to_file_matcher(name_of_referenced_selector),
            is_reference_to_files_matcher(name_of_referenced_files_matcher),
        ])

        arguments = fsm_args.argument_constructor_for_symbol_reference(
            files_matcher_symbol_name=name_of_referenced_files_matcher,
            named_matcher=name_of_referenced_selector).apply(
                expectation_type_config__non_is_success(
                    ExpectationType.POSITIVE))

        source = remaining_source(arguments)

        # ACT #

        sdv = sut.parsers().full.parse(source)

        # ASSERT #

        expected_symbol_usages.apply_without_message(self, sdv.references)
コード例 #2
0
    def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: FilesMatcherArgumentsConstructor,
        model_constructor: ModelConstructorFromRelOptConf,
        default_relativity: RelOptionType,
        non_default_relativity: RelOptionType,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        rel_opt_configs = [
            rel_opt_conf.default_conf_rel_any(default_relativity),
            rel_opt_conf.conf_rel_any(non_default_relativity),
        ]

        for rel_opt_config in rel_opt_configs:
            for expectation_type_of_test_case in ExpectationType:
                etc = expectation_type_config__non_is_success(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(etc)

                for source in equivalent_source_variants__for_expression_parser(
                        self.put, Arguments(instruction_arguments)):
                    self._check_(
                        source,
                        model_constructor(rel_opt_config),
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
コード例 #3
0
ファイル: test_resources.py プロジェクト: emilkarlen/exactly
    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),
                            ),
                        )
                    )
コード例 #4
0
    def test_it_SHOULD_be_possible_to_create_multiple_intermediate_files(self):
        # ARRANGE #
        original_file_contents = 'original_file_contents'
        expected_transformer_contents = original_file_contents.upper()

        transform_to_uppercase = test_transformers_setup.TO_UPPER_CASE_TRANSFORMER

        symbol_table_with_lines_transformer = transform_to_uppercase.symbol_table
        expected_symbol_references = asrt.matches_sequence([
            is_reference_to_string_transformer(transform_to_uppercase.name)
        ])

        for_all__equals__arguments = args.complete_arguments_constructor(
            FileQuantificationAssertionVariant(
                Quantifier.ALL,
                file_contents_arg2(sm_arg.Transformed(transform_to_uppercase.name,
                                                      sm_arg.Equals.eq_string(expected_transformer_contents)))
                ,
            ))
        relativity_root_conf = AN_ACCEPTED_SDS_REL_OPT_CONFIG
        etc = expectation_type_config__non_is_success(ExpectationType.POSITIVE)
        arguments = for_all__equals__arguments.apply(etc)
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_FULL.check(
            self,
            remaining_source(arguments),
            model.model_with_rel_root_as_source_path(relativity_root_conf),
            arrangement=
            arrangement_w_tcds(
                tcds_contents=relativity_root_conf.populator_for_relativity_option_root(
                    DirContents([
                        File('1.txt', original_file_contents),
                        File('2.txt', original_file_contents),
                    ])
                ),
                symbols=symbol_table_with_lines_transformer
            ),
            expectation=
            Expectation(
                ParseExpectation(
                    symbol_references=expected_symbol_references
                ),
                ExecutionExpectation(
                    main_result=etc.pass__if_positive__fail__if_negative,
                ),
            )
        )
コード例 #5
0
ファイル: files_matcher.py プロジェクト: emilkarlen/exactly
    def _not_num_files_beginning_with_a_eq_1_arg() -> str:
        file_matcher_arg__begins_with_a = fm_args.file_matcher_arguments(
            name_pattern='a*'
        )

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

        args = fsm_args.SelectionAndMatcherArgumentsConstructor(
            file_matcher_arg__begins_with_a,
            files_matcher_args__num_files_eq_1,
        )

        return args.apply(
            expectation_type_config__non_is_success(ExpectationType.NEGATIVE)
        )
コード例 #6
0
    def test_hard_error_when_there_is_a_single_file_that_is_not_a_regular_file(self):
        name_of_checked_dir = 'checked-dir'
        relativity_root_conf = rel_opt_conf.default_conf_rel_any(RelOptionType.REL_CWD)
        the_model = model.model_with_source_path_as_sub_dir_of_rel_root(self.name_of_checked_dir)(relativity_root_conf)

        non_regular_files = [
            Dir.empty('a-directory'),
            sym_link('sym-link', 'non-existing-target')
        ]

        for file_contents_assertion in self.file_content_assertion_variants:
            for quantifier in Quantifier:
                arguments_constructor = args.complete_arguments_constructor(
                    FileQuantificationAssertionVariant(
                        quantifier,
                        file_contents_arg2(file_contents_assertion)))
                for expectation_type in ExpectationType:
                    arguments = arguments_constructor.apply(
                        expectation_type_config__non_is_success(expectation_type))
                    for non_regular_file in non_regular_files:
                        with self.subTest(
                                quantifier=quantifier.name,
                                expectation_type=expectation_type.name,
                                arguments=arguments,
                                non_regular_file=non_regular_file.name):
                            integration_check.CHECKER__PARSE_FULL.check(
                                self,
                                remaining_source(arguments),
                                the_model,
                                arrangement=
                                arrangement_w_tcds(
                                    tcds_contents=relativity_root_conf.populator_for_relativity_option_root(
                                        DirContents([
                                            Dir(name_of_checked_dir, [
                                                non_regular_file,
                                            ]),
                                        ])
                                    )
                                ),
                                expectation=
                                Expectation(
                                    execution=ExecutionExpectation(
                                        is_hard_error=asrt.anything_goes()
                                    ),
                                )
                            )
コード例 #7
0
    def check_expectation_type_variants(
        self,
        make_instruction_arguments: FilesMatcherArgumentsConstructor,
        model_constructor: ModelConstructorFromRelOptConf,
        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()):

        for expectation_type_of_test_case in ExpectationType:
            etc = expectation_type_config__non_is_success(
                expectation_type_of_test_case)
            instruction_arguments = make_instruction_arguments.apply(etc)
            self._check_(remaining_source(instruction_arguments),
                         model_constructor(root_dir_of_dir_contents),
                         etc,
                         main_result_for_positive_expectation,
                         root_dir_of_dir_contents,
                         contents_of_relativity_option_root,
                         test_case_name,
                         following_symbols_setup=following_symbols_setup)
コード例 #8
0
    def test_symbols_from_contents_assertion_SHOULD_be_reported(self):
        # ARRANGE #

        operand_sym_ref = SymbolReference('operand_symbol_name',
                                          is_string__all_indirect_refs_are_strings())

        condition_str = '{operator} {symbol_reference}'.format(
            operator=comparators.EQ.name,
            symbol_reference=symbol_reference_syntax_for_name(operand_sym_ref.name)
        )
        arguments_constructor = args.complete_arguments_constructor(
            FileQuantificationAssertionVariant(
                Quantifier.ALL,
                file_contents_arg2(sm_arg.NumLines(condition_str))))

        argument = arguments_constructor.apply(
            expectation_type_config__non_is_success(ExpectationType.NEGATIVE)
        )

        source = remaining_source(argument)

        # ACT #

        matcher_sdv = sut.parsers().full.parse(source)

        assert isinstance(matcher_sdv, MatcherSdv)

        actual_symbol_references = matcher_sdv.references

        # ASSERT #

        expected_symbol_references = [
            operand_sym_ref,
        ]
        assertion = equals_symbol_references__w_str_rendering(expected_symbol_references)

        assertion.apply_without_message(self, actual_symbol_references)
コード例 #9
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,
                            ),
                        )
                    )
コード例 #10
0
 def apply(self, condition_str: str) -> str:
     arguments_constructor = args.complete_arguments_constructor(
         FileQuantificationAssertionVariant(
             Quantifier.ALL,
             file_contents_arg2(sm_arg.NumLines(condition_str))))
     return arguments_constructor.apply(expectation_type_config__non_is_success(ExpectationType.POSITIVE))
コード例 #11
0
ファイル: selections.py プロジェクト: emilkarlen/exactly
    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(), ),
            ))
コード例 #12
0
ファイル: test_case_utils.py プロジェクト: emilkarlen/exactly
 def runTest(self):
     for expectation_type in ExpectationType:
         with self.subTest(expectation_type=expectation_type):
             self._doTest(
                 expectation_type_config__non_is_success(expectation_type))
コード例 #13
0
 def __init__(self, option_configuration: RelativityOptionConfiguration,
              expectation_type: ExpectationType):
     super().__init__()
     self.rel_opt = option_configuration
     self.not_opt = expectation_type_config__non_is_success(
         expectation_type)