comparison 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
comparison
equal deleted inserted replaced
119:0811f92cbdc7 120:133845647083
1 import os.path 1 import os.path
2 import pytest 2 import pytest
3 from piecrust.baking.baker import PageBaker, Baker 3 from piecrust.baking.baker import PageBaker, Baker
4 from piecrust.baking.records import BakeRecord
4 from .mockutil import get_mock_app, mock_fs, mock_fs_scope 5 from .mockutil import get_mock_app, mock_fs, mock_fs_scope
5 6
6 7
7 @pytest.mark.parametrize('uri, page_num, pretty, expected', [ 8 @pytest.mark.parametrize('uri, page_num, pretty, expected', [
8 # Pretty URLs 9 # Pretty URLs
69 structure = fs.getStructure('kitchen/_counter') 70 structure = fs.getStructure('kitchen/_counter')
70 assert structure == { 71 assert structure == {
71 '2010': {'01': {'01': {'post1.html': 'post one'}}}, 72 '2010': {'01': {'01': {'post1.html': 'post one'}}},
72 'index.html': 'something'} 73 'index.html': 'something'}
73 74
75 def test_removed():
76 fs = (mock_fs()
77 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page')
78 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something"))
79 with mock_fs_scope(fs):
80 app = fs.getApp()
81 baker = Baker(app)
82 baker.bake()
83 structure = fs.getStructure('kitchen/_counter')
84 assert structure == {
85 'foo.html': 'a foo page',
86 'index.html': 'something'}
87
88 os.remove(fs.path('kitchen/pages/foo.md'))
89 app = fs.getApp()
90 baker = Baker(app)
91 baker.bake()
92 structure = fs.getStructure('kitchen/_counter')
93 assert structure == {
94 'index.html': 'something'}
95
96 def test_record_version_change():
97 fs = (mock_fs()
98 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page'))
99 with mock_fs_scope(fs):
100 app = fs.getApp()
101 baker = Baker(app)
102 baker.bake()
103 mtime = os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
104
105 app = fs.getApp()
106 baker = Baker(app)
107 baker.bake()
108 assert mtime == os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
109
110 BakeRecord.RECORD_VERSION += 1
111 try:
112 app = fs.getApp()
113 baker = Baker(app)
114 baker.bake()
115 assert mtime < os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
116 finally:
117 BakeRecord.RECORD_VERSION -= 1
118