Пример #1
0
def test_unstow_with_read_only_dest(source_a, dest):
    dploy.stow([source_a], dest)
    utils.remove_write_permission(dest)
    message = str(
        error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest))
    with pytest.raises(error.InsufficientPermissionsToSubcmdTo, match=message):
        dploy.unstow([source_a], dest)
Пример #2
0
def test_unstow_folding_with_existing_file_in_dest(source_a, source_b, dest):
    os.mkdir(os.path.join(dest, 'aaa'))
    a_file = os.path.join(dest, 'aaa', 'a_file')
    utils.create_file(a_file)
    dploy.stow([source_a, source_b], dest)
    dploy.unstow([source_a], dest)
    assert os.path.exists(a_file)
Пример #3
0
def test_unstow_with_read_only_dest(source_a, dest):
    dploy.stow([source_a], dest)
    utils.remove_write_permission(dest)
    with pytest.raises(PermissionError) as e:
        dploy.unstow([source_a], dest)
    assert error.InsufficientPermissionsToSubcmdTo(
        subcmd=SUBCMD, file=dest).msg in str(e.value)
Пример #4
0
def test_unstow_with_write_only_source(source_a, dest):
    dploy.stow([source_a], dest)
    utils.remove_read_permission(source_a)
    with pytest.raises(PermissionError) as e:
        dploy.unstow([source_a], dest)
    assert (error.InsufficientPermissionsToSubcmdFrom(subcmd=SUBCMD,
                                                      file=source_a).msg
            in str(e.value))
Пример #5
0
def test_unstow_folding_with_multiple_sources_with_execute_permission_unset(
        source_a, source_b, dest):
    dploy.stow([source_a, source_b], dest)
    utils.remove_execute_permission(source_b)
    dest_dir = os.path.join(dest, 'aaa', 'ddd')
    message = str(error.PermissionDenied(subcmd=SUBCMD, file=dest_dir))
    with pytest.raises(error.PermissionDenied, match=message):
        dploy.unstow([source_a], dest)
Пример #6
0
def test_unstow_with_dest_dir_with_no_executue_permissions(
        source_a, source_b, dest):
    dest_dir = os.path.join(dest, 'aaa')
    dploy.stow([source_a, source_b], dest)
    utils.remove_execute_permission(os.path.join(dest, 'aaa'))
    message = str(
        error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest_dir))
    with pytest.raises(error.InsufficientPermissionsToSubcmdTo, match=message):
        dploy.unstow([source_a, source_b], dest)
Пример #7
0
def test_unstow_folding_with_multiple_sources_with_execute_permission_unset(
        source_a, source_b, dest):
    dploy.stow([source_a, source_b], dest)
    utils.remove_execute_permission(source_b)
    with pytest.raises(PermissionError) as e:
        dploy.unstow([source_a], dest)
    dest_dir = os.path.join(dest, 'aaa', 'ddd')
    assert error.PermissionDenied(subcmd=SUBCMD,
                                  file=dest_dir).msg in str(e.value)
Пример #8
0
def test_unstow_with_dest_dir_with_no_executue_permissions(
        source_a, source_b, dest):
    dest_dir = os.path.join(dest, 'aaa')
    dploy.stow([source_a, source_b], dest)
    utils.remove_execute_permission(os.path.join(dest, 'aaa'))
    with pytest.raises(PermissionError) as e:
        dploy.unstow([source_a, source_b], dest)
    assert error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD,
                                                   file=dest_dir).msg in str(
                                                       e.value)
Пример #9
0
def test_unstow_with_a_broken_link_dest(source_a, dest):
    conflicting_link = os.path.join(dest, 'aaa')
    source_file = os.path.join(source_a, 'aaa')
    os.symlink('non_existant_source', os.path.join(dest, 'aaa'))
    with pytest.raises(ValueError) as e:
        dploy.unstow([source_a], dest)
    assert (error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                            source=source_file,
                                            dest=conflicting_link).msg
            in str(e.value))
Пример #10
0
def test_unstow_with_a_broken_link_dest(source_a, dest):
    conflicting_link = os.path.join(dest, 'aaa')
    source_file = os.path.join(source_a, 'aaa')
    os.symlink('non_existant_source', os.path.join(dest, 'aaa'))

    message = str(
        error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                        source=source_file,
                                        dest=conflicting_link))

    with pytest.raises(error.ConflictsWithExistingLink, match=message):
        dploy.unstow([source_a], dest)
Пример #11
0
 def use(self, package=None, **_kwargs):
     self.check_if_r2env_initialized()
     if not package:
         self.list_installed_packages()
         raise R2EnvException("Package not defined.")
     if package not in self._package_manager.list_installed_packages():
         raise R2EnvException(f"Package {package} not installed.")
     cur_ver = self._get_current_version()
     new_dst_dir = self._package_manager.get_package_path(package)
     if cur_ver:
         unstow([self._package_manager.get_package_path(cur_ver)],
                self._r2env_path)
     stow([new_dst_dir], self._r2env_path)
     self._set_current_version(package)
     print_console(f"[*] Using {package} package")
Пример #12
0
def test_unstow_folding_with_stray_symlink_in_unfolded_dest_dir(
        source_a, source_b, source_d, dest):
    """
    Given a dest directory with stowed packages that share a unfolded directory,
    that also contains a stray link along with the links created by stowing.

    When the stowed packages are unstowed

    Then the folded directory remains with the single stray symlink
    """
    stray_path = os.path.join(dest, 'aaa', 'ggg')
    dploy.stow([source_a, source_b], dest)
    dploy.link(os.path.join(source_d, 'aaa', 'ggg'), stray_path)
    dploy.unstow([source_a, source_b], dest)
    assert os.path.islink(stray_path)
Пример #13
0
def test_unstow_dwith_basic_senario_doesnt_delete_dest_directory(
        source_a, dest):
    dploy.stow([source_a], dest)
    dploy.unstow([source_a], dest)
    assert os.path.exists(dest)
Пример #14
0
def test_unstow_with_file_as_source(file_a, dest):
    message = str(error.NoSuchDirectory(subcmd=SUBCMD, file=file_a))
    with pytest.raises(error.NoSuchDirectory, match=message):
        dploy.unstow([file_a], dest)
Пример #15
0
def test_unstow_with_file_as_source_and_dest(file_a, file_b):
    with pytest.raises(NotADirectoryError) as e:
        dploy.unstow([file_a], file_b)
    assert (error.NoSuchDirectoryToSubcmdInto(subcmd=SUBCMD, file=file_b).msg
            in str(e.value))
Пример #16
0
def test_unstow_with_non_existant_dest(source_a):
    dest = 'dest'
    with pytest.raises(NotADirectoryError) as e:
        dploy.unstow([source_a], dest)
    assert error.NoSuchDirectoryToSubcmdInto(subcmd=SUBCMD,
                                             file=dest).msg in str(e.value)
Пример #17
0
def test_unstow_with_non_existant_source(dest):
    source = 'source'
    with pytest.raises(NotADirectoryError) as e:
        dploy.unstow([source], dest)
    assert error.NoSuchDirectory(subcmd=SUBCMD,
                                 file=source).msg in str(e.value)
Пример #18
0
def test_unstow_folding_basic(source_a, source_b, dest):
    dploy.stow([source_a, source_b], dest)
    dploy.unstow([source_b], dest)
    assert os.path.islink(os.path.join(dest, 'aaa'))
Пример #19
0
def test_unstow_with_same_simple_directory_used_as_source_and_dest(
        source_only_files):
    with pytest.raises(ValueError) as e:
        dploy.unstow([source_only_files], source_only_files)
    assert error.SourceIsSameAsDest(subcmd=SUBCMD,
                                    file=source_only_files).msg in str(e.value)
Пример #20
0
def test_unstow_with_same_directory_used_as_source_and_dest(source_a):
    with pytest.raises(ValueError) as e:
        dploy.unstow([source_a], source_a)
    assert utils.is_subcmd_error_message('unstow', e)
Пример #21
0
def test_unstow_with_write_only_dest_file(source_a, dest):
    dploy.stow([source_a], dest)
    utils.remove_read_permission(os.path.join(dest, 'aaa'))
    dploy.unstow([source_a], dest)
Пример #22
0
def test_unstow_with_non_existant_dest(source_a):
    dest = 'dest'
    message = str(error.NoSuchDirectoryToSubcmdInto(subcmd=SUBCMD, file=dest))
    with pytest.raises(error.NoSuchDirectoryToSubcmdInto, match=message):
        dploy.unstow([source_a], dest)
Пример #23
0
def test_unstow_with_broken_link_in_dest(source_a, dest):
    os.mkdir(os.path.join(dest, 'aaa'))
    dploy.stow([source_a], dest)
    os.symlink(os.path.join(source_a, 'non_existant_source'),
               os.path.join(dest, 'aaa', 'non_existant_source'))
    dploy.unstow([source_a], dest)
Пример #24
0
def test_unstow_with_duplicate_source(source_a, dest):
    dploy.stow([source_a], dest)
    message = str(error.DuplicateSource(subcmd=SUBCMD, file=source_a))
    with pytest.raises(error.DuplicateSource, match=message):
        dploy.unstow([source_a, source_a], dest)
Пример #25
0
def test_unstow_with_duplicate_source(source_a, dest):
    dploy.stow([source_a], dest)
    with pytest.raises(ValueError) as e:
        dploy.unstow([source_a, source_a], dest)
    assert error.DuplicateSource(subcmd=SUBCMD,
                                 file=source_a).msg in str(e.value)
Пример #26
0
def test_unstow_folding_with_multiple_stowed_sources(source_a, source_b,
                                                     source_d, dest):
    dploy.stow([source_a, source_b, source_d], dest)
    dploy.unstow([source_b], dest)
    assert not os.path.islink(os.path.join(dest, 'aaa'))
Пример #27
0
def test_unstow_with_file_as_source(file_a, dest):
    with pytest.raises(NotADirectoryError) as e:
        dploy.unstow([file_a], dest)
    assert error.NoSuchDirectory(subcmd=SUBCMD,
                                 file=file_a).msg in str(e.value)
Пример #28
0
def test_unstow_folding_with_multiple_sources_all_unstowed(
        source_a, source_b, dest):
    dploy.stow([source_a, source_b], dest, is_silent=False)
    dploy.unstow([source_a, source_b], dest, is_silent=False)
    assert not os.path.exists(os.path.join(dest, 'aaa'))
Пример #29
0
def test_unstow_with_basic_senario(source_a, dest):
    dploy.stow([source_a], dest)
    dploy.unstow([source_a], dest)
    assert not os.path.exists(os.path.join(dest, 'aaa'))
Пример #30
0
def test_unstow_with_file_as_source_and_dest(file_a, file_b):
    message = str(error.NoSuchDirectoryToSubcmdInto(subcmd=SUBCMD,
                                                    file=file_b))
    with pytest.raises(error.NoSuchDirectoryToSubcmdInto, match=message):
        dploy.unstow([file_a], file_b)