def _check_(
        self,
        instruction_source: ParseSource,
        etc: ExpectationTypeConfigForPfh,
        main_result_for_positive_expectation: PassOrFail,
        rel_opt_config: 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):
            instruction_check.check(
                self.put, self.parser, instruction_source,
                ArrangementPostAct(
                    pre_contents_population_action=
                    MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                    tcds_contents=rel_opt_config.
                    populator_for_relativity_option_root(
                        contents_of_relativity_option_root),
                    symbols=_symbol_table_of(rel_opt_config.symbols,
                                             following_symbols_setup),
                ),
                Expectation(
                    main_result=etc.main_result(
                        main_result_for_positive_expectation),
                    symbol_usages=asrt.matches_sequence(
                        rel_opt_config.symbols.usage_expectation_assertions() +
                        following_symbols_setup.expected_usages_list),
                ))
    def check_rel_opt_variants_with_same_result_for_every_expectation_type(
            self,
            make_instruction_arguments: InstructionArgumentsVariantConstructor,
            main_result: ValueAssertion,
            contents_of_relativity_option_root: DirContents = empty_dir_contents(),
            following_symbols_setup: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:

            for expectation_type_of_test_case in ExpectationType:
                etc = pfh_expectation_type_config(expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(etc, rel_opt_config)
                instruction_source = remaining_source(instruction_arguments)

                with self.put.subTest(expectation_type=etc.expectation_type.name,
                                      arguments=instruction_arguments):
                    instruction_check.check(
                        self.put,
                        self.parser,
                        instruction_source,
                        ArrangementPostAct(
                            pre_contents_population_action=MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                            home_or_sds_contents=rel_opt_config.populator_for_relativity_option_root(
                                contents_of_relativity_option_root
                            ),
                            symbols=_symbol_table_of(rel_opt_config.symbols,
                                                     following_symbols_setup),
                        ),
                        Expectation(
                            main_result=main_result,
                            symbol_usages=asrt.matches_sequence(
                                rel_opt_config.symbols.usage_expectation_assertions() +
                                following_symbols_setup.expected_references_list
                            )
                        ))
    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)
Exemplo n.º 4
0
def tmp_dir_as_cwd(contents: DirContents = empty_dir_contents()
                   ) -> ContextManager[pathlib.Path]:
    with temp_dir() as dir_path:
        with preserved_cwd():
            os.chdir(str(dir_path))
            contents.write_to(dir_path)
            yield dir_path
    def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        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 = pfh_expectation_type_config(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(
                    etc, rel_opt_config)

                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self.put, instruction_arguments):
                    self._check_(
                        source,
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
    def _check_(
            self,
            instruction_source: ParseSource,
            model: Model,
            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: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.empty()):

        with self.put.subTest(case_name=test_case_name,
                              expectation_type=etc.expectation_type.name,
                              arguments=instruction_source.source_string):
            integration_check.check(
                self.put,
                self.parser,
                instruction_source,
                model,
                ArrangementPostAct(
                    pre_contents_population_action=MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                    home_or_sds_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(
                    main_result=etc.main_result(main_result_for_positive_expectation),
                    symbol_usages=following_symbols_setup.expected_references_assertion,
                ))
    def check_parsing_with_different_source_variants(
            self,
            make_instruction_arguments: InstructionArgumentsVariantConstructor,
            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: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.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 = pfh_expectation_type_config(expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(etc, rel_opt_config)

                for source in equivalent_source_variants__with_source_check(self.put, instruction_arguments):
                    self._check_(
                        source,
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
    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: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.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__with_source_check__following_content_on_last_line_accepted(
                        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)
Exemplo n.º 9
0
def tmp_dir_as_cwd(contents: DirContents = empty_dir_contents()) -> pathlib.Path:
    with tempfile.TemporaryDirectory() as dir_name:
        with preserved_cwd():
            dir_path = resolved_path(dir_name)
            os.chdir(str(dir_path))
            contents.write_to(dir_path)
            yield dir_path
    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), ),
                ))
Exemplo n.º 11
0
def single_dir_setup(contents: DirContents = empty_dir_contents()
                     ) -> SingleDirSetup:
    action_dir = Dir('act', contents.file_system_elements)
    tmp_dir_contents = DirContents([action_dir])
    with tempfile.TemporaryDirectory() as dir_name:
        dir_path = resolved_path(dir_name)
        tmp_dir_contents.write_to(dir_path)
        yield SingleDirSetup(dir_path / action_dir.name, )
 def _do_parse_and_validate_pre_sds(self,
                                    instructions: Sequence[ActPhaseInstruction],
                                    home_dir_contents: DirContents = empty_dir_contents()
                                    ):
     with home_directory_structure(
             contents=case_home_dir_contents(home_dir_contents)) as hds:
         pre_sds_env = InstructionEnvironmentForPreSdsStep(hds,
                                                           {})
         executor = self.actor.parse(instructions)
         return executor.validate_pre_sds(pre_sds_env)
 def _do_parse_and_validate_pre_sds(
     self,
     instructions: Sequence[ActPhaseInstruction],
     home_dir_contents: DirContents = empty_dir_contents()):
     with home_directory_structure(
             contents=hds_case_dir_contents(home_dir_contents)) as hds:
         pre_sds_env = InstructionEnvironmentPreSdsBuilder.of_empty_env(
             hds=hds).build
         executor = self.actor.parse(instructions)
         return executor.validate_pre_sds(pre_sds_env)
Exemplo n.º 14
0
 def __init__(self,
              hds_contents: home_populators.HomePopulator = home_populators.empty(),
              root_dir_contents: DirContents = empty_dir_contents(),
              actor: Actor = dummy_actor(),
              test_case_status: TestCaseStatus = TestCaseStatus.PASS,
              timeout_in_seconds: int = None):
     super().__init__(hds_contents=hds_contents)
     self.root_dir_contents = root_dir_contents
     self.actor = actor
     self.test_case_status = test_case_status
     self.timeout_in_seconds = timeout_in_seconds
Exemplo n.º 15
0
 def __init__(
     self,
     act_phase_instructions: List[ActPhaseInstruction],
     home_act_dir_contents: DirContents = empty_dir_contents(),
     environ: Optional[Mapping[str, str]] = None,
     symbols: Optional[SymbolTable] = None,
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     self.symbols = symbol_table_from_none_or_value(symbols)
     self.home_act_dir_contents = home_act_dir_contents
     self.act_phase_instructions = act_phase_instructions
     self.environ = environ
     self.symbol_usages = symbol_usages
    def check_rel_opt_variants_and_expectation_type_variants(
            self,
            make_instruction_arguments: InstructionArgumentsVariantConstructor,
            main_result_for_positive_expectation: PassOrFail,
            contents_of_relativity_option_root: DirContents = empty_dir_contents(),
            test_case_name: str = '',
            following_symbols_setup: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:
            self.check_expectation_type_variants(
                make_instruction_arguments,
                main_result_for_positive_expectation,
                rel_opt_config,
                contents_of_relativity_option_root,
                test_case_name,
                following_symbols_setup=following_symbols_setup)
    def check_rel_opt_variants_and_expectation_type_variants(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        test_case_name: str = '',
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:
            self.check_expectation_type_variants(
                make_instruction_arguments,
                main_result_for_positive_expectation,
                rel_opt_config,
                contents_of_relativity_option_root,
                test_case_name,
                following_symbols_setup=following_symbols_setup)
    def check_rel_opt_variants_and_expectation_type_variants(
            self,
            make_instruction_arguments: FilesMatcherArgumentsConstructor,
            model_constructor: ModelConstructorFromRelOptConf,
            main_result_for_positive_expectation: PassOrFail,
            contents_of_relativity_option_root: DirContents = empty_dir_contents(),
            test_case_name: str = '',
            following_symbols_setup: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.empty()):

        for rel_opt_config in SOME_ACCEPTED_REL_OPT_CONFIGURATIONS:
            self.check_expectation_type_variants(
                make_instruction_arguments,
                model_constructor,
                main_result_for_positive_expectation,
                rel_opt_config,
                contents_of_relativity_option_root,
                test_case_name,
                following_symbols_setup=following_symbols_setup)
    def check_rel_opt_variants_and_expectation_type_variants(
        self,
        make_instruction_arguments: FilesMatcherArgumentsConstructor,
        model_constructor: ModelConstructorFromRelOptConf,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        test_case_name: str = '',
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        for rel_opt_config in SOME_ACCEPTED_REL_OPT_CONFIGURATIONS:
            self.check_expectation_type_variants(
                make_instruction_arguments,
                model_constructor,
                main_result_for_positive_expectation,
                rel_opt_config,
                contents_of_relativity_option_root,
                test_case_name,
                following_symbols_setup=following_symbols_setup)
    def check_rel_opt_variants(
            self,
            make_instruction_arguments: InstructionArgumentsVariantConstructor,
            main_result_for_positive_expectation: PassOrFail,
            contents_of_relativity_option_root: DirContents = empty_dir_contents(),
            test_case_name: str = '',
            following_symbols_setup: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:
            etc = pfh_expectation_type_config(ExpectationType.POSITIVE)
            instruction_arguments = make_instruction_arguments.apply(etc, rel_opt_config)
            self._check_(
                remaining_source(instruction_arguments),
                etc,
                main_result_for_positive_expectation,
                rel_opt_config,
                contents_of_relativity_option_root,
                test_case_name,
                following_symbols_setup=following_symbols_setup)
    def check_rel_opt_variants(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        test_case_name: str = '',
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:
            etc = pfh_expectation_type_config(ExpectationType.POSITIVE)
            instruction_arguments = make_instruction_arguments.apply(
                etc, rel_opt_config)
            self._check_(remaining_source(instruction_arguments),
                         etc,
                         main_result_for_positive_expectation,
                         rel_opt_config,
                         contents_of_relativity_option_root,
                         test_case_name,
                         following_symbols_setup=following_symbols_setup)
    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: SymbolsArrAndExpectSetup = SymbolsArrAndExpectSetup.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)
    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)
Exemplo n.º 24
0
def cases(model_file_name: str) -> Sequence[NameAndValue[DirContents]]:
    return [
        NameAndValue(
            'file does not exist',
            empty_dir_contents(),
        ),
        NameAndValue(
            'file is regular file',
            DirContents([File.empty(model_file_name)]),
        ),
        NameAndValue(
            'file is broken sym link',
            DirContents([sym_link(model_file_name, 'non-existing-target')]),
        ),
        NameAndValue(
            'file is sym link to regular file',
            DirContents([
                sym_link(model_file_name, 'regular file'),
                File.empty('regular file')
            ]),
        ),
    ]
    def check_rel_opt_variants_with_same_result_for_every_expectation_type(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        main_result: Assertion,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:

            for expectation_type_of_test_case in ExpectationType:
                etc = pfh_expectation_type_config(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(
                    etc, rel_opt_config)
                instruction_source = remaining_source(instruction_arguments)

                with self.put.subTest(
                        expectation_type=etc.expectation_type.name,
                        arguments=instruction_arguments):
                    instruction_check.check(
                        self.put, self.parser, instruction_source,
                        ArrangementPostAct(
                            pre_contents_population_action=
                            MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                            tcds_contents=rel_opt_config.
                            populator_for_relativity_option_root(
                                contents_of_relativity_option_root),
                            symbols=_symbol_table_of(rel_opt_config.symbols,
                                                     following_symbols_setup),
                        ),
                        Expectation(
                            main_result=main_result,
                            symbol_usages=asrt.matches_sequence(
                                rel_opt_config.symbols.
                                usage_expectation_assertions() +
                                following_symbols_setup.expected_usages_list)))
Exemplo n.º 26
0
 def test_fail_WHEN_file_argument_do_not_exit(self):
     self._expect_raise_argument_parsing_error(
         cwd_contents=empty_dir_contents(),
         arguments=['non-existing.suite'])
Exemplo n.º 27
0
 def test_fail_WHEN_no_file_argument(self):
     self._expect_raise_argument_parsing_error(
         cwd_contents=empty_dir_contents(), arguments=[])
Exemplo n.º 28
0
def tmp_dir(contents: DirContents = empty_dir_contents()) -> ContextManager[
        pathlib.Path]:
    with temp_dir() as dir_path:
        contents.write_to(dir_path)
        yield dir_path
Exemplo n.º 29
0
class TestCheckForDirectory(TestCaseBase):
    file_name = 'name-of-checked-file'
    instruction_argument_constructor = arguments_constructor_for_file_type(
        file_name,
        FileType.DIRECTORY)

    cases_with_existing_directory = [
        NameAndValue(
            'exists as directory',
            DirContents([Dir.empty(file_name)])
        ),
        NameAndValue(
            'exists as sym-link to existing directory',
            DirContents([Dir.empty('directory'),
                         Link(file_name, 'directory')]),
        ),
    ]

    cases_with_existing_files_that_are_not_directories = [
        NameAndValue(
            'exists as regular file',
            DirContents([File.empty(file_name)])
        ),
        NameAndValue(
            'exists as sym-link to existing regular file',
            DirContents([File.empty('existing-file'),
                         Link(file_name, 'directory')]),
        ),
        NameAndValue(
            'broken sym-link',
            DirContents(
                [Link(file_name, 'non-existing-target-file')])
        ),
    ]

    cases_with_non_existing_files = [
        NameAndValue(
            'non-existing file',
            empty_dir_contents()
        ),
    ]

    def test_file_is_an_existing_directory(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_existing_directory,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.PASS,
        )

    def test_file_exists_but_is_not_a_directory(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_existing_files_that_are_not_directories,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.FAIL,
        )

    def test_file_does_not_exist(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_non_existing_files,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.FAIL,
        )
Exemplo n.º 30
0
def dir_is_empty() -> ValueAssertion[pathlib.Path]:
    """
    Assumes that the actual value is a pathlib.Path
    """
    return DirContainsExactly(file_structure.empty_dir_contents())
Exemplo n.º 31
0
 def test_fail_WHEN_no_file_argument(self):
     self._expect_raise_argument_parsing_error(
         cwd_contents=empty_dir_contents(),
         arguments=[]
     )
Exemplo n.º 32
0
 def test_fail_WHEN_argument_is_non_existing_file(self):
     self._expect_resolving_error(
         contents_dir_contents=empty_dir_contents(),
         source='non-existing.file',
     )
Exemplo n.º 33
0
def tmp_dir(contents: DirContents = empty_dir_contents()) -> pathlib.Path:
    with tempfile.TemporaryDirectory() as dir_name:
        dir_path = resolved_path(dir_name)
        contents.write_to(dir_path)
        yield dir_path
Exemplo n.º 34
0
 def __init__(self, act_phase_instructions: list,
              home_act_dir_contents: DirContents = empty_dir_contents()):
     self.home_act_dir_contents = home_act_dir_contents
     self.act_phase_instructions = act_phase_instructions
Exemplo n.º 35
0
class TestCheckForSymLink(TestCaseBase):
    file_name = 'the-name-of-checked-file'
    instruction_argument_constructor = arguments_constructor_for_file_type(
        file_name,
        FileType.SYMLINK)

    cases_with_existing_files_that_are_symbolic_links = [
        NameAndValue(
            'exists as sym-link to directory',
            DirContents([Dir.empty('dir'),
                         Link(file_name, 'dir')])
        ),
        NameAndValue(
            'exists as sym-link to existing regular file',
            DirContents([File.empty('file'),
                         Link(file_name, 'file')]),
        ),
        NameAndValue(
            'exists as sym-link to non-existing file',
            DirContents([Link(file_name, 'non-existing-file')]),
        ),
    ]

    cases_with_existing_files_that_are_not_symbolic_links = [
        NameAndValue(
            'exists as directory',
            DirContents([File.empty(file_name)])
        ),
        NameAndValue(
            'exists as regular file',
            DirContents([Dir.empty(file_name)]),
        ),
    ]

    cases_with_non_existing_files = [
        NameAndValue(
            'non-existing file',
            empty_dir_contents()
        ),
    ]

    def test_file_exists_and_is_a_regular_file(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_existing_files_that_are_symbolic_links,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.PASS,
        )

    def test_file_exists_but_is_not_a_regular_file(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_existing_files_that_are_not_symbolic_links,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.FAIL,
        )

    def test_file_does_not_exist(self):
        self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants(
            self.cases_with_non_existing_files,
            self.instruction_argument_constructor,
            main_result_for_positive_expectation=PassOrFail.FAIL,
        )
Exemplo n.º 36
0
def dir_is_empty() -> Assertion[pathlib.Path]:
    """
    Assumes that the actual value is a pathlib.Path
    """
    return DirContainsExactly(file_structure.empty_dir_contents())
Exemplo n.º 37
0
 def test_fail_WHEN_file_argument_do_not_exit(self):
     self._expect_raise_argument_parsing_error(
         cwd_contents=empty_dir_contents(),
         arguments=['non-existing.suite']
     )
Exemplo n.º 38
0
 def test_fail_WHEN_argument_is_non_existing_file(self):
     self._expect_resolving_error(
         contents_dir_contents=empty_dir_contents(),
         source='non-existing.file',
     )
Exemplo n.º 39
0
 def file_structure(self, tmp_cwd_dir_path: pathlib.Path) -> DirContents:
     return empty_dir_contents()
Exemplo n.º 40
0
 def file_structure(self, tmp_cwd_dir_path: pathlib.Path) -> DirContents:
     return empty_dir_contents()