Mercurial > piecrust2
changeset 394:65db6df28120
tests: Also mock `open` in Jinja to be able to use templates in bake tests.
This also required raising the proper exception in the mock function. We are
now raising `IOError` and set the `errno` attribute on it.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 17 May 2015 15:28:00 -0700 |
parents | 89c1e2a91468 |
children | 9e25852f058b |
files | piecrust/sources/prose.py tests/mockutil.py |
diffstat | 2 files changed, 18 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/sources/prose.py Sun May 17 15:26:46 2015 -0700 +++ b/piecrust/sources/prose.py Sun May 17 15:28:00 2015 -0700 @@ -25,7 +25,7 @@ path = os.path.join(self.fs_endpoint_path, rel_path) try: c['title'] = get_first_line(path) - except OSError: + except IOError: if mode == MODE_PARSING: raise return c
--- a/tests/mockutil.py Sun May 17 15:26:46 2015 -0700 +++ b/tests/mockutil.py Sun May 17 15:28:00 2015 -0700 @@ -1,5 +1,6 @@ import io import time +import errno import random import codecs import shutil @@ -252,7 +253,10 @@ def _startMock(self): # TODO: sadly, there seems to be no way to replace `open` everywhere? - modules = self.open_patches + ['__main__', 'piecrust.records'] + modules = self.open_patches + [ + '__main__', + 'piecrust.records', + 'jinja2.utils'] for m in modules: self._createMock('%s.open' % m, open, self._open, create=True) @@ -296,14 +300,22 @@ e = self._getFsEntry(path) assert e is not None elif 'x' in mode: - raise OSError("File '%s' already exists" % path) + err = IOError("File '%s' already exists" % path) + err.errno = errno.EEXIST + raise err else: - raise OSError("Unsupported open mode: %s" % mode) + err = IOError("Unsupported open mode: %s" % mode) + err.errno = errno.EINVAL + raise err if e is None: - raise OSError("No such file: %s" % path) + err = IOError("No such file: %s" % path) + err.errno = errno.ENOENT + raise err if not isinstance(e, _MockFsEntry): - raise OSError("'%s' is not a file %s" % (path, e)) + err = IOError("'%s' is not a file %s" % (path, e)) + err.errno = errno.EISDIR + raise err return _MockFsEntryWriter(e, mode)