Example #1
0
    def _check_failing_validation_of_referenced_program__for_relativity(self, missing_file_relativity: RelOptionType):
        relativity_conf = relativity_options.conf_rel_any(missing_file_relativity)

        program_symbol_with_ref_to_non_exiting_exe_file = ProgramSymbolContext.of_sdv(
            'PGM_WITH_REF_TO_EXE_FILE',
            program_sdvs.ref_to_exe_file(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-exe-file')))
        )

        program_symbol_with_ref_to_non_exiting_file_as_argument = ProgramSymbolContext.of_sdv(
            'PGM_WITH_ARG_WITH_REF_TO_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-python-file.py')))
        )

        expectation = MultiSourceExpectation.of_const(
            symbol_references=asrt.anything_goes(),
            primitive=asrt.anything_goes(),
            execution=ExecutionExpectation(
                validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[relativity_conf.directory_structure_partition],
            )
        )

        symbols = SymbolContext.symbol_table_of_contexts([
            program_symbol_with_ref_to_non_exiting_exe_file,
            program_symbol_with_ref_to_non_exiting_file_as_argument,
        ])
        arrangement = arrangement_w_tcds(
            symbols=symbols,
        )

        cases = [
            NameAndValue(
                'executable does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_exe_file.name),
            ),
            NameAndValue(
                'file referenced from argument does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_file_as_argument.name),
            ),
        ]

        for case in cases:
            with self.subTest(case=case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self,
                    equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
                    case.value,
                    arrangement,
                    expectation,
                )
Example #2
0
 def _just_string_argument(
     self,
     argument: str,
 ) -> PathSdv:
     argument_path = pathlib.PurePosixPath(argument)
     if argument_path.is_absolute():
         #  TODO Should we check if absolute paths are allowed according to RelOptionArgumentConfiguration??
         return path_sdvs.constant(path_ddvs.absolute_file_name(argument))
     path_suffix = path_ddvs.constant_path_part(argument)
     return path_sdvs.constant(
         path_ddvs.of_rel_option(
             self.conf.rel_opt_conf.options.default_option, path_suffix))
Example #3
0
 def test_arguments_of_interpreter(self):
     # ARRANGE #
     exe_file = fs.python_executable_file(
         'program-name',
         py_programs.exit_with(0)
     )
     for case in VALIDATION_CASES:
         with self.subTest(case.name):
             interpreter_arguments = arguments_sdvs.ref_to_path_that_must_exist(
                 path_sdvs.of_rel_option_with_const_file_name(case.path_relativity,
                                                              'non-existing-file')
             )
             actor = sut.actor(
                 command_sdvs.for_executable_file(
                     path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable)),
                     interpreter_arguments
                 )
             )
             act_instruction = instr([exe_file.name])
             # ACT & ASSERT #
             integration_check.check_execution(
                 self,
                 actor,
                 [act_instruction],
                 arrangement_w_tcds(
                     hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds(
                         fs.DirContents([exe_file])
                     )
                 ),
                 Expectation(validation=case.expectation),
             )
Example #4
0
    def runTest(self):
        # ARRANGE #

        source_file = fs.File.empty('source-file.src')
        a_dir = fs.Dir.empty('a-dir')

        interpreter_with_program_that_is_a_dir = command_sdvs.for_executable_file(
            path_sdvs.constant(
                path_ddvs.rel_hds(relativity_configurations.INTERPRETER_FILE.relativity_option_rel_hds,
                                  path_ddvs.constant_path_part(a_dir.name))),
        )

        command_line = source_file
        arrangement = arrangement_w_tcds(
            hds_contents=hds_populators.multiple([
                relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds(
                    fs.DirContents([source_file])
                ),
                relativity_configurations.INTERPRETER_FILE.populator_for_relativity_option_root__hds(
                    fs.DirContents([a_dir])
                ),
            ])
        )
        expectation = Expectation(
            validation=ValidationExpectationSvh.fails__pre_sds()
        )
        # ACT & ASSERT #
        check_execution(self,
                        sut.actor(interpreter_with_program_that_is_a_dir),
                        [instr([command_line.name])],
                        arrangement,
                        expectation)
Example #5
0
    def runTest(self):
        # ARRANGE #
        source_file = fs.File.empty('source-file.src')

        interpreter_with_non_existing_program_file = command_sdvs.for_executable_file(
            path_sdvs.constant(
                path_ddvs.rel_hds(relativity_configurations.INTERPRETER_FILE.relativity_option_rel_hds,
                                  path_ddvs.constant_path_part('non-existing'))),
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds(
                fs.DirContents([source_file])
            )
        )

        expectation = Expectation(
            validation=ValidationExpectationSvh.fails__pre_sds()
        )
        # ACT & ASSERT #
        check_execution(self,
                        sut.actor(interpreter_with_non_existing_program_file),
                        [instr([source_file.name])],
                        arrangement,
                        expectation)
    def runTest(self):
        # ARRANGE #

        source_file = fs.File.empty('source-file.src')

        python_interpreter_symbol = PathSymbolContext.of_sdv(
            'PYTHON_INTERPRETER_SYMBOL',
            path_sdvs.constant(
                path_ddvs.absolute_path(pathlib.Path(sys.executable))))

        interpreter_with_symbol_reference = command_sdvs.for_executable_file(
            python_interpreter_symbol.reference_sdv__path_or_string(
                relativity_configurations.INTERPRETER_FILE.relativity))

        arrangement = arrangement_w_tcds(
            symbol_table=python_interpreter_symbol.symbol_table,
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([source_file])))
        expectation = Expectation(
            symbol_usages=asrt.matches_singleton_sequence(
                python_interpreter_symbol.reference_assertion__path_or_string),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=asrt_pr.sub_process_result(
                    exitcode=asrt.equals(0),
                    stdout=asrt.equals(''),
                    stderr=asrt.equals(''),
                )),
        )
        # ACT & ASSERT #
        check_execution(self, sut.actor(interpreter_with_symbol_reference),
                        [instr([])], arrangement, expectation)
Example #7
0
 def test_differs__exists_pre_sds(self):
     # ARRANGE #
     expected = PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name'))
     actual = PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name'))
     assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
Example #8
0
 def test_differs__relativity(self):
     # ARRANGE #
     expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name'))
     actual = PathDdvTestImpl(RelOptionType.REL_HDS_CASE, path_ddvs.constant_path_part('file-name'))
     assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
Example #9
0
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(
                 abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src2(ValueType.PATH, 'name',
                                     '{rel_source_file} component')
         for source in equivalent_source_variants__with_source_check__consume_last_line(
                 self, instruction_argument):
             expected_path_sdv = path_sdvs.constant(
                 path_ddvs.rel_abs_path(
                     abs_path_of_dir_containing_last_file_base_name,
                     path_ddvs.constant_path_part('component')))
             expected_symbol_value = PathSymbolValueContext.of_sdv(
                 expected_path_sdv)
             expected_symbol = PathSymbolContext('name',
                                                 expected_symbol_value)
             INSTRUCTION_CHECKER.check(
                 self, source,
                 Arrangement.phase_agnostic(
                     fs_location_info=fs_location_info),
                 Expectation.phase_agnostic(
                     symbol_usages=asrt.matches_singleton_sequence(
                         expected_symbol.assert_matches_definition_of_sdv),
                     symbols_after_main=assert_symbol_table_is_singleton(
                         'name', expected_symbol_value.
                         assert_matches_container_of_sdv)))
 def test_fail__different_source_line_and_source_line_check_is_not_ignored(
         self):
     # ARRANGE #
     common_value = path_sdvs.constant(path_test_impl('common file-name'))
     expected = PathSymbolValueContext.of_sdv(
         common_value,
         definition_source=single_line_sequence(1,
                                                'source code 1')).container
     actual = PathSymbolValueContext.of_sdv(
         common_value,
         definition_source=single_line_sequence(2,
                                                'source code 2')).container
     assertion = sut.equals_container(expected, ignore_source_line=False)
     assert_that_assertion_fails(assertion, actual)
Example #11
0
 def _with_explicit_relativity(
         self, path_argument: Token,
         path_part_2_path_sdv: Callable[[PathPartSdv], PathSdv]) -> PathSdv:
     string_sdv = _parse_string_sdv(path_argument)
     if string_sdv.is_string_constant:
         path_argument_str = string_sdv.string_constant
         path_argument_path = pathlib.PurePosixPath(path_argument_str)
         if path_argument_path.is_absolute():
             return path_sdvs.constant(
                 path_ddvs.absolute_file_name(path_argument_str))
         path_suffix = path_part_sdvs.from_constant_str(path_argument_str)
         return path_part_2_path_sdv(path_suffix)
     else:
         path_suffix = path_part_sdvs.from_string(string_sdv)
         return path_part_2_path_sdv(path_suffix)
Example #12
0
    def construct(self, environment: i.InstructionEnvironmentForPostSdsStep,
                  os_services: OsServices) -> ComparisonActualFile:
        program = resolving_helper_for_instruction_env(
            os_services, environment).resolve_program(self._program)
        result = make_transformed_file_from_output_in_instruction_tmp_dir(
            environment, os_services, self._checked_output, program)
        file_with_transformed_contents = path_sdvs.constant(
            path_ddvs.absolute_path(
                result.path_of_file_with_transformed_contents))

        path_with_transformed_contents = (
            file_with_transformed_contents.resolve(
                environment.symbols).value_of_any_dependency__d(
                    environment.tcds))

        return ComparisonActualFile(path_with_transformed_contents, False)
Example #13
0
 def test_difference_in_relativity_root(self):
     symbols = empty_symbol_table()
     for relativity in _RELATIVITY_VARIANTS:
         for path_suffix in _PATH_SUFFIX_VARIANTS:
             test_case_descr = 'relativity:{}, path-suffix: {}'.format(relativity, type(path_suffix))
             path = PathDdvTestImpl(relativity, path_suffix)
             path_sdv = path_sdvs.constant(path)
             with self.subTest(msg=sut.equals_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.equals_path_sdv(path_sdv)
                 assertion.apply_without_message(self, path_sdv)
             with self.subTest(msg=sut.matches_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.matches_path_sdv(path,
                                                  equals_symbol_references__w_str_rendering(
                                                      path_sdv.references),
                                                  symbols)
                 assertion.apply_without_message(self, path_sdv)
 def runTest(self):
     # ARRANGE #
     for case in VALIDATION_CASES:
         with self.subTest(case.name):
             interpreter_arguments = arguments_sdvs.ref_to_path_that_must_exist(
                 path_sdvs.of_rel_option_with_const_file_name(
                     case.path_relativity, 'non-existing-file'))
             actor = sut.actor(
                 command_sdvs.for_executable_file(
                     path_sdvs.constant(
                         path_ddvs.absolute_file_name(sys.executable)),
                     interpreter_arguments))
             act_instruction = instr([])
             # ACT & ASSERT #
             integration_check.check_execution(
                 self,
                 actor,
                 [act_instruction],
                 arrangement_w_tcds(),
                 Expectation(validation=case.expectation),
             )
Example #15
0
import sys

from exactly_lib.impls.types.program.command import arguments_sdvs
from exactly_lib.impls.types.program.command import driver_sdvs as drivers
from exactly_lib.type_val_deps.types.list_ import list_sdvs
from exactly_lib.type_val_deps.types.path import path_ddvs, path_sdvs
from exactly_lib.type_val_deps.types.path.path_sdv import PathSdv
from exactly_lib.type_val_deps.types.program.sdv.arguments import ArgumentsSdv
from exactly_lib.type_val_deps.types.program.sdv.command import CommandSdv
from exactly_lib_test.test_resources.programs.python_program_execution import \
    PY_ARG_FOR_EXECUTING_SOURCE_ON_COMMAND_LINE

PYTHON_EXECUTABLE_DRIVER = drivers.CommandDriverSdvForExecutableFile(
    path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable)))

PYTHON_EXECUTABLE_COMMAND = CommandSdv(PYTHON_EXECUTABLE_DRIVER,
                                       ArgumentsSdv.empty())

EXECUTABLE_FILE_FOR_PY_SRC_ON_COMMAND_LINE = PYTHON_EXECUTABLE_COMMAND.new_with_additional_argument_list(
    list_sdvs.from_str_constant(PY_ARG_FOR_EXECUTING_SOURCE_ON_COMMAND_LINE))


def for_py_source_on_command_line(python_source: str) -> CommandSdv:
    return EXECUTABLE_FILE_FOR_PY_SRC_ON_COMMAND_LINE.new_with_additional_argument_list(
        list_sdvs.from_str_constant(python_source))


def for_interpret_py_file_that_must_exist(
        python_source_file: PathSdv) -> CommandSdv:
    return PYTHON_EXECUTABLE_COMMAND.new_with_additional_arguments(
        arguments_sdvs.ref_to_file_that_must_exist(python_source_file))
def all_command_driver_types() -> Sequence[CommandDriverSdvCase]:
    # ARRANGE #
    system_program_name = 'system-program'
    executable_program_file_name = 'executable-program-file'
    executable_file_relativity = relativity_options.conf_rel_any(
        RelOptionType.REL_HDS_ACT)
    executable_file_ddv = path_ddvs.of_rel_option(
        executable_file_relativity.relativity_option,
        path_ddvs.constant_path_part(executable_program_file_name))
    shell_initial_command = 'shell initial command'

    def mk_arrangement__executable_file(symbols: SymbolTable) -> Arrangement:
        return arrangement_w_tcds(
            symbols=symbols,
            tcds_contents=executable_file_relativity.
            populator_for_relativity_option_root(
                fs.DirContents(
                    [fs.executable_file(executable_program_file_name)])))

    def expected_command_driver__system_program(
            env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]:
        return asrt_command.matches_system_program_command_driver(
            asrt.equals(system_program_name))

    def expected_command_driver__executable_file(
            env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]:
        return asrt_command.matches_executable_file_command_driver(
            asrt.equals(
                executable_file_ddv.value_of_any_dependency__d(
                    env.tcds).primitive), )

    def expected_command_driver__shell_cmd_line(
            env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]:
        return asrt_command.matches_shell_command_driver(
            asrt.equals(shell_initial_command))

    return [
        CommandDriverSdvCase(
            'system program',
            command_driver=driver_sdvs.CommandDriverSdvForSystemProgram(
                string_sdvs.str_constant(system_program_name)),
            expected_command_driver=expected_command_driver__system_program,
            mk_arrangement=lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl
                                                               ),
        ),
        CommandDriverSdvCase(
            'executable program file',
            command_driver=driver_sdvs.CommandDriverSdvForExecutableFile(
                path_sdvs.constant(executable_file_ddv)),
            expected_command_driver=expected_command_driver__executable_file,
            mk_arrangement=mk_arrangement__executable_file,
        ),
        CommandDriverSdvCase(
            'shell command line',
            command_driver=driver_sdvs.CommandDriverSdvForShell(
                string_sdvs.str_constant(shell_initial_command)),
            expected_command_driver=expected_command_driver__shell_cmd_line,
            mk_arrangement=lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl
                                                               ),
        ),
    ]
Example #17
0
 def test_not_equals__path(self):
     # ARRANGE #
     expected = path_sdvs.constant(path_test_impl('expected-file-name'))
     actual = path_sdvs.constant(path_test_impl('actual-file-name'))
     # ACT & ASSERT #
     assert_that_assertion_fails(sut.equals_data_type_sdv(expected), actual)
Example #18
0
 def test_not_equals__non_symbol_type(self):
     # ARRANGE #
     expected = path_sdvs.constant(path_test_impl('file-name'))
     actual = UnknownDataTypeSdvClass()
     # ACT & ASSERT #
     assert_that_assertion_fails(sut.equals_data_type_sdv(expected), actual)
Example #19
0
 def test_not_equals__different_symbol_types(self):
     # ARRANGE #
     expected = path_sdvs.constant(path_test_impl('file-name'))
     actual = str_constant('string value')
     # ACT & ASSERT #
     assert_that_assertion_fails(sut.equals_data_type_sdv(expected), actual)
Example #20
0
 def test_equals__path(self):
     # ARRANGE #
     value = path_sdvs.constant(path_test_impl('file-name'))
     # ACT & ASSERT #
     sut.equals_data_type_sdv(value).apply_without_message(self, value)
Example #21
0
 def _path_sdv_for(self, path_suffix: PathPartDdv) -> PathSdv:
     return path_sdvs.constant(
         path_ddvs.of_rel_option(rel_any_from_rel_sds(self.relativity_sds),
                                 path_suffix))
Example #22
0
def path_sdv_test_impl(valid_relativities: PathRelativityVariants) -> PathSdv:
    relativity = list(valid_relativities.rel_option_types)[0]
    assert isinstance(relativity, RelOptionType)
    return path_sdvs.constant(path_test_impl('path_test_impl', relativity))
Example #23
0
 def _result_from_no_arguments(self, ) -> Either[SymbolName, PathSdv]:
     return Either.of_right(
         path_sdvs.constant(
             path_ddvs.of_rel_option(
                 self.conf.rel_opt_conf.options.default_option,
                 path_ddvs.empty_path_part())))
Example #24
0
def path_constant_sdv() -> PathSdv:
    return path_sdvs.constant(
        path_test_impl('file-name-rel-home',
                       relativity=RelOptionType.REL_HDS_CASE))
Example #25
0
    def runTest(self):
        # ARRANGE #
        actor = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE)

        exe_file = fs.python_executable_file(
            'program-name',
            py_programs.exit_with_0()
        )
        argument_to_act_file = 'argument-to-act-file'
        act_contents = ab.sequence__r([
            ab.singleton(exe_file.name),
            ab.singleton(argument_to_act_file)
        ])
        interpreter_arguments_symbol = ListConstantSymbolContext('INTERPRETER_ARGS_LIST', ['1st', '2nd'])
        interpreter_arguments = ArgumentsSdv.new_without_validation(
            interpreter_arguments_symbol.sdv
        )
        actor = sut.actor(
            command_sdvs.for_executable_file(
                path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable)),
                interpreter_arguments
            )
        )

        def get_command_assertion(tcds: TestCaseDs) -> Assertion[Command]:
            symbols = SymbolTable.empty()
            return asrt_command.matches_command(
                asrt.anything_goes(),
                asrt.equals(
                    interpreter_arguments_symbol.constant_list +
                    [
                        str(relativity_configurations.ATC_FILE
                            .named_file_conf(exe_file.name)
                            .path_sdv
                            .resolve(symbols)
                            .value_of_any_dependency__d(tcds)
                            .primitive
                            ),
                        argument_to_act_file,
                    ]
                )
            )

        act_instruction = instr([act_contents.as_str])
        executor_that_records_arguments = CommandExecutorThatRecordsArguments()
        # ACT & ASSERT #
        integration_check.check_execution(
            self,
            actor,
            [act_instruction],
            arrangement_w_tcds(
                process_execution=ProcessExecutionArrangement(
                    os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments)
                ),
                hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds(
                    fs.DirContents([exe_file])
                )
            ),
            Expectation(
                after_execution=ExecutedCommandAssertion(
                    executor_that_records_arguments,
                    get_command_assertion,
                )
            ),
        )
Example #26
0
 def _parse_python_interpreter(token_parser: TokenParser) -> PathSdv:
     return path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable))
def _command_for_non_existing_interpreter() -> CommandSdv:
    interpreter_path = pathlib.Path().cwd().resolve() / 'non-existing-interpreter'
    return command_sdvs.for_executable_file(
        path_sdvs.constant(path_ddvs.absolute_path(interpreter_path))
    )