Пример #1
0
    def _is_valid_source(self, source):
        if not source.exists():
            self.errors.add(error.NoSuchFileOrDirectory(self.subcmd, source))
            return False

        elif (not utils.is_file_readable(source)
              or not utils.is_directory_readable(source)):
            self.errors.add(error.InsufficientPermissions(self.subcmd, source))
            return False

        return True
Пример #2
0
    def _is_valid_dest(self, dest):
        if not dest.parent.exists():
            self.errors.add(
                error.NoSuchFileOrDirectory(self.subcmd, dest.parent))
            return False

        elif (not utils.is_file_writable(dest.parent)
              or not utils.is_directory_writable(dest.parent)):
            self.errors.add(
                error.InsufficientPermissionsToSubcmdTo(self.subcmd, dest))
            return False

        return True
Пример #3
0
    def get_directory_contents(self, directory):
        """
        Get the contents of a directory while handling errors that may occur
        """
        contents = []

        try:
            contents = utils.get_directory_contents(directory)
        except PermissionError:
            self.errors.add(error.PermissionDenied(self.subcmd, directory))
        except FileNotFoundError:
            self.errors.add(
                error.NoSuchFileOrDirectory(self.subcmd, directory))
        except NotADirectoryError:
            self.errors.add(error.NoSuchDirectory(self.subcmd, directory))

        return contents
Пример #4
0
def test_link_with_non_existant_dest(source_a):
    non_existant_dest = 'dest'
    with pytest.raises(FileNotFoundError) as e:
        dploy.link(source_a, os.path.join(non_existant_dest, 'source_a_link'))
    assert error.NoSuchFileOrDirectory(
        subcmd=SUBCMD, file=non_existant_dest).msg in str(e.value)
Пример #5
0
def test_link_with_non_existant_dest(source_a):
    non_existant_dest = 'dest'
    message = str(
        error.NoSuchFileOrDirectory(subcmd=SUBCMD, file=non_existant_dest))
    with pytest.raises(error.NoSuchFileOrDirectory, match=message):
        dploy.link(source_a, os.path.join(non_existant_dest, 'source_a_link'))