Mercurial > piecrust2
diff tests/test_sources_posts.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 | cb6eadea0845 |
children | 45ad976712ec |
line wrap: on
line diff
--- a/tests/test_sources_posts.py Sat May 30 15:41:52 2015 -0700 +++ b/tests/test_sources_posts.py Fri Jun 12 17:09:19 2015 -0700 @@ -1,44 +1,45 @@ -import os import pytest from .mockutil import mock_fs, mock_fs_scope -@pytest.mark.parametrize('fs, src_type, expected_paths, expected_metadata', [ - (mock_fs(), 'flat', [], []), - (mock_fs().withPage('test/2014-01-01_foo.md'), +@pytest.mark.parametrize('fs_fac, src_type, expected_paths, expected_metadata', [ + (lambda: mock_fs(), 'flat', [], []), + (lambda: mock_fs().withPage('test/2014-01-01_foo.md'), 'flat', ['2014-01-01_foo.md'], [(2014, 1, 1, 'foo')]), - (mock_fs(), 'shallow', [], []), - (mock_fs().withPage('test/2014/01-01_foo.md'), + (lambda: mock_fs(), 'shallow', [], []), + (lambda: mock_fs().withPage('test/2014/01-01_foo.md'), 'shallow', ['2014/01-01_foo.md'], [(2014, 1, 1, 'foo')]), - (mock_fs(), 'hierarchy', [], []), - (mock_fs().withPage('test/2014/01/01_foo.md'), + (lambda: mock_fs(), 'hierarchy', [], []), + (lambda: mock_fs().withPage('test/2014/01/01_foo.md'), 'hierarchy', ['2014/01/01_foo.md'], [(2014, 1, 1, 'foo')]), ]) -def test_post_source_factories(fs, src_type, expected_paths, expected_metadata): - fs.withConfig({ - 'site': { - 'sources': { - 'test': {'type': 'posts/%s' % src_type}}, - 'routes': [ - {'url': '/%slug%', 'source': 'test'}] - } - }) - fs.withDir('kitchen/test') - with mock_fs_scope(fs): - app = fs.getApp(cache=False) - s = app.getSource('test') - facs = list(s.buildPageFactories()) - paths = [f.rel_path for f in facs] - assert paths == expected_paths - metadata = [ - (f.metadata['year'], f.metadata['month'], - f.metadata['day'], f.metadata['slug']) - for f in facs] - assert metadata == expected_metadata +def test_post_source_factories(fs_fac, src_type, expected_paths, + expected_metadata): + fs = fs_fac() + fs.withConfig({ + 'site': { + 'sources': { + 'test': {'type': 'posts/%s' % src_type}}, + 'routes': [ + {'url': '/%slug%', 'source': 'test'}] + } + }) + fs.withDir('kitchen/test') + with mock_fs_scope(fs): + app = fs.getApp(cache=False) + s = app.getSource('test') + facs = list(s.buildPageFactories()) + paths = [f.rel_path for f in facs] + assert paths == expected_paths + metadata = [ + (f.metadata['year'], f.metadata['month'], + f.metadata['day'], f.metadata['slug']) + for f in facs] + assert metadata == expected_metadata