Пример #1
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),
             )
Пример #2
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)
Пример #3
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)
Пример #4
0
    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)
Пример #5
0
    def _assert_passes_validation(
            self, actual: PathSdv,
            environment: PathResolvingEnvironmentPreOrPostSds):
        path_as_exe_file_cmd = command_sdvs.for_executable_file(actual)
        actual_validator = ddv_validators.all_of(
            path_as_exe_file_cmd.resolve(environment.symbols).validators)

        assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
            validation.Expectation.passes_all(), environment.tcds)
        assertion.apply_with_message(self, actual_validator, 'validation')
Пример #6
0
    def _assert_does_not_pass_validation(
            self, actual: PathSdv,
            environment: PathResolvingEnvironmentPreOrPostSds):
        path_as_exe_file_cmd = command_sdvs.for_executable_file(actual)
        actual_validator = ddv_validators.all_of(
            path_as_exe_file_cmd.resolve(environment.symbols).validators)

        passes_pre_sds = not self.configuration.exists_pre_sds
        passes_post_sds = not passes_pre_sds
        expectation = validation.Expectation(
            passes_pre_sds=passes_pre_sds,
            passes_post_sds=passes_post_sds,
        )

        assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
            expectation, environment.tcds)
        assertion.apply_with_message(self, actual_validator, 'validation')
Пример #7
0
 def _check(self, arguments_str: str,
            expected_source_after_parse: Assertion[ParseSource],
            expectation_on_exe_file: ExpectationOnExeFile,
            validator_expectation: validation.Expectation):
     # ARRANGE #
     source = ParseSource(arguments_str)
     # ACT #
     exe_file = sut.parser().parse(source)
     # ASSERT #
     utils.check_exe_file(self, expectation_on_exe_file, exe_file)
     expected_source_after_parse.apply_with_message(self, source,
                                                    'parse source')
     exe_file_command = command_sdvs.for_executable_file(exe_file)
     with tcds_with_act_as_curr_dir() as environment:
         actual_validator = ddv_validators.all_of(
             exe_file_command.resolve(environment.symbols).validators)
         assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
             validator_expectation, environment.tcds)
         assertion.apply_with_message(self, actual_validator, 'validation')
Пример #8
0
def check(put: unittest.TestCase, instruction_argument_string: str,
          arrangement: Arrangement, expectation: Expectation):
    # ARRANGE #
    source = ParseSource(instruction_argument_string)
    # ACT #
    actual_exe_file = parse_executable_file_path.parser().parse(source)
    # ASSERT #
    exe_file_as_command = command_sdvs.for_executable_file(actual_exe_file)

    expectation.source.apply_with_message(put, source, 'parse source')
    check_exe_file(put, expectation.expectation_on_exe_file, actual_exe_file)
    with tcds_with_act_as_curr_dir(
            tcds_contents=arrangement.tcds_populator) as environment:
        os.mkdir('act-cwd')
        os.chdir('act-cwd')
        actual_validator = ddv_validators.all_of(
            exe_file_as_command.resolve(environment.symbols).validators)

        assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
            expectation.validation_result, environment.tcds)
        assertion.apply_with_message(put, actual_validator, 'validation')
Пример #9
0
 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),
             )
Пример #10
0
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))
    )
Пример #11
0
def ref_to_exe_file(
    exe_file: PathSdv, arguments: ArgumentsSdv = ArgumentsSdv.empty()
) -> ProgramSdvForCommand:
    return command_program_sdv.plain(
        command_sdvs.for_executable_file(exe_file, arguments))
Пример #12
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,
                )
            ),
        )
Пример #13
0
 def parse_from_token_parser(self, parser: TokenParser) -> CommandSdv:
     exe_file = self._exe_file_parser.parse_from_token_parser(parser)
     arguments = self._arguments_parser.parse_from_token_parser(parser)
     return command_sdvs.for_executable_file(exe_file, arguments)