Пример #1
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(),
                 )
             )
Пример #2
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)
                 )
             )
Пример #3
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))
                 ),
             )
Пример #4
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), ),
        )
Пример #5
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(),
                 ),
             )
Пример #6
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),
                     )
                 )
Пример #7
0
def legal_relativities_specific_for_phases_after_act(
) -> Sequence[NameAndValue[ArgumentElementsRenderer]]:
    src_legal = RelOptionType.REL_RESULT
    return [
        NameAndValue(
            'legal src:{}'.format(src_legal),
            args.copy(
                RelOptPathArgument('src-file-name', src_legal),
                RelOptPathArgument('dst-file-name',
                                   defs.ARBITRARY_LEGAL_RELATIVITY__DST)),
        )
    ]
Пример #8
0
def illegal_relativities_specific_for_phase_before_act(
) -> Sequence[NameAndValue[ArgumentElementsRenderer]]:
    dst_illegal_relativities = {RelOptionType.REL_RESULT}
    return [
        NameAndValue(
            'illegal dst relativity: {}'.format(dst_illegal),
            args.copy(
                RelOptPathArgument('src-file-name',
                                   defs.ARBITRARY_LEGAL_RELATIVITY__SRC),
                RelOptPathArgument('dst-file-name', dst_illegal)))
        for dst_illegal in dst_illegal_relativities
    ]
Пример #9
0
def illegal_relativities_independent_of_phase(
) -> Sequence[NameAndValue[ArgumentElementsRenderer]]:
    dst_illegal_relativities = DEPENDENCY_DICT[DirectoryStructurePartition.HDS]
    return [
        NameAndValue(
            'illegal dst relativity: {}'.format(dst_illegal),
            args.copy(
                RelOptPathArgument('src-file-name',
                                   defs.ARBITRARY_LEGAL_RELATIVITY__SRC),
                RelOptPathArgument('dst-file-name', dst_illegal)))
        for dst_illegal in dst_illegal_relativities
    ]
Пример #10
0
 def runTest(self):
     # ARRANGE #
     src_file_arg = RelOptPathArgument('non-existing-file',
                                       RelOptionType.REL_ACT)
     dst_file_arg = RelOptPathArgument('non-existing-file',
                                       defs.ARBITRARY_LEGAL_RELATIVITY__DST)
     arguments_cases = [
         NameAndValue(
             'without dst arg',
             args.copy(src_file_arg),
         ),
         NameAndValue(
             'with dst arg',
             args.copy(src_file_arg, dst_file_arg),
         ),
     ]
     for arguments_case in arguments_cases:
         with self.subTest(arguments_case.name):
             # ACT & ASSERT #
             self.conf.run_single_line_test_with_source_variants_and_source_check(
                 self, arguments_case.value.as_str, self.conf.arrangement(),
                 self.conf.expect_hard_error_of_main__any())
Пример #11
0
def legal_relativities_independent_of_phase(
) -> Sequence[NameAndValue[ArgumentElementsRenderer]]:
    src_legal_relativities = (set(RelOptionType) - {RelOptionType.REL_RESULT})
    dst_legal_relativities = (
        DEPENDENCY_DICT[DirectoryStructurePartition.NON_HDS] -
        {RelOptionType.REL_RESULT})

    ret_val = []
    ret_val += [
        NameAndValue(
            'only src:{}'.format(relativity),
            args.copy(RelOptPathArgument('src-file-name', relativity)))
        for relativity in src_legal_relativities
    ]
    ret_val += [
        NameAndValue(
            'src:{}, dst:{}'.format(src_relativity, dst_relativity),
            args.copy(RelOptPathArgument('src-file-name', src_relativity),
                      RelOptPathArgument('dst-file-name', dst_relativity)))
        for src_relativity in src_legal_relativities
        for dst_relativity in dst_legal_relativities
    ]
    return ret_val
Пример #12
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = File('src-file_name-file.txt', 'contents')
        home_dir_contents = DirContents([src_file])
        expected_destination_dir_contents = DirContents([File(dst_file_name, src_file.contents)])

        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,
        )
        for phase_is_after_act in [False, True]:
            with self.subTest(phase_is_after_act=phase_is_after_act):
                checker = instruction_embryo_check.Checker(sut.EmbryoParser(phase_is_after_act))
                src_rel_option = rel_opt_conf.symbol_conf_rel_hds(
                    defs.ARBITRARY_LEGAL_RELATIVITY__SRC__HDS,
                    'SRC_SYMBOL',
                    defs.path_relativity_variants__src(phase_is_after_act),
                )
                # ACT & ASSERT #
                checker.check(
                    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,
                    Arrangement.phase_agnostic(
                        tcds=TcdsArrangement(
                            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()
                        )
                    ),
                    Expectation.phase_agnostic_2(
                        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),

                    ),
                )
Пример #13
0
 def test_ERROR_when_file_does_not_exist__without_explicit_destination__hds(self):
     for execution_checker in _EXECUTION_CHECKERS:
         for relativity_option in source_relativity_options__hds():
             with self.subTest(parser=execution_checker.name,
                               relativity=relativity_option.test_case_description):
                 execution_checker.value.check(
                     self,
                     args.copy(
                         relativity_option.path_argument_of_rel_name('source-that-do-not-exist')
                     ).as_remaining_source,
                     Arrangement.phase_agnostic(
                         tcds=TcdsArrangement(),
                         symbols=relativity_option.symbols.in_arrangement(),
                     ),
                     Expectation.phase_agnostic_2(
                         validation=ValidationAssertions.pre_sds_fails__w_any_msg(),
                         symbol_usages=relativity_option.symbols.usages_expectation(),
                     ),
                 )
Пример #14
0
 def _sub_test__copy_file(
         self,
         src_rel_option: rel_opt_conf.RelativityOptionConfigurationRelHds,
         dst_rel_option: rel_opt_conf.RelativityOptionConfigurationForRelNonHds,
         src_file_name: str,
         dst_file_name: str,
         expected_destination_dir_contents: DirContents,
         sds_populator_before_main: sds_populator.SdsPopulator,
         hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
 ):
     arguments = args.copy(src_rel_option.path_argument_of_rel_name(src_file_name),
                           dst_rel_option.path_argument_of_rel_name(dst_file_name))
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name,
                           arguments=arguments.as_str):
             symbols_in_arrangement = SymbolContext.symbol_table_of_contexts(
                 src_rel_option.symbols.contexts_for_arrangement() +
                 dst_rel_option.symbols.contexts_for_arrangement()
             )
             expected_symbol_usages = asrt.matches_sequence(
                 src_rel_option.symbols.usage_expectation_assertions() +
                 dst_rel_option.symbols.usage_expectation_assertions()
             )
             parser_case.value.check__w_source_variants(
                 self,
                 arguments.as_str,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=hds_contents,
                         sds_contents=sds_populator_before_main,
                     ),
                     symbols=symbols_in_arrangement,
                 ),
                 MultiSourceExpectation.phase_agnostic(
                     symbol_usages=expected_symbol_usages,
                     main_result=asrt.is_none,
                     main_side_effects_on_sds=sds_contents_check.non_hds_dir_contains_exactly(
                         dst_rel_option.root_dir__non_hds,
                         expected_destination_dir_contents),
                 ),
             )
Пример #15
0
 def runTest(self):
     # ARRANGE #
     src_relativity_option = defs.DEFAULT_SRC_REL_OPT
     file_arg = src_relativity_option.path_argument_of_rel_name(
         'existing-file')
     file_to_install = fs.DirContents([fs.File(file_arg.name, 'contents')])
     # ACT & ASSERT #
     self.conf.run_single_line_test_with_source_variants_and_source_check(
         self,
         args.copy(file_arg).as_str,
         self.conf.arrangement(
             hds_contents=src_relativity_option.
             populator_for_relativity_option_root__hds(file_to_install),
             symbols=src_relativity_option.symbols.in_arrangement(),
         ),
         self.conf.expect_success(
             main_side_effects_on_sds=sds_contents_check.
             cwd_contains_exactly(file_to_install),
             symbol_usages=src_relativity_option.symbols.usages_expectation(
             ),
         ))
Пример #16
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),
            ),
        )
Пример #17
0
 def test_copy_directory__destination_is_existing_directory(self):
     # ARRANGE #
     src_dir = 'existing-dir'
     dst_dir = 'existing-dst-dir'
     files_to_install = [Dir(src_dir,
                             [File('a', 'a'),
                              Dir('d', []),
                              Dir('d2',
                                  [File('f', 'f')])
                              ])]
     cwd_dir_contents_before = DirContents([Dir.empty(dst_dir)])
     cwd_dir_contents_after = DirContents([Dir(dst_dir, files_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_dir),
                     defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst_dir)
                 ).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(files_to_install)
                         ),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             cwd_dir_contents_before
                         ),
                     ),
                 ),
                 MultiSourceExpectation.phase_agnostic(
                     main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(
                         cwd_dir_contents_after)
                 ),
             )