Exemplo n.º 1
0
 def test_destination_already_exists_in_destination_directory(self):
     src = 'src-file-name'
     dst = 'dst-dir-name'
     home_dir_contents = DirContents([(File.empty(src))])
     cwd_dir_contents = DirContents([Dir(dst,
                                         [File.empty(src)])])
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src),
                     defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst)
                 ).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             home_dir_contents),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             cwd_dir_contents
                         ),
                     )
                 ),
                 Expectation.phase_agnostic(
                     main_result=asrt_text_doc.is_any_text(),
                 ),
             )
Exemplo n.º 2
0
 def test_destination_already_exists__without_explicit_destination(self):
     # ARRANGE #
     file_name = 'existing-file'
     file_to_install = DirContents([(File(file_name,
                                          'contents'))])
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(file_name)
                 ).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             file_to_install),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             DirContents([File.empty(file_name)])
                         ),
                     )
                 ),
                 Expectation.phase_agnostic_2(
                     main_result=asrt_text_doc.is_any_text(),
                 )
             )
Exemplo n.º 3
0
    def test_WHEN_program_is_non_non_existing_system_command_THEN_result_SHOULD_be_error_message(self):
        failing_program_builder = program_abs_stx.TransformableProgramAbsStxBuilder(
            program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(NON_EXISTING_SYSTEM_PROGRAM)
        )
        transformer = TO_UPPER_TRANSFORMER_SYMBOL
        symbols = transformer.symbol_table

        cases = failing_program_builder.with_and_without_transformer_cases(transformer.abstract_syntax)

        for transformation_case in cases:
            instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                path_abs_stx.DefaultRelPathAbsStx('dst-file'),
                string_source_abs_stx.StringSourceOfProgramAbsStx(
                    ProcOutputFile.STDOUT,
                    transformation_case.value,
                    ignore_exit_code=False)
            )
            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,
                                  transformation=transformation_case.name):
                    checker.check__abs_stx__std_layouts_and_source_variants(
                        self,
                        instruction_syntax,
                        Arrangement.phase_agnostic(
                            symbols=symbols,
                            tcds=TcdsArrangement(),
                        ),
                        MultiSourceExpectation.phase_agnostic(
                            symbol_usages=asrt.anything_goes(),
                            main_result=IS_FAILURE,
                        )
                    )
Exemplo n.º 4
0
 def test_copy_file__destination_is_existing_directory(self):
     # ARRANGE #
     src = 'src-file'
     dst = 'dst-dir'
     file_to_install = File(src, 'contents')
     home_dir_contents = [file_to_install]
     act_dir_contents = [Dir.empty(dst)]
     act_dir_contents_after = [Dir(dst, [file_to_install])]
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check__w_source_variants(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src),
                     defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst)
                 ).as_str,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             DirContents(home_dir_contents)
                         ),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             DirContents(act_dir_contents)
                         ),
                     ),
                 ),
                 MultiSourceExpectation.phase_agnostic(
                     main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(
                         DirContents(act_dir_contents_after))
                 ),
             )
Exemplo n.º 5
0
 def test_single_file_in_root_dir(self):
     # ARRANGE #
     expected_file = File.empty('file-name.txt')
     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:
             with self.subTest(
                     relativity_option_string=rel_opt_conf.option_argument,
                     phase_is_after_act=phase_is_after_act):
                 instruction_syntax = abs_stx.without_contents(
                     rel_opt_conf.path_abs_stx_of_name(expected_file.name))
                 # 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 runTest(self):
     # ARRANGE #
     rel_conf = rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP)
     for case in successful_cases():
         dst_path = rel_conf.path_abs_stx_of_name(case.dst_file_name)
         instruction_syntax = NewDirArguments(
             dst_path,
             case.contents_syntax,
         )
         with self.subTest(case.name):
             # ACT & ASSERT #
             _CHECKER.check__abs_stx(
                 self,
                 instruction_syntax,
                 embryo_arr_exp.Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         non_hds_contents=rel_conf.populator_for_relativity_option_root__non_hds__s(
                             case.pre_existing_files
                         )
                     ),
                 ),
                 embryo_arr_exp.Expectation.phase_agnostic(
                     main_side_effects_on_sds=rel_conf.assert_root_dir_contains_exactly__p(
                         case.expected_files)
                 ),
             )
Exemplo n.º 7
0
    def runTest(self):
        sub_dir = fs.Dir.empty('sub-dir')
        top_dir = fs.Dir('top-dir', [sub_dir])

        for rel_conf in RELATIVITY_OPTIONS:
            dst_path = rel_conf.path_abs_stx_of_name__c(
                [top_dir.name, sub_dir.name])
            instruction_syntax = NewDirArguments.implicitly_empty(dst_path)
            with self.subTest(relativity=rel_conf.name):
                # ACT & ASSERT #
                _CHECKER.check__abs_stx(
                    self,
                    instruction_syntax,
                    embryo_arr_exp.Arrangement.phase_agnostic(
                        symbols=rel_conf.symbols.in_arrangement(),
                        tcds=TcdsArrangement(
                            pre_population_action=
                            SETUP_CWD_TO_NON_TCDS_DIR_ACTION)),
                    embryo_arr_exp.Expectation.phase_agnostic_3(
                        symbol_usages=rel_conf.symbols.usages_expectation(),
                        main_result=is_success(),
                        main_side_effects_on_files=TcdsExpectation(
                            sds=rel_conf.assert_root_dir_contains_exactly__p(
                                [top_dir]))),
                )
Exemplo n.º 8
0
 def test_copy_file__src_rel_non_hds(self):
     for execution_checker in _EXECUTION_CHECKERS:
         for relativity_option in source_relativity_options__non_hds():
             with self.subTest(parser=execution_checker.name,
                               relativity=relativity_option.test_case_description):
                 file_arg = relativity_option.path_argument_of_rel_name('existing-file')
                 file_to_install = DirContents([(File(file_arg.name,
                                                      'contents'))])
                 execution_checker.value.check(
                     self,
                     args.copy(file_arg).as_remaining_source,
                     Arrangement.phase_agnostic(
                         tcds=TcdsArrangement(
                             pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                             non_hds_contents=relativity_option.populator_for_relativity_option_root__non_hds(
                                 file_to_install
                             ),
                         ),
                         symbols=relativity_option.symbols.in_arrangement(),
                     ),
                     Expectation.phase_agnostic_2(
                         symbol_usages=relativity_option.symbols.usages_expectation(),
                         main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(file_to_install),
                     )
                 )
Exemplo n.º 9
0
    def _check_variants_with_expectation_type(
            self,
            args_variant_constructor: InstructionArgumentsVariantConstructor,
            expected_result_of_positive_test: PassOrFail,
            actual_file_contents: str,
            symbols: SymbolTable = None,
            expected_symbol_references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence):
        for expectation_type in ExpectationType:
            etc = expectation_type_config__non_is_success(expectation_type)
            with self.subTest(expectation_type=expectation_type):

                args_variant = args_variant_constructor.construct(expectation_type)
                complete_instruction_arguments = test_configuration.arguments_for(args_variant)

                for source in equivalent_source_variants__for_expression_parser(
                        self,
                        complete_instruction_arguments):
                    integration_check.CHECKER__PARSE_FULL.check(
                        self,
                        source,
                        model_constructor.of_str(self, actual_file_contents),
                        Arrangement(
                            tcds=TcdsArrangement(
                                post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY
                            ),
                            symbols=symbols),
                        Expectation(
                            ParseExpectation(
                                symbol_references=expected_symbol_references,
                            ),
                            ExecutionExpectation(
                                main_result=etc.main_result(expected_result_of_positive_test),
                            ),
                        )
                    )
Exemplo n.º 10
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.º 11
0
 def runTest(self):
     # ARRANGE #
     rel_conf = rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP)
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         for case in successful_cases():
             dst_path = rel_conf.path_abs_stx_of_name(case.dst_file_name)
             instruction_syntax = InstructionAbsStx(
                 dst_path,
                 case.contents_syntax,
             )
             with self.subTest(case.name,
                               phase_is_after_act=phase_is_after_act):
                 # ACT & ASSERT #
                 checker.check__abs_stx(
                     self,
                     instruction_syntax,
                     embryo_arr_exp.Arrangement.phase_agnostic(
                         symbols=SymbolContext.symbol_table_of_contexts(case.symbols),
                         tcds=TcdsArrangement(
                             non_hds_contents=rel_conf.populator_for_relativity_option_root__non_hds__s(
                                 case.pre_existing_files
                             )
                         ),
                     ),
                     embryo_arr_exp.Expectation.phase_agnostic(
                         symbol_usages=SymbolContext.usages_assertion_of_contexts(case.symbols),
                         main_result=IS_SUCCESS,
                         main_side_effects_on_sds=rel_conf.assert_root_dir_contains_exactly__p(
                             case.expected_files)
                     ),
                 )
Exemplo n.º 12
0
 def runTest(self):
     # ARRANGE #
     non_existing_leaf = fs.Dir.empty('leaf-dir')
     existing_top_dir__name = 'top-dir'
     for rel_conf in RELATIVITY_OPTIONS:
         dst_path = rel_conf.path_abs_stx_of_name__c(
             [existing_top_dir__name, non_existing_leaf.name])
         instruction_syntax = NewDirArguments.implicitly_empty(dst_path)
         # ACT & ASSERT #
         with self.subTest(relativity=rel_conf.name):
             _CHECKER.check__abs_stx(
                 self,
                 instruction_syntax,
                 embryo_arr_exp.Arrangement.phase_agnostic(
                     symbols=rel_conf.symbols.in_arrangement(),
                     tcds=TcdsArrangement(
                         pre_population_action=
                         SETUP_CWD_TO_NON_TCDS_DIR_ACTION,
                         tcds_contents=rel_conf.
                         populator_for_relativity_option_root__s(
                             [fs.Dir.empty(existing_top_dir__name)]),
                     )),
                 embryo_arr_exp.Expectation.phase_agnostic_3(
                     symbol_usages=rel_conf.symbols.usages_expectation(),
                     main_result=is_success(),
                     main_side_effects_on_files=TcdsExpectation(
                         sds=rel_conf.assert_root_dir_contains_exactly__p([
                             fs.Dir(existing_top_dir__name,
                                    [non_existing_leaf])
                         ]))),
             )
Exemplo n.º 13
0
 def test_with_explicit_non_cd_relativity_and_source_layout_variants(self):
     # ARRANGE #
     relativity = RelOptionType.REL_TMP
     for is_after_act_phase in [False, True]:
         checker = embryo_checker(is_after_act_phase)
         for case in path_name_variants.SOURCE_LAYOUT_CASES:
             path_argument = RelOptPathArgument(case.input_value,
                                                relativity)
             with self.subTest(case.name,
                               is_after_act_phase=is_after_act_phase):
                 with self.subTest(case.name):
                     # ACT & ASSERT #
                     checker.check__w_source_variants(
                         self, path_argument.as_str,
                         Arrangement.phase_agnostic(tcds=TcdsArrangement(
                             tcds_contents=tcds_populators.
                             TcdsPopulatorForRelOptionType(
                                 relativity,
                                 DirContents(
                                     [Dir.empty(case.expected_value)]))), ),
                         MultiSourceExpectation.phase_agnostic(
                             side_effects_on_tcds=CwdAssertion(
                                 relativity,
                                 case.expected_value,
                             )))
Exemplo n.º 14
0
 def test_copy_directory(self):
     src_path_arg = defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name('existing-dir')
     files_to_install = DirContents([Dir(src_path_arg.name,
                                         [File('a', 'a'),
                                          Dir('d', []),
                                          Dir('d2',
                                              [File('f', 'f')])
                                          ])])
     for execution_checker in _EXECUTION_CHECKERS:
         with self.subTest(parser=execution_checker.name):
             execution_checker.value.check(
                 self,
                 args.copy(src_path_arg).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             files_to_install),
                     ),
                 ),
                 Expectation.phase_agnostic_2(
                     main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(
                         files_to_install)
                 )
             )
Exemplo n.º 15
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.º 16
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.º 17
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.º 18
0
 def test_check_non_zero_exit_code(self):
     EXECUTION_CHECKER.check__w_source_variants(
         self,
         pgm_args.interpret_py_source_line('exit(1)').as_str,
         Arrangement.phase_agnostic(tcds=TcdsArrangement(), ),
         MultiSourceExpectation.phase_agnostic(
             main_result=result_assertions.equals(1, '')))
Exemplo n.º 19
0
 def tcds_arrangement_for_contents_of_checked_dir(
     self,
     contents: List[FileSystemElement],
 ) -> TcdsArrangement:
     return TcdsArrangement(
         tcds_contents=tcds_populators.TcdsPopulatorForRelOptionType(
             self.model_file.location,
             DirContents([Dir(self.model_file.name, contents)])), )
Exemplo n.º 20
0
 def test_check_non_zero_exit_code_with_output_to_stderr(self):
     python_program = 'import sys; sys.stderr.write("on stderr"); exit(2)'
     EXECUTION_CHECKER.check__w_source_variants(
         self,
         pgm_args.interpret_py_source_line(python_program).as_str,
         Arrangement.phase_agnostic(tcds=TcdsArrangement(), ),
         MultiSourceExpectation.phase_agnostic(
             main_result=result_assertions.equals(2, 'on stderr')))
Exemplo n.º 21
0
 def tcds_arrangement_dir_with_contents(self,
                                        checked_dir_contents: List[FileSystemElement],
                                        ) -> TcdsArrangement:
     return TcdsArrangement(
         tcds_contents=self.tcds_populator_for_dir_with_contents(
             checked_dir_contents
         ),
     )
Exemplo n.º 22
0
 def test_hds(self):
     self._check_source_and_exe_variants(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(),
         ),
         MultiSourceExpectation.phase_agnostic(
             side_effects_on_hds=asrt.IsInstance(pathlib.Path)
         ),
     )
Exemplo n.º 23
0
 def test_side_effects_on_files(self):
     self._check_source_and_exe_variants(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(),
         ),
         MultiSourceExpectation.phase_agnostic(
             main_side_effects_on_sds=asrt.IsInstance(SandboxDs)
         ),
     )
Exemplo n.º 24
0
    def runTest(self):
        # ARRANGE #
        clashing_file_name = 'clashing-file'
        non_clashing_file_name = 'non-clashing-file'

        clash_cases: Sequence[NameAndValue[FileSystemElements]] = [
            NameAndValue(
                'exists as regular',
                [fs.File.empty(clashing_file_name)],
            ),
            NameAndValue(
                'exists as dir',
                [fs.Dir.empty(clashing_file_name)],
            ),
            NameAndValue(
                'exists as sym-link to regular',
                [fs.File.empty(non_clashing_file_name),
                 fs.sym_link(clashing_file_name, non_clashing_file_name)],
            ),
            NameAndValue(
                'exists as broken sym-link',
                [fs.sym_link(clashing_file_name, non_clashing_file_name)],
            ),
        ]
        src_dir_relativity = relativity_options.conf_rel_any(RelOptionType.REL_HDS_CASE)
        src_dir_symbol = PathDdvSymbolContext.of_no_suffix(
            'SRC_PATH_SYMBOL',
            src_dir_relativity.relativity,
            accepted_relativities=RELATIVITY_VARIANTS__READ__BEFORE_ACT,
        )
        arguments_syntax = abs_stx.CopyOfDirContentsAbsStx(src_dir_symbol.abstract_syntax)
        for clash_case in clash_cases:
            with self.subTest(clash_case.name):
                # ACT & ASSERT #
                integration_check.CHECKER.check__abs_stx(
                    self,
                    arguments_syntax,
                    clash_case.value,
                    Arrangement(
                        symbols=src_dir_symbol.symbol_table,
                        tcds=TcdsArrangement(
                            tcds_contents=src_dir_relativity.populator_for_relativity_option_root__s(
                                [fs.File.empty(clashing_file_name)]
                            )
                        )
                    ),
                    Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_end_of_line(1),
                            symbol_references=src_dir_symbol.references_assertion,
                        ),
                        execution=ExecutionExpectation.is_any_hard_error()
                    ),
                )
Exemplo n.º 25
0
 def test_fail_due_to_fail_of_side_effects_on_files(self):
     self._check_source_and_exe_variants__failing_assertions(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(),
         ),
         MultiSourceExpectation.phase_agnostic(
             main_side_effects_on_sds=act_dir_contains_exactly(
                 DirContents([File.empty('non-existing-file.txt')]))
         ),
     )
Exemplo n.º 26
0
 def test_arrangement_and_expectation_of_hds_dir_contents(self):
     home_dir_contents = DirContents([File.empty('file-name.txt')])
     self._check_source_and_exe_variants(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(
                 hds_contents=hds_case_dir_contents(home_dir_contents)),
         ),
         MultiSourceExpectation.phase_agnostic(
             side_effects_on_hds=f_asrt.dir_contains_exactly(home_dir_contents)),
     )
Exemplo n.º 27
0
 def test_fail_due_to_side_effects_on_hds(self):
     self._check_source_and_exe_variants__failing_assertions(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(),
         ),
         MultiSourceExpectation.phase_agnostic(
             side_effects_on_hds=f_asrt.dir_contains_at_least(
                 DirContents([File.empty('file-name.txt')]))
         ),
     )
Exemplo n.º 28
0
    def runTest(self):
        # ARRANGE #
        text_printed_by_program = StringSymbolContext.of_constant('STRING_TO_PRINT_SYMBOL', 'hello world')

        dst_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'DST_FILE_SYMBOL',
            RelOptionType.REL_ACT,
            'dst-file-name.txt',
            sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants,
        )

        to_upper_transformer = TO_UPPER_TRANSFORMER_SYMBOL

        transformed_program_output_contents_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.name__sym_ref_syntax
                    )
                ),
                transformation=to_upper_transformer.abstract_syntax,
            )
        )
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_file_symbol.abstract_syntax,
            transformed_program_output_contents_syntax
        )
        symbols = SymbolContext.symbol_table_of_contexts([
            dst_file_symbol,
            text_printed_by_program,
            to_upper_transformer,
        ])

        # ACT & ASSERT #
        checker = integration_check.checker(False)
        checker.check__abs_stx__std_layouts_and_source_variants(
            self,
            instruction_syntax,
            Arrangement.phase_agnostic(
                symbols=symbols,
                tcds=TcdsArrangement(),
            ),
            MultiSourceExpectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_sequence([
                    dst_file_symbol.reference_assertion__path_or_string,
                    text_printed_by_program.reference_assertion__w_str_rendering,
                    to_upper_transformer.reference_assertion,
                ]),
            )
        )
Exemplo n.º 29
0
 def test_that_cwd_for_main__and__validate_post_setup_is_act_dir(self):
     instruction_that_raises_exception_if_unexpected_state = instruction_embryo_that__phase_agnostic(
         main_initial_action=utils.raise_test_error_if_cwd_is_not_act_root__env,
         validate_post_sds_initial_action=utils.raise_test_error_if_cwd_is_not_act_root__env,
     )
     self._check_source_and_exe_variants(
         ParserThatGives(instruction_that_raises_exception_if_unexpected_state),
         Arrangement.phase_agnostic(
             tcds=TcdsArrangement(),
         ),
         MultiSourceExpectation.phase_agnostic(),
     )
Exemplo n.º 30
0
    def test__with_transformer(self):
        # ARRANGE #
        src_file = fs.File('source-file.txt', 'contents of source file')
        expected_file = fs.File('a-file-name.txt', src_file.contents.upper())

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )

        src_rel_opt_conf = ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT[0]
        dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_ACT)

        expected_non_hds_contents = self._expected_non_hds_contents(
            dst_rel_opt_conf,
            expected_file,
            src_rel_opt_conf,
            src_file,
        )

        transformed_file_contents_abs_stx = 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.file_name),
            transformed_file_contents_abs_stx,
        )

        symbols = to_upper_transformer.symbol_table

        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,
                            tcds_contents=src_rel_opt_conf.
                            populator_for_relativity_option_root(
                                DirContents([src_file])),
                        ),
                        symbols=symbols,
                    ),
                    MultiSourceExpectation.phase_agnostic(
                        main_result=IS_SUCCESS,
                        main_side_effects_on_sds=expected_non_hds_contents,
                        symbol_usages=to_upper_transformer.usages_assertion,
                    ))