Mercurial > piecrust2
annotate tests/test_baking_baker.py @ 1014:071f30aa04bb
bake: Do template caching in a background job if possible.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 28 Nov 2017 21:28:15 -0800 |
parents | 1857dbd4580f |
children | 298b07a899b5 |
rev | line source |
---|---|
989
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import time |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from .mockutil import get_mock_app, mock_fs, mock_fs_scope |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 def test_bake_and_add_post(): |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 fs = (mock_fs() |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 .withConfig() |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 .withPage('pages/_index.html', {'layout': 'none', 'format': 'none'}, |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 "{% for p in pagination.posts -%}\n" |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 "{{p.title}}\n" |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 "{% endfor %}") |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 .withPage('posts/2017-01-01_first.html', {'title': "First"}, |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 "something")) |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 with mock_fs_scope(fs): |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 fs.runChef('bake') |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 structure = fs.getStructure('kitchen/_counter') |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 assert structure['index.html'] == 'First\n' |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 time.sleep(1) |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 fs.withPage('posts/2017-01-02_second.html', {'title': "Second"}, |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 "something else") |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 fs.runChef('bake') |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 structure = fs.getStructure('kitchen/_counter') |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 assert structure['index.html'] == 'Second\nFirst\n' |
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
26 |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
27 def test_bake_four_times(): |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
28 fs = (mock_fs() |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
29 .withConfig({'site': { |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
30 'default_format': 'none', |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
31 'default_page_layout': 'none', |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
32 'default_post_layout': 'none', |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
33 }}) |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
34 .withPage('pages/_index.html', {'layout': 'none', 'format': 'none'}, |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
35 "{% for p in pagination.posts -%}\n" |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
36 "{{p.title}}\n" |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
37 "{% endfor %}") |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
38 .withPage('posts/2017-01-01_first.html', {'title': "First"}, |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
39 "something 1") |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
40 .withPage('posts/2017-01-02_second.html', {'title': "Second"}, |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
41 "something 2")) |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
42 with mock_fs_scope(fs): |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
43 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
44 structure = fs.getStructure('kitchen/_counter') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
45 assert structure['index.html'] == 'Second\nFirst\n' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
46 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
47 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
48 |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
49 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
50 structure = fs.getStructure('kitchen/_counter') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
51 assert structure['index.html'] == 'Second\nFirst\n' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
52 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
53 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
54 |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
55 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
56 structure = fs.getStructure('kitchen/_counter') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
57 assert structure['index.html'] == 'Second\nFirst\n' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
58 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
59 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
60 |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
61 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
62 structure = fs.getStructure('kitchen/_counter') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
63 assert structure['index.html'] == 'Second\nFirst\n' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
64 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
65 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
66 |