Skip to content

Commit

Permalink
mockfs.mfs: Update docstrings to reference the Python standard library
Browse files Browse the repository at this point in the history
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Apr 19, 2010
1 parent c477b9e commit a8b408c
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions mockfs/mfs.py
Expand Up @@ -8,10 +8,9 @@

class MockFS(object):
"""
The main MockFS implementation
MockFS implementation object
Provides stubs for functions in ``os``, ``os.path``,
and ``glob``.
Provides stubs for functions in :mod:`os`, :mod:`os.path`, and :mod:`glob`.
"""

Expand All @@ -28,20 +27,57 @@ def add_entries(self, entries):
util.merge_dicts(new_entries, self._entries)

def exists(self, path):
"""
Return True if path exists
Implements the :func:`os.path.exists` interface.
"""
path = util.sanitize(path)
dirent = self._direntry(os.path.dirname(path))
if path == '/':
return bool(dirent)
return bool(dirent) and os.path.basename(path) in dirent

def isdir(self, path):
"""
Return True if path is a directory
Implements the :func:`os.path.isdir` interface.
"""
path = util.sanitize(path)
return type(self._direntry(path)) is dict

def isfile(self, path):
"""
Return True if path is a file
Implements the :func:`os.path.isfile` interface.
"""
return not self.isdir(path)

def islink(self, path):
"""
Return True if path is a symlink
.. note::
Currently hard-wired to return False
"""
path = util.sanitize(path)
return False

def listdir(self, path):
"""
Return the directory contents of 'path'
Implements the :func:`os.listdir` interface.
:param path: filesystem path
"""
path = util.sanitize(path)
direntry = self._direntry(path)
if direntry:
Expand All @@ -50,11 +86,13 @@ def listdir(self, path):
return entries
return []

def islink(self, path):
path = util.sanitize(path)
return False

def walk(self, path):
"""
Walk a filesystem path
Implements the :func:`os.walk` interface.
"""
path = util.sanitize(path)
entries = []
inspect = [path]
Expand All @@ -78,6 +116,7 @@ def walk(self, path):
raise StopIteration

def _direntry(self, path):
"""Return the directory "dict" entry for a path"""
path = util.sanitize(path)
if path == '/':
return self._entries
Expand Down

0 comments on commit a8b408c

Please sign in to comment.