# HG changeset patch # User Ludovic Chabant # Date 1408471608 25200 # Node ID 644869022b6ed6dd240631e6f2d5baeaa97f1fe6 # Parent 923699e816d0f2ac6d30436b2fcb266c8e216634 Mock `os.path.isfile`, and fix a few other test utilities. diff -r 923699e816d0 -r 644869022b6e tests/mockutil.py --- 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)