comparison tests/test_sources_base.py @ 411:e7b865f8f335

bake: Enable multiprocess baking. Baking is now done by running a worker per CPU, and sending jobs to them. This changes several things across the codebase: * Ability to not cache things related to pages other than the 'main' page (i.e. the page at the bottom of the execution stack). * Decouple the baking process from the bake records, so only the main process keeps track (and modifies) the bake record. * Remove the need for 'batch page getters' and loading a page directly from the page factories. There are various smaller changes too included here, including support for scope performance timers that are saved with the bake record and can be printed out to the console. Yes I got carried away. For testing, the in-memory 'mock' file-system doesn't work anymore, since we're spawning processes, so this is replaced by a 'tmpfs' file-system which is saved in temporary files on disk and deleted after tests have run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 12 Jun 2015 17:09:19 -0700
parents dd25bd3ce1f9
children f987b29d6fab
comparison
equal deleted inserted replaced
410:d1a472464e57 411:e7b865f8f335
4 from piecrust.sources.pageref import PageRef, PageNotFoundError 4 from piecrust.sources.pageref import PageRef, PageNotFoundError
5 from .mockutil import mock_fs, mock_fs_scope 5 from .mockutil import mock_fs, mock_fs_scope
6 from .pathutil import slashfix 6 from .pathutil import slashfix
7 7
8 8
9 @pytest.mark.parametrize('fs, expected_paths, expected_slugs', [ 9 @pytest.mark.parametrize('fs_fac, expected_paths, expected_slugs', [
10 (mock_fs(), [], []), 10 (lambda: mock_fs(), [], []),
11 (mock_fs().withPage('test/foo.html'), 11 (lambda: mock_fs().withPage('test/foo.html'),
12 ['foo.html'], ['foo']), 12 ['foo.html'], ['foo']),
13 (mock_fs().withPage('test/foo.md'), 13 (lambda: mock_fs().withPage('test/foo.md'),
14 ['foo.md'], ['foo']), 14 ['foo.md'], ['foo']),
15 (mock_fs().withPage('test/foo.ext'), 15 (lambda: mock_fs().withPage('test/foo.ext'),
16 ['foo.ext'], ['foo.ext']), 16 ['foo.ext'], ['foo.ext']),
17 (mock_fs().withPage('test/foo/bar.html'), 17 (lambda: mock_fs().withPage('test/foo/bar.html'),
18 ['foo/bar.html'], ['foo/bar']), 18 ['foo/bar.html'], ['foo/bar']),
19 (mock_fs().withPage('test/foo/bar.md'), 19 (lambda: mock_fs().withPage('test/foo/bar.md'),
20 ['foo/bar.md'], ['foo/bar']), 20 ['foo/bar.md'], ['foo/bar']),
21 (mock_fs().withPage('test/foo/bar.ext'), 21 (lambda: mock_fs().withPage('test/foo/bar.ext'),
22 ['foo/bar.ext'], ['foo/bar.ext']), 22 ['foo/bar.ext'], ['foo/bar.ext']),
23 ]) 23 ])
24 def test_default_source_factories(fs, expected_paths, expected_slugs): 24 def test_default_source_factories(fs_fac, expected_paths, expected_slugs):
25 fs = fs_fac()
25 fs.withConfig({ 26 fs.withConfig({
26 'site': { 27 'site': {
27 'sources': { 28 'sources': {
28 'test': {}}, 29 'test': {}},
29 'routes': [ 30 'routes': [
129 fs = mock_fs() 130 fs = mock_fs()
130 with mock_fs_scope(fs): 131 with mock_fs_scope(fs):
131 app = fs.getApp() 132 app = fs.getApp()
132 r = PageRef(app, 'whatever:doesnt_exist.md') 133 r = PageRef(app, 'whatever:doesnt_exist.md')
133 with pytest.raises(Exception): 134 with pytest.raises(Exception):
134 r.possible_rel_paths 135 r.possible_ref_specs
135 136
136 137
137 def test_page_ref_with_missing_file(): 138 def test_page_ref_with_missing_file():
138 fs = mock_fs() 139 fs = mock_fs()
139 with mock_fs_scope(fs): 140 with mock_fs_scope(fs):
140 app = fs.getApp() 141 app = fs.getApp()
141 r = PageRef(app, 'pages:doesnt_exist.%ext%') 142 r = PageRef(app, 'pages:doesnt_exist.%ext%')
142 assert r.possible_rel_paths == [ 143 assert r.possible_ref_specs == [
143 'doesnt_exist.html', 'doesnt_exist.md', 'doesnt_exist.textile'] 144 'pages:doesnt_exist.html', 'pages:doesnt_exist.md',
144 assert r.source_name == 'pages' 145 'pages:doesnt_exist.textile']
146 with pytest.raises(PageNotFoundError):
147 r.source_name
145 with pytest.raises(PageNotFoundError): 148 with pytest.raises(PageNotFoundError):
146 r.rel_path 149 r.rel_path
147 with pytest.raises(PageNotFoundError): 150 with pytest.raises(PageNotFoundError):
148 r.path 151 r.path
149 assert not r.exists 152 assert not r.exists