annotate tests/test_baking_baker.py @ 113:de257cc40ce1

Re-enable proper caching of rendered segments in server. The server keeps records on files that are processed while the server is running. Disk caching is simply disabled for files that are known to use other pages -- because unlike the baker, there's no cheap way to know which files are up to date or not, and rendering is faster enough anyway.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 19 Oct 2014 00:30:44 -0700
parents 3471ffa059b2
children 133845647083
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
617191dec18e Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
1 import os.path
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pytest
85
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
3 from piecrust.baking.baker import PageBaker, Baker
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
4 from .mockutil import get_mock_app, mock_fs, mock_fs_scope
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 @pytest.mark.parametrize('uri, page_num, pretty, expected', [
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 # Pretty URLs
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 ('', 1, True, 'index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 ('', 2, True, '2/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 ('foo', 1, True, 'foo/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 ('foo', 2, True, 'foo/2/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 ('foo/bar', 1, True, 'foo/bar/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 ('foo/bar', 2, True, 'foo/bar/2/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 ('foo.ext', 1, True, 'foo.ext/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 ('foo.ext', 2, True, 'foo.ext/2/index.html'),
29
7e44f6092a1d More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
17 ('foo/bar.ext', 1, True, 'foo/bar.ext/index.html'),
7e44f6092a1d More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
18 ('foo/bar.ext', 2, True, 'foo/bar.ext/2/index.html'),
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 ('foo.bar.ext', 1, True, 'foo.bar.ext/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 ('foo.bar.ext', 2, True, 'foo.bar.ext/2/index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 # Ugly URLs
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 ('', 1, False, 'index.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 ('', 2, False, '2.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 ('foo', 1, False, 'foo.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 ('foo', 2, False, 'foo/2.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 ('foo/bar', 1, False, 'foo/bar.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 ('foo/bar', 2, False, 'foo/bar/2.html'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 ('foo.ext', 1, False, 'foo.ext'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 ('foo.ext', 2, False, 'foo/2.ext'),
29
7e44f6092a1d More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
30 ('foo/bar.ext', 1, False, 'foo/bar.ext'),
7e44f6092a1d More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
31 ('foo/bar.ext', 2, False, 'foo/bar/2.ext'),
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 ('foo.bar.ext', 1, False, 'foo.bar.ext'),
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 ('foo.bar.ext', 2, False, 'foo.bar/2.ext')
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 ])
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 def test_get_output_path(uri, page_num, pretty, expected):
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 app = get_mock_app()
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 if pretty:
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 app.config.set('site/pretty_urls', True)
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 assert app.config.get('site/pretty_urls') == pretty
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 baker = PageBaker(app, '/destination')
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 sub_uri = baker.getOutputUri(uri, page_num)
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 path = baker.getOutputPath(sub_uri)
11
617191dec18e Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
44 expected = os.path.normpath(
617191dec18e Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
45 os.path.join('/destination', expected))
6
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 assert expected == path
f5ca5c5bed85 More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47
85
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
48
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
49 def test_empty_bake():
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
50 fs = mock_fs()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
51 with mock_fs_scope(fs):
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
52 assert not os.path.isdir(fs.path('kitchen/_counter'))
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
53 app = fs.getApp()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
54 baker = Baker(app)
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
55 baker.bake()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
56 assert os.path.isdir(fs.path('kitchen/_counter'))
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
57 structure = fs.getStructure('kitchen/_counter')
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
58 assert list(structure.keys()) == ['index.html']
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
59
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
60
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
61 def test_simple_bake():
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
62 fs = (mock_fs()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
63 .withPage('posts/2010-01-01_post1.md', {'layout': 'none', 'format': 'none'}, 'post one')
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
64 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something"))
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
65 with mock_fs_scope(fs):
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
66 app = fs.getApp()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
67 baker = Baker(app)
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
68 baker.bake()
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
69 structure = fs.getStructure('kitchen/_counter')
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
70 assert structure == {
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
71 '2010': {'01': {'01': {'post1.html': 'post one'}}},
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
72 'index.html': 'something'}
3471ffa059b2 Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 29
diff changeset
73