Mercurial > piecrust2
annotate tests/test_baking_baker.py @ 1051:971b4d67e82a
serve: Fix problems with assets disappearing between servings.
When an asset file changes, its source's pipeline is re-run. But that created
a bake record that only had that pipeline's output, so the other outputs were
incorrectly considered empty and therefore any stray files were removed. Now we
copy over bake records for the pipelines we don't run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 26 Jan 2018 18:05:02 -0800 |
parents | 298b07a899b5 |
children |
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 |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
49 print("\n\n\n") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
50 fs.runChef('bake') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
51 structure = fs.getStructure('kitchen/_counter') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
52 assert structure['index.html'] == 'Second\nFirst\n' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
53 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
54 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
55 |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
56 print("\n\n\n") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
57 fs.runChef('bake') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
58 structure = fs.getStructure('kitchen/_counter') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
59 assert structure['index.html'] == 'Second\nFirst\n' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
60 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
61 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
62 |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
63 print("\n\n\n") |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
64 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
65 structure = fs.getStructure('kitchen/_counter') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
70 |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
71 def test_bake_four_times_again(): |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
72 fs = (mock_fs() |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
73 .withConfig({'site': { |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
74 'default_format': 'none', |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
75 'default_page_layout': 'none', |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
76 'default_post_layout': 'none', |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
77 }}) |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
78 .withPage('pages/_index.html', {'layout': 'none', 'format': 'none'}, |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
79 "{% for p in pagination.posts -%}\n" |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
80 "{{p.title}} : {{p.content}}\n" |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
81 "{% endfor %}") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
82 .withPage('posts/2017-01-01_first.html', {'title': "First"}, |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
83 "something 1") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
84 .withPage('posts/2017-01-02_second.html', {'title': "Second"}, |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
85 "something 2")) |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
86 with mock_fs_scope(fs): |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
87 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
88 structure = fs.getStructure('kitchen/_counter') |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
89 assert structure['index.html'] == 'Second : something 2\nFirst : something 1\n' |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
90 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
|
91 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
|
92 |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
93 print("\n\n\n") |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
94 fs.runChef('bake') |
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
95 structure = fs.getStructure('kitchen/_counter') |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
96 assert structure['index.html'] == 'Second : something 2\nFirst : something 1\n' |
991
1857dbd4580f
bake: Fix bugs introduced by bake optimizations, of course.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
97 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
|
98 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
|
99 |
1020
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
100 print("\n\n\n") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
101 fs.runChef('bake') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
102 structure = fs.getStructure('kitchen/_counter') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
103 assert structure['index.html'] == 'Second : something 2\nFirst : something 1\n' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
104 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
105 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
106 |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
107 print("\n\n\n") |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
108 fs.runChef('bake') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
109 structure = fs.getStructure('kitchen/_counter') |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
110 assert structure['index.html'] == 'Second : something 2\nFirst : something 1\n' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
111 assert structure['2017']['01']['01']['first.html'] == 'something 1' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
112 assert structure['2017']['01']['02']['second.html'] == 'something 2' |
298b07a899b5
bake: Fix overriding issues between theme and user pages for index pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
991
diff
changeset
|
113 |