changeset 24:644869022b6e

Mock `os.path.isfile`, and fix a few other test utilities.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Aug 2014 11:06:48 -0700
parents 923699e816d0
children 65ae19c4e8a3
files tests/mockutil.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/mockutil.py	Tue Aug 19 08:34:16 2014 -0700
+++ b/tests/mockutil.py	Tue Aug 19 11:06:48 2014 -0700
@@ -129,6 +129,7 @@
         self._createMock('codecs.open', codecs.open, self._codecsOpen)
         self._createMock('os.listdir', os.listdir, self._listdir)
         self._createMock('os.path.isdir', os.path.isdir, self._isdir)
+        self._createMock('os.path.isfile', os.path.isfile, self._isfile)
         self._createMock('os.path.islink', os.path.islink, self._islink)
         self._createMock('os.path.getmtime', os.path.getmtime, self._getmtime)
         for p in self._patchers:
@@ -149,6 +150,8 @@
         e = self._getFsEntry(path)
         if e is None:
             raise OSError("No such file: %s" % path)
+        if not isinstance(e, tuple):
+            raise OSError("'%s' is not a file" % path)
         return io.StringIO(e[0])
 
     def _codecsOpen(self, path, *args, **kwargs):
@@ -158,6 +161,8 @@
         e = self._getFsEntry(path)
         if e is None:
             raise OSError("No such file: %s" % path)
+        if not isinstance(e, tuple):
+            raise OSError("'%s' is not a file" % path)
         return io.StringIO(e[0])
 
     def _listdir(self, path):
@@ -176,6 +181,12 @@
         e = self._getFsEntry(path)
         return e is not None and isinstance(e, dict)
 
+    def _isfile(self, path):
+        if not path.startswith('/' + self._root):
+            return self._originals['os.path.isfile'](path)
+        e = self._getFsEntry(path)
+        return e is not None and isinstance(e, tuple)
+
     def _islink(self, path):
         if not path.startswith('/' + self._root):
             return self._originals['os.path.islink'](path)