Example #1
0
 def runTest(self):
     # ARRANGE #
     expected_file_name = 'quoted file name.src'
     act_phase_instructions = [instr([str(surrounded_by_hard_quotes(expected_file_name))]),
                               instr([''])]
     executor_that_records_arguments = CommandExecutorThatRecordsArguments()
     arrangement = integration_check.arrangement_w_tcds(
         hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, DirContents([
             File.empty(expected_file_name)])),
         process_execution=ProcessExecutionArrangement(
             os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments)
         )
     )
     expectation = integration_check.Expectation()
     # ACT #
     integration_check.check_execution(self,
                                       ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE,
                                       act_phase_instructions,
                                       arrangement, expectation)
     # ASSERT #
     expected_command = asrt_command.matches_command(
         driver=asrt_command.matches_executable_file_command_driver(asrt.anything_goes()),
         arguments=asrt.matches_sequence([
             asrt_path.str_as_path(asrt_path.name_equals(expected_file_name))
         ])
     )
     expected_command.apply_with_message(
         self,
         executor_that_records_arguments.command,
         'command',
     )
    def _check_with_exit_code(self, exit_code: int):
        # ARRANGE #
        result = SubProcessResult(
            exitcode=exit_code,
            stdout='output on stdout',
            stderr='output on stderr',
        )

        command_py_program = py_program.program_that_prints_and_exits_with_exit_code(result)

        py_file = fs.File(
            'the-program.py',
            command_py_program,
        )
        program_wo_transformation = ProgramSymbolContext.of_sdv(
            'PROGRAM_SYMBOL',
            program_sdvs.interpret_py_source_file_that_must_exist(
                path_sdvs.of_rel_option_with_const_file_name(
                    RelOptionType.REL_HDS_CASE,
                    py_file.name,
                )
            )
        )

        source = args.program(
            args.symbol_ref_command_line(program_wo_transformation.name),
            transformation=TO_UPPER_CASE_TRANSFORMER.name__sym_ref_syntax)

        symbols = [
            program_wo_transformation,
            TO_UPPER_CASE_TRANSFORMER,
        ]
        # ACT & ASSERT #

        integration_check.check_execution(
            self,
            sut.actor(),
            [instr(source.as_arguments.lines)],
            arrangement_w_tcds(
                symbol_table=SymbolContext.symbol_table_of_contexts(symbols),
                hds_contents=hds_populators.contents_in(
                    RelHdsOptionType.REL_HDS_CASE,
                    DirContents([py_file]),
                )
            ),
            Expectation(
                symbol_usages=SymbolContext.references_assertion_of_contexts(symbols),
                execute=asrt_eh.is_exit_code(result.exitcode),
                post_sds=PostSdsExpectation.constant(
                    sub_process_result_from_execute=asrt_proc_result.matches_proc_result(
                        exit_code=asrt.equals(result.exitcode),
                        stdout=asrt.equals(result.stdout.upper()),
                        stderr=asrt.equals(result.stderr),
                    )
                )
            ),
        )
    def runTest(self):
        # ARRANGE #

        command_py_program = py_program.exit_with_code(0)

        py_file = fs.File(
            'the-program.py',
            lines_content(command_py_program),
        )
        program_wo_transformation = ProgramSymbolContext.of_sdv(
            'PROGRAM_SYMBOL',
            program_sdvs.interpret_py_source_file_that_must_exist(
                path_sdvs.of_rel_option_with_const_file_name(
                    RelOptionType.REL_HDS_CASE,
                    py_file.name,
                )
            )
        )

        error_message = 'error message from transformer'
        transformer = StringTransformerPrimitiveSymbolContext(
            'HARD_ERROR_TRANSFORMER',
            string_transformers.model_access_raises_hard_error(error_message),
        )

        source = args.program(
            args.symbol_ref_command_line(program_wo_transformation.name),
            transformation=transformer.name__sym_ref_syntax)

        symbols = [
            program_wo_transformation,
            transformer,
        ]

        # ACT & ASSERT #

        integration_check.check_execution(
            self,
            sut.actor(),
            [instr(source.as_arguments.lines)],
            arrangement_w_tcds(
                symbol_table=SymbolContext.symbol_table_of_contexts(symbols),
                hds_contents=hds_populators.contents_in(
                    RelHdsOptionType.REL_HDS_CASE,
                    DirContents([py_file]),
                )
            ),
            Expectation(
                symbol_usages=SymbolContext.references_assertion_of_contexts(symbols),
                execute=asrt_eh.matches_hard_error(
                    asrt_failure_details.is_failure_message_matching__td(
                        asrt_text_doc.is_string_for_test_that_equals(error_message)
                    )
                ),
            ),
        )
 def runTest(self):
     act_phase_instructions = [instr(['system-under-test'])]
     with home_directory_structure(contents=contents_in(
             RelHdsOptionType.REL_HDS_ACT,
             fs.DirContents([fs.executable_file('system-under-test')
                             ]))) as hds:
         environment = InstructionEnvironmentPreSdsBuilder.of_empty_env(
             hds=hds).build
         executor = self.actor.parse(act_phase_instructions)
         actual = executor.validate_pre_sds(environment)
     self.assertIs(svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS,
                   actual.status, 'Validation result')
Example #5
0
    def test_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('file-name.txt', 'file contents')])
        populator = sut.contents_in(RelHdsOptionType.REL_HDS_CASE,
                                    expected_dir_contents)
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        with home_directory_structure() as hds:
            # ACT #
            populator.populate_hds(hds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
Example #6
0
 def runTest(self):
     source_file = 'source-file.src'
     command_line = source_file
     arrangement = arrangement_w_tcds(
         hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
             Dir.empty(source_file)]))
     )
     expectation = Expectation(
         validation=ValidationExpectationSvh.fails__pre_sds()
     )
     self._check(command_line,
                 arrangement,
                 expectation)
Example #7
0
    def runTest(self):
        sub_dir_of_home = 'sub-dir'
        dir_symbol = ConstantSuffixPathDdvSymbolContext('dir_symbol_name',
                                                        RelOptionType.REL_HDS_ACT,
                                                        sub_dir_of_home,
                                                        PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)

        source_file_name_symbol = StringConstantSymbolContext('source_file_name_symbol_name',
                                                              'the-source-file.py')

        argument = 'argument_string'

        expected_output = lines_content([argument])

        command_line = '{dir}/{file_name}  {argument} '.format(
            dir=dir_symbol.name__sym_ref_syntax,
            file_name=source_file_name_symbol.name__sym_ref_syntax,
            argument=argument,
        )

        executable_file = fs.File(
            source_file_name_symbol.str_value,
            PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES)

        arrangement = arrangement_w_tcds(
            hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
                fs.Dir(sub_dir_of_home, [executable_file])
            ])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                dir_symbol,
                source_file_name_symbol,
            ])
        )

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                dir_symbol.reference_assertion__path_or_string,
                source_file_name_symbol.reference_assertion__path_component,
            ]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output,
                                                                      'CLI arguments, one per line'))
            ),
        )
        self._check(command_line,
                    arrangement,
                    expectation)
Example #8
0
 def test_populate_hds(self):
     populated_dir_contents = DirContents([File.empty('hds-file.txt')])
     the_hds_dir = RelHdsOptionType.REL_HDS_CASE
     self._check___single_and_multi(
         utils.single_line_arguments(),
         ARBITRARY_MODEL,
         parser_of_matcher_that_is_an_assertion_on_tcds(
             self,
             hds_contents_check.hds_2_tcds_assertion(
                 hds_contents_check.dir_contains_exactly(the_hds_dir,
                                                         populated_dir_contents)
             )
         ),
         arrangement_w_tcds(
             hds_contents=hds_populators.contents_in(
                 the_hds_dir,
                 populated_dir_contents)),
         Expectation(),
     )
Example #9
0
 def runTest(self):
     # ARRANGE #
     atc_file_name = 'existing-file.py'
     arg_1 = 'un-quoted'
     arg_2 = 'single quoted'
     arg_3 = 'double quoted'
     act_line_1 = '{} {} {} {}'.format(
         atc_file_name,
         arg_1,
         surrounded_by_hard_quotes(arg_2),
         surrounded_by_soft_quotes(arg_3),
     )
     atc_line_2 = ''
     act_phase_instructions = [instr([act_line_1]),
                               instr([atc_line_2])]
     executor_that_records_arguments = CommandExecutorThatRecordsArguments()
     arrangement = integration_check.arrangement_w_tcds(
         hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, DirContents([
             File.empty(atc_file_name)])),
         process_execution=ProcessExecutionArrangement(
             os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments)
         )
     )
     expected_command = asrt_command.matches_command(
         driver=asrt_command.matches_executable_file_command_driver(asrt.anything_goes()),
         arguments=asrt.matches_sequence([
             asrt_path.str_as_path(asrt_path.name_equals(atc_file_name)),
             asrt.equals(arg_1),
             asrt.equals(arg_2),
             asrt.equals(arg_3),
         ])
     )
     expectation = integration_check.Expectation(
         after_execution=ExecutedCommandAssertion(executor_that_records_arguments,
                                                  lambda tcds: expected_command)
     )
     # ACT & ASSERT #
     integration_check.check_execution(self,
                                       ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE,
                                       act_phase_instructions,
                                       arrangement,
                                       expectation)
Example #10
0
    def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(self):
        symbol = StringConstantSymbolContext('symbol_name', 'symbol value with space')

        expected_output = lines_content([symbol.str_value])

        source_file = 'the-source-file.py'

        command_line = '{source_file} {symbol}'.format(
            source_file=source_file,
            symbol=symbol.name__sym_ref_syntax,
        )

        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)
Example #11
0
    def runTest(self):
        # ARRANGE #
        exit_code_from_program = 0
        py_file = fs.File(
            'the-program',
            lines_content(py_program.exit_with_code(exit_code_from_program)),
        )
        program_symbol = ProgramSymbolContext.of_sdv(
            'PROGRAM_SYMBOL',
            program_sdvs.interpret_py_source_file_that_must_exist(
                path_sdvs.of_rel_option_with_const_file_name(
                    RelOptionType.REL_HDS_CASE,
                    py_file.name,
                )))
        program_line = args.symbol_ref_command_line(program_symbol.name).as_str

        with tmp_dir_in_path_with_files(DirContents([py_file])) as environ:
            for source_case in valid_source_variants(program_line):
                with self.subTest(source_case.name):
                    # ACT & ASSERT #
                    integration_check.check_execution(
                        self,
                        sut.actor(),
                        [instr([program_line])],
                        arrangement_w_tcds(
                            symbol_table=program_symbol.symbol_table,
                            act_exe_input=AtcExeInputArr(environ=environ),
                            hds_contents=hds_populators.contents_in(
                                RelHdsOptionType.REL_HDS_CASE,
                                DirContents([py_file])),
                        ),
                        Expectation(
                            symbol_usages=program_symbol.usages_assertion,
                            execute=asrt_eh.is_exit_code(
                                exit_code_from_program)),
                    )
Example #12
0
def _hds_pop_of(setup: TestCaseSourceSetup) -> HdsPopulator:
    return hds_populators.contents_in(RelHdsOptionType.REL_HDS_ACT,
                                      setup.home_act_dir_contents)
Example #13
0
 def populator_for_relativity_option_root__hds(
         self, contents: DirContents) -> HdsPopulator:
     return hds_populators.contents_in(self._relativity_hds, contents)
Example #14
0
def file_in_hds_act_dir(file_name: str) -> hds_populators.HdsPopulator:
    return hds_populators.contents_in(RelHdsOptionType.REL_HDS_ACT,
                                      fs.DirContents([File.empty(file_name)]))