mockfs.util.is_dir

Here are the examples of the python api mockfs.util.is_dir taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: mockfs Source File: mfs.py
    def read(self, path):
        path = self.abspath(path)
        dirname = os.path.dirname(path)
        basename = os.path.basename(path)
        entry = self._direntry(dirname)
        if not util.is_dir(entry):
            raise _OSError(errno.EPERM, path)

        try:
            return entry[basename]
        except KeyError:
            raise _OSError(errno.ENOENT, path)

Example 2

Project: mockfs Source File: mfs.py
Function: is_dir
    def isdir(self, path):
        """
        Return True if path is a directory

        Implements the :func:`os.path.isdir` interface.

        """
        return util.is_dir(self._direntry(path))

Example 3

Project: mockfs Source File: mfs.py
Function: chdir
    def chdir(self, path):
        # Make it absolute
        if os.path.isabs(path):
            cdpath = path
        else:
            cdpath = os.path.join(self._cwd, path)

        entry = self._mfs._direntry(path)
        if entry is None:
            raise _OSError(errno.ENOENT, path)
        elif not util.is_dir(entry):
            raise _OSError(errno.ENOTDIR, path)

        self._cwd = _abspath_builtin(cdpath)

Example 4

Project: mockfs Source File: mfs.py
Function: remove
    def remove(self, path):
        """Remove the entry for a file path

        Implements the :func:`os.remove` interface.

        """
        path = self.abspath(path)
        dirname = os.path.dirname(path)
        basename = os.path.basename(path)
        entry = self._direntry(dirname)
        if not util.is_dir(entry):
            raise _OSError(errno.EPERM, path)

        try:
            fsentry = entry[basename]
        except KeyError:
            raise _OSError(errno.ENOENT, path)

        if not util.is_file(fsentry):
            raise _OSError(errno.EPERM, path)

        del entry[basename]

Example 5

Project: mockfs Source File: mfs.py
Function: rm_dir
    def rmdir(self, fspath):
        """Remove the entry for a directory path

        Implements the :func:`os.rmdir` interface.

        """
        path = self.abspath(fspath)
        dirname = os.path.dirname(path)
        basename = os.path.basename(path)
        entry = self._direntry(dirname)
        if not util.is_dir(entry):
            raise _OSError(errno.ENOENT, path)

        try:
            direntry = entry[basename]
        except KeyError:
            raise _OSError(errno.ENOENT, fspath)

        if not util.is_dir(direntry):
            raise _OSError(errno.ENOTDIR, fspath)

        if len(direntry) != 0:
            raise _OSError(errno.ENOTEMPTY, fspath)

        del entry[basename]