Exemplo n.º 1
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)
Exemplo n.º 2
0
 def test_single_file_in_existing_sub_dir(self):
     sub_dir_name = 'sub-dir'
     expected_file = File.empty('file-name.txt')
     dst_file_name = '/'.join([sub_dir_name, expected_file.name])
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES:
             instruction_syntax = abs_stx.without_contents(
                 rel_opt_conf.path_abs_stx_of_name(dst_file_name))
             with self.subTest(
                     relativity_option_string=rel_opt_conf.option_argument):
                 checker.check__abs_stx__std_layouts_and_source_variants(
                     self, instruction_syntax,
                     Arrangement.phase_agnostic(tcds=TcdsArrangement(
                         pre_population_action=
                         SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN,
                         non_hds_contents=rel_opt_conf.
                         populator_for_relativity_option_root__non_hds(
                             fs.DirContents([Dir.empty(sub_dir_name)])),
                     ), ),
                     MultiSourceExpectation.phase_agnostic(
                         main_result=IS_SUCCESS,
                         side_effects_on_hds=f_asrt.dir_is_empty(),
                         symbol_usages=asrt.is_empty_sequence,
                         main_side_effects_on_sds=
                         non_hds_dir_contains_exactly(
                             rel_opt_conf.root_dir__non_hds,
                             fs.DirContents(
                                 [fs.Dir(sub_dir_name, [expected_file])])),
                     ))
Exemplo n.º 3
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = fs.File('src-file_name-file.txt', 'contents')
        home_dir_contents = fs.DirContents([src_file])
        expected_destination_dir_contents = fs.DirContents(
            [fs.File(dst_file_name, src_file.contents)])

        src_rel_option = defs.ARBITRARY_SRC_REL_OPT
        dst_rel_option = defs.ARBITRARY_DST_REL_OPT
        # ACT & ASSERT #
        self.conf.run_test(
            self,
            args.copy(src_rel_option.path_argument_of_rel_name(src_file.name),
                      dst_rel_option.path_argument_of_rel_name(
                          dst_file_name)).as_remaining_source,
            self.conf.arrangement(hds_contents=src_rel_option.
                                  populator_for_relativity_option_root__hds(
                                      home_dir_contents), ),
            self.conf.expect_success(
                main_side_effects_on_sds=sds_contents_check.
                non_hds_dir_contains_exactly(
                    dst_rel_option.root_dir__non_hds,
                    expected_destination_dir_contents), ),
        )
Exemplo n.º 4
0
 def _expected_non_hds_contents(
         dst_file_rel_opt_conf: RelativityOptionConfigurationForRelNonHds,
         dst_file: fs.File,
         src_file_rel_opt_conf: RelativityOptionConfiguration,
         src_file: fs.File) -> Assertion:
     if ((dst_file_rel_opt_conf.option_argument_str
          == src_file_rel_opt_conf.option_string
          and src_file_rel_opt_conf.option_string != '')
             or (dst_file_rel_opt_conf.is_rel_cwd
                 and src_file_rel_opt_conf.is_rel_cwd)):
         return dst_file_rel_opt_conf.assert_root_dir_contains_exactly(
             fs.DirContents([dst_file, src_file]))
     else:
         return dst_file_rel_opt_conf.assert_root_dir_contains_exactly(
             fs.DirContents([dst_file]))
Exemplo n.º 5
0
 def test_contents_from_here_doc(self):
     # ARRANGE #
     string_value = rich_str_abs_stx.HereDocAbsStx(
         'single line in here doc\n')
     expected_file = fs.File('a-file-name.txt', string_value.value)
     rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY
     dst_path = rel_opt_conf.path_abs_stx_of_name(expected_file.name)
     instruction_syntax = instr_abs_stx.create_w_explicit_contents(
         dst_path,
         string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
     )
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         with self.subTest(phase_is_after_act=phase_is_after_act):
             # ACT & ASSERT #
             checker.check__abs_stx__std_layouts_and_source_variants(
                 self, instruction_syntax,
                 Arrangement.phase_agnostic(tcds=TcdsArrangement(
                     pre_population_action=
                     SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ),
                 MultiSourceExpectation.phase_agnostic(
                     main_result=IS_SUCCESS,
                     side_effects_on_hds=f_asrt.dir_is_empty(),
                     symbol_usages=asrt.is_empty_sequence,
                     main_side_effects_on_sds=non_hds_dir_contains_exactly(
                         rel_opt_conf.root_dir__non_hds,
                         fs.DirContents([expected_file])),
                 ))
Exemplo n.º 6
0
    def test_symbol_reference_in_dst_file_argument(self):
        dst_path_symbol = ConstantSuffixPathDdvSymbolContext(
            'dst_path_symbol', RelOptionType.REL_ACT, 'dst-file.txt',
            ACCEPTED_DST_RELATIVITY_VARIANTS)
        string_value = rich_str_abs_stx.HereDocAbsStx(
            'single line in here doc\n')
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_path_symbol.abstract_syntax,
            string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
        )

        expected_file = fs.File(dst_path_symbol.path_suffix,
                                string_value.value)
        integration_check.CHECKER__BEFORE_ACT.check__abs_stx(
            self, instruction_syntax,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    pre_population_action=
                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                symbols=dst_path_symbol.symbol_table,
            ),
            Expectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_singleton_sequence(
                    dst_path_symbol.reference_assertion),
                main_side_effects_on_sds=dir_contains_exactly(
                    dst_path_symbol.rel_option_type,
                    fs.DirContents([expected_file])),
            ))
Exemplo n.º 7
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])

        executable_file_name = 'the-executable_file_name'

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

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable_file_name,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = 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=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Exemplo n.º 8
0
    def test_possibility_to_have_sds_path_references_in_argument(self):
        file_name_of_referenced_file = 'file-name.txt'
        symbol = ConstantSuffixPathDdvSymbolContext(
            'symbol_name', RelOptionType.REL_TMP, file_name_of_referenced_file)

        executable = 'the-executable'

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

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = Expectation(
            execute=eh_assertions.is_exit_code(0),
            symbol_usages=asrt.matches_singleton_sequence(
                symbol.reference_assertion__w_str_rendering),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(
                    str_asrt.contains(file_name_of_referenced_file))),
        )

        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Exemplo n.º 9
0
    def test_success_when_executable_does_exist(self):
        for relativity_option_conf in RELATIVITY_OPTIONS:
            argument = '{relativity_option} {executable_file}'.format(
                relativity_option=relativity_option_conf.option_argument,
                executable_file=EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0.
                file_name,
            )

            expectation = MultiSourceExpectation.phase_agnostic(
                symbol_usages=asrt.matches_sequence(
                    relativity_option_conf.symbols.
                    usage_expectation_assertions()), )

            arrangement = Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    tcds_contents=relativity_option_conf.
                    populator_for_relativity_option_root(
                        fs.DirContents(
                            [EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0])), ),
                symbols=relativity_option_conf.symbols.in_arrangement(),
            )
            with self.subTest(
                    option=relativity_option_conf.test_case_description):
                EXECUTION_CHECKER.check__w_source_variants(
                    self, argument, arrangement, expectation)
Exemplo n.º 10
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)
Exemplo n.º 11
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),
             )
Exemplo n.º 12
0
 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)])))
Exemplo n.º 13
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)
Exemplo n.º 14
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),
             )
Exemplo n.º 15
0
 def runTest(self):
     exe_file = fs.python_executable_file('program-name',
                                          py_programs.exit_with(0))
     cases = [
         NameAndValue(
             'pre sds',
             (
                 RelOptionType.REL_HDS_CASE,
                 self.conf.expect_failing_validation_pre_sds(),
             ),
         ),
         NameAndValue(
             'post sds',
             (
                 RelOptionType.REL_ACT,
                 self.conf.expect_hard_error_of_main__any(),
             ),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             arguments = sys_cmd.command_line(
                 exe_file.name,
                 program_arguments.existing_file(
                     path_arguments.RelOptPathArgument(
                         'non-existing', case.value[0])),
             )
             with tmp_dir_in_path_with_files(fs.DirContents([exe_file
                                                             ])) as env:
                 self.conf.run_single_line_test_with_source_variants_and_source_check(
                     self,
                     arguments.as_str,
                     self.conf.arrangement(environ=env),
                     case.value[1],
                 )
Exemplo n.º 16
0
def dir_contains_exactly_2(
        expected_contents: FileSystemElements) -> Assertion[pathlib.Path]:
    """
    Assumes that the actual value is a pathlib.Path
    """
    return DirContainsExactly(
        file_structure.DirContents(list(expected_contents)))
Exemplo n.º 17
0
    def test_validate_should_fail_when_executable_does_not_exist(self):
        existing_file_to_interpret = 'existing-file-to-interpret.src'
        home_dir_contents = fs.DirContents(
            [File.empty(existing_file_to_interpret)])
        for relativity_option_conf in RELATIVITY_OPTIONS:
            argument = '{relativity_option} non-existing-file {interpret_option}' \
                       ' {rel_hds_case_option} {existing_file}'.format(
                relativity_option=relativity_option_conf.option_argument,
                interpret_option=syntax_elements.EXISTING_FILE_OPTION_NAME,
                rel_hds_case_option=REL_HDS_CASE_OPTION,
                existing_file=existing_file_to_interpret,
            )

            expectation = _expect_validation_error_and_symbol_usages_of(
                relativity_option_conf)

            arrangement = Arrangement.phase_agnostic(
                symbols=relativity_option_conf.symbols.in_arrangement(),
                tcds=TcdsArrangement(
                    hds_contents=hds_case_dir_contents(home_dir_contents), ),
            )
            with self.subTest(msg='option=' +
                              relativity_option_conf.test_case_description):
                EXECUTION_CHECKER.check__w_source_variants(
                    self, argument, arrangement, expectation)
Exemplo n.º 18
0
    def test_two_populators_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([self.first_file,
                                                self.second_file])
        first_populator = sut.hds_case_dir_contents(fs.DirContents([self.first_file]))
        second_populator = sut.hds_case_dir_contents(fs.DirContents([self.second_file]))
        populator = sut.multiple([first_populator,
                                  second_populator])
        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')
Exemplo n.º 19
0
 def __init__(self, contents: str):
     super().__init__(_dir_file_space_that_must_not_be_used_getter)
     self.contents = contents
     file_with_contents = fs.File('model-file.txt', self.contents)
     relativity = RelOptionType.REL_TMP
     self._ddv = path_ddvs.simple_of_rel_option(relativity,
                                                file_with_contents.name)
     self._tcds_populator = tcds_populators.TcdsPopulatorForRelOptionType(
         relativity, fs.DirContents([file_with_contents]))
Exemplo n.º 20
0
    def test_success_when_referenced_files_does_exist(self):
        symbol_name_for_executable_file = 'EXECUTABLE_FILE_SYMBOL_NAME'
        symbol_name_for_source_file = 'SOURCE_FILE_SYMBOL_NAME'
        source_file = File.empty('source-file.src')
        for roc_executable_file in relativity_options_of_symbol(
                symbol_name_for_executable_file):
            for roc_source_file in relativity_options_of_symbol(
                    symbol_name_for_source_file):
                argument = '{relativity_option_executable} {executable_file} {interpret_option}' \
                           ' {relativity_option_source_file} {source_file}'.format(
                    relativity_option_executable=roc_executable_file.option_argument,
                    relativity_option_source_file=roc_source_file.option_argument,
                    executable_file=EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0.file_name,
                    interpret_option=args.option(syntax_elements.EXISTING_FILE_OPTION_NAME).as_str,
                    source_file=source_file.file_name,
                )

                expectation = MultiSourceExpectation.phase_agnostic(
                    symbol_usages=asrt.matches_sequence(
                        roc_executable_file.symbols.
                        usage_expectation_assertions() +
                        roc_source_file.symbols.usage_expectation_assertions()
                    ), )

                arrangement = Arrangement.phase_agnostic(
                    tcds=TcdsArrangement(tcds_contents=multiple([
                        roc_executable_file.
                        populator_for_relativity_option_root(
                            fs.DirContents(
                                [EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0])),
                        roc_source_file.populator_for_relativity_option_root(
                            fs.DirContents([source_file])),
                    ]), ),
                    symbols=SymbolContext.symbol_table_of_contexts(
                        roc_executable_file.symbols.contexts_for_arrangement()
                        + roc_source_file.symbols.contexts_for_arrangement()),
                )
                test_name = 'exe-file-option={}, source-file-option={}'.format(
                    roc_executable_file.test_case_description,
                    roc_source_file.test_case_description,
                )
                with self.subTest(msg=test_name):
                    EXECUTION_CHECKER.check__w_source_variants(
                        self, argument, arrangement, expectation)
Exemplo n.º 21
0
    def runTest(self):
        # ARRANGE #

        src_file = fs.File('source-file.txt', 'contents of source file')
        src_rel_opt_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE)

        expected_file = fs.File('a-file-name.txt', src_file.contents.upper())
        dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_ACT)

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            to_uppercase(),
        )
        symbols = to_upper_transformer.symbol_table

        transformed_file_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(
                src_rel_opt_conf.path_abs_stx_of_name(src_file.name)),
            to_upper_transformer.abstract_syntax,
        )
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_rel_opt_conf.path_abs_stx_of_name(expected_file.name),
            transformed_file_syntax,
        )

        expected_non_hds_contents = dst_rel_opt_conf.assert_root_dir_contains_exactly(
            fs.DirContents([expected_file]))

        instruction_checker = self.conf.instruction_checker
        parser = self.conf.parser()
        for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
                instruction_syntax):
            with self.subTest(source_case.name):
                source = source_case.value.source
                # ACT #
                instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                # ASSERT #
                source_case.value.expectation.apply_with_message(
                    self, source, 'source-after-parse')
                # ACT & ASSERT #
                instruction_checker.check(
                    self, instruction,
                    self.conf.arrangement(
                        pre_contents_population_action=
                        SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR,
                        tcds_contents=src_rel_opt_conf.
                        populator_for_relativity_option_root(
                            DirContents([src_file])),
                        symbols=symbols,
                    ),
                    self.conf.expect_success(
                        symbol_usages=asrt.matches_sequence([
                            to_upper_transformer.reference_assertion,
                        ]),
                        main_side_effects_on_sds=expected_non_hds_contents,
                    ))
Exemplo n.º 22
0
 def test_executable_file_must_be_executable(self):
     executable_file_name = 'existing-executable'
     act_phase_instructions = [instr([executable_file_name])]
     arrangement = arrangement_w_tcds(
         hds_contents=relativity_configurations.ATC_FILE.
         populator_for_relativity_option_root__hds(
             fs.DirContents([File.empty(executable_file_name)])))
     expectation = Expectation(
         validation=ValidationExpectationSvh.fails__pre_sds())
     check_execution(self, sut.actor(), act_phase_instructions, arrangement,
                     expectation)
Exemplo n.º 23
0
 def runTest(self):
     exe_file = fs.python_executable_file('program-name',
                                          py_programs.exit_with(0))
     with tmp_dir_in_path_with_files(fs.DirContents([exe_file])) as env:
         instruction_argument = exe_file.name
         self.conf.run_single_line_test_with_source_variants_and_source_check(
             self,
             instruction_argument,
             self.conf.arrangement(environ=env),
             self.conf.expectation_for_zero_exitcode(),
         )
Exemplo n.º 24
0
    def runTest(self):
        text_printed_by_program = 'single line of output'

        expected_file_contents = text_printed_by_program.upper()
        expected_file = fs.File('dst-file.txt', expected_file_contents)

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TO_UPPER_CASE',
            to_uppercase(),
        )
        symbols = to_upper_transformer.symbol_table

        dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_TMP)

        program_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
            ProcOutputFile.STDOUT,
            program_abs_stx.FullProgramAbsStx(
                program_abs_stx.ProgramOfPythonInterpreterAbsStx.
                of_execute_python_src_string(
                    py_programs.single_line_pgm_that_prints_to(
                        ProcOutputFile.STDOUT, text_printed_by_program)),
                transformation=to_upper_transformer.abstract_syntax,
            ))
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_rel_opt_conf.path_abs_stx_of_name(expected_file.name),
            program_syntax,
        )

        instruction_checker = self.conf.instruction_checker
        parser = self.conf.parser()
        for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
                instruction_syntax):
            with self.subTest(source_case.name):
                source = source_case.value.source
                # ACT #
                instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                # ASSERT #
                source_case.value.expectation.apply_with_message(
                    self, source, 'source-after-parse')
                # ACT & ASSERT #
                instruction_checker.check(
                    self, instruction,
                    self.conf.arrangement(
                        pre_contents_population_action=
                        SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR,
                        symbols=symbols),
                    self.conf.expect_success(
                        symbol_usages=asrt.matches_sequence([
                            to_upper_transformer.reference_assertion,
                        ]),
                        main_side_effects_on_sds=non_hds_dir_contains_exactly(
                            dst_rel_opt_conf.root_dir__non_hds,
                            fs.DirContents([expected_file])),
                    ))
Exemplo n.º 25
0
    def test_that_populator_is_applied(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('file-name.txt', 'file contents')])
        populator = hds_populators.hds_case_dir_contents(expected_dir_contents)
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        # ACT #
        with home_directory_structure(contents=populator) as hds:
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of home/case dir')
Exemplo n.º 26
0
    def test_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('file-name.txt', 'file contents')])
        populator = sut.hds_case_dir_contents(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')
Exemplo n.º 27
0
    def test_no_populators_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([])
        populator = sut.multiple([])
        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')
 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')
Exemplo n.º 29
0
def _to_upper_command(empty_tmp_dir: Path, exit_code: int) -> Command:
    py_program = fs.File(
        'to-upper.py',
        _to_upper_stdin_py_program_w_exit_code(exit_code))
    fs.DirContents([py_program]).write_to(empty_tmp_dir)

    return Command(
        CommandDriverForExecutableFile(
            described_path.new_primitive(Path(sys.executable))
        ),
        [str(empty_tmp_dir / py_program.name)]
    )
Exemplo n.º 30
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = fs.File('src-file_name-file.txt', 'contents')
        home_dir_contents = fs.DirContents([src_file])
        expected_destination_dir_contents = fs.DirContents(
            [fs.File(dst_file_name, src_file.contents)])

        src_rel_option = rel_opt_conf.symbol_conf_rel_hds(
            defs.ARBITRARY_LEGAL_RELATIVITY__SRC__HDS,
            'SRC_SYMBOL',
            defs.path_relativity_variants__src(self.conf.phase_is_after_act()),
        )
        dst_rel_option = rel_opt_conf.symbol_conf_rel_non_hds(
            defs.ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS,
            'DST_SYMBOL',
            defs.PATH_RELATIVITY_VARIANTS__DST,
        )
        # ACT & ASSERT #
        self.conf.run_test(
            self,
            args.copy(src_rel_option.path_argument_of_rel_name(src_file.name),
                      dst_rel_option.path_argument_of_rel_name(
                          dst_file_name)).as_remaining_source,
            self.conf.arrangement(
                hds_contents=src_rel_option.
                populator_for_relativity_option_root__hds(home_dir_contents),
                symbols=SymbolContext.symbol_table_of_contexts(
                    src_rel_option.symbols.contexts_for_arrangement() +
                    dst_rel_option.symbols.contexts_for_arrangement())),
            self.conf.expect_success(
                symbol_usages=asrt.matches_sequence(
                    src_rel_option.symbols.usage_expectation_assertions() +
                    dst_rel_option.symbols.usage_expectation_assertions()),
                main_side_effects_on_sds=sds_contents_check.
                non_hds_dir_contains_exactly(
                    dst_rel_option.root_dir__non_hds,
                    expected_destination_dir_contents),
            ),
        )