예제 #1
0
 def test_arguments_of_program_file(self):
     # ARRANGE #
     exe_file = fs.python_executable_file(
         'program-name',
         py_programs.exit_with(0)
     )
     actor = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE)
     for case in VALIDATION_CASES:
         with self.subTest(case.name):
             act_contents = ab.sequence__r([
                 ab.singleton(exe_file.name),
                 program_arguments.existing_file(
                     path_arguments.RelOptPathArgument('non-existing',
                                                       case.path_relativity)
                 )
             ])
             act_instruction = instr([act_contents.as_str])
             # 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 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),
             )
예제 #3
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)
예제 #4
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)
예제 #5
0
 def _check(self,
            command_line: str,
            arrangement: Arrangement,
            expectation: Expectation):
     check_execution(self,
                     sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE),
                     [instr([command_line])],
                     arrangement,
                     expectation)
예제 #6
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([source_file.name])],
                        arrangement,
                        expectation,
                        )
예제 #7
0
        arrangement = integration_check.arrangement_w_tcds(
            hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
                fs.File(
                    source_file,
                    PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES)
            ])),
            symbol_table=symbol.symbol_table
        )

        expectation = integration_check.Expectation(
            symbol_usages=asrt.matches_sequence(
                [symbol.reference_assertion__w_str_rendering]
            ),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=asrt_pr.stdout(asrt.Equals(expected_output,
                                                                           'CLI arguments, one per line'))
            ),
        )
        integration_check.check_execution(self,
                                          ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE,
                                          [instr([command_line])],
                                          arrangement,
                                          expectation)


ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE)

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
예제 #8
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,
                )
            ),
        )
예제 #9
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()
        )
        text_until_end_of_line = 'some {}invalidly quoted text'.format(SOFT_QUOTE_CHAR)

        existing_path_relativity = relativity_options.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE)

        existing_path_argument = path_arguments.RelOptPathArgument(
            'existing-path',
            existing_path_relativity.relativity,
        )
        act_contents = ab.sequence__r([
            ab.singleton(exe_file.name),
            program_arguments.existing_path(
                existing_path_argument
            ),
            program_arguments.remaining_part_of_current_line_as_literal(text_until_end_of_line),
        ])

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

        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=hds_populators.multiple([
                    relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds(
                        fs.DirContents([exe_file])
                    ),
                    existing_path_relativity.populator_for_relativity_option_root__hds(
                        fs.DirContents([fs.File.empty(existing_path_argument.name)])
                    ),
                ])
            ),
            Expectation(
                after_execution=ExecutedCommandAssertion(
                    executor_that_records_arguments,
                    get_command_assertion,
                )
            ),
        )
예제 #10
0
def _parse_file_actor(token_parser: TokenParser) -> NameAndValue[Actor]:
    act_interpreter = parse_act_interpreter.parser().parse_from_token_parser(
        token_parser)
    return NameAndValue(actors.FILE_INTERPRETER_ACTOR.singular_name,
                        file_interpreter.actor(act_interpreter))