Mercurial > piecrust2
diff tests/test_baking_baker.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 | dce37d1d4f05 |
line wrap: on
line diff
--- a/tests/test_baking_baker.py Wed Oct 29 08:19:58 2014 -0700 +++ b/tests/test_baking_baker.py Sun Nov 09 14:46:23 2014 -0800 @@ -1,6 +1,7 @@ import os.path import pytest from piecrust.baking.baker import PageBaker, Baker +from piecrust.baking.records import BakeRecord from .mockutil import get_mock_app, mock_fs, mock_fs_scope @@ -71,3 +72,47 @@ '2010': {'01': {'01': {'post1.html': 'post one'}}}, 'index.html': 'something'} +def test_removed(): + fs = (mock_fs() + .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page') + .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something")) + with mock_fs_scope(fs): + app = fs.getApp() + baker = Baker(app) + baker.bake() + structure = fs.getStructure('kitchen/_counter') + assert structure == { + 'foo.html': 'a foo page', + 'index.html': 'something'} + + os.remove(fs.path('kitchen/pages/foo.md')) + app = fs.getApp() + baker = Baker(app) + baker.bake() + structure = fs.getStructure('kitchen/_counter') + assert structure == { + 'index.html': 'something'} + +def test_record_version_change(): + fs = (mock_fs() + .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page')) + with mock_fs_scope(fs): + app = fs.getApp() + baker = Baker(app) + baker.bake() + mtime = os.path.getmtime(fs.path('kitchen/_counter/foo.html')) + + app = fs.getApp() + baker = Baker(app) + baker.bake() + assert mtime == os.path.getmtime(fs.path('kitchen/_counter/foo.html')) + + BakeRecord.RECORD_VERSION += 1 + try: + app = fs.getApp() + baker = Baker(app) + baker.bake() + assert mtime < os.path.getmtime(fs.path('kitchen/_counter/foo.html')) + finally: + BakeRecord.RECORD_VERSION -= 1 +