diff tests/mockutil.py @ 120:133845647083

Better error management and removal support in baking/processing. * Baker and processor pipeline now store errors in their records. * They also support deleting output files that are no longer valid. * The basic transitional record class implements more boilerplate code. * The processor pipeline is run from the `bake` command directly. * New unit tests. * Unit test mocking now mocks `os.remove` too.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 09 Nov 2014 14:46:23 -0800
parents 3471ffa059b2
children d356f6178623
line wrap: on
line diff
--- a/tests/mockutil.py	Wed Oct 29 08:19:58 2014 -0700
+++ b/tests/mockutil.py	Sun Nov 09 14:46:23 2014 -0800
@@ -46,6 +46,7 @@
 
     def __exit__(self, exc_type, exc_value, exc_tb):
         self._entry.contents = self._stream.getvalue()
+        self._entry.metadata['mtime'] = time.time()
         self._stream.close()
 
 
@@ -197,12 +198,13 @@
         self._endMock()
 
     def _startMock(self):
+        # TODO: sadly, there seems to be no way to replace `open` everywhere?
         self._createMock('__main__.open', open, self._open, create=True)
-        # TODO: WTF, apparently the previous one doesn't really work?
         self._createMock('piecrust.records.open', open, self._open, create=True)
         self._createMock('codecs.open', codecs.open, self._codecsOpen)
         self._createMock('os.listdir', os.listdir, self._listdir)
         self._createMock('os.makedirs', os.makedirs, self._makedirs)
+        self._createMock('os.remove', os.remove, self._remove)
         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)
@@ -272,6 +274,10 @@
             raise Exception("Shouldn't create directory: %s" % path)
         self._fs._createDir(path)
 
+    def _remove(self, path):
+        path = os.path.normpath(path)
+        self._fs._deleteEntry(path)
+
     def _isdir(self, path):
         path = os.path.normpath(path)
         if path.startswith(resources_path):