# HG changeset patch # User Ludovic Chabant # Date 1431901680 25200 # Node ID 65db6df281201e9431e611b2ccfbe1a7e77bfb01 # Parent 89c1e2a91468ce623dfeefb1379476ea4639da77 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. diff -r 89c1e2a91468 -r 65db6df28120 piecrust/sources/prose.py --- 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 diff -r 89c1e2a91468 -r 65db6df28120 tests/mockutil.py --- 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)