comparison tests/test_sources_posts.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents e7b865f8f335
children 22e767899e52
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
1 import os.path
1 import pytest 2 import pytest
2 from .mockutil import mock_fs, mock_fs_scope 3 from .mockutil import mock_fs, mock_fs_scope
3 4
4 5
5 @pytest.mark.parametrize('fs_fac, src_type, expected_paths, expected_metadata', [ 6 @pytest.mark.parametrize(
7 'fs_fac, src_type, expected_paths, expected_metadata',
8 [
6 (lambda: mock_fs(), 'flat', [], []), 9 (lambda: mock_fs(), 'flat', [], []),
7 (lambda: mock_fs().withPage('test/2014-01-01_foo.md'), 10 (lambda: mock_fs().withPage('test/2014-01-01_foo.md'),
8 'flat', 11 'flat',
9 ['2014-01-01_foo.md'], 12 ['2014-01-01_foo.md'],
10 [(2014, 1, 1, 'foo')]), 13 [(2014, 1, 1, 'foo')]),
16 (lambda: mock_fs(), 'hierarchy', [], []), 19 (lambda: mock_fs(), 'hierarchy', [], []),
17 (lambda: mock_fs().withPage('test/2014/01/01_foo.md'), 20 (lambda: mock_fs().withPage('test/2014/01/01_foo.md'),
18 'hierarchy', 21 'hierarchy',
19 ['2014/01/01_foo.md'], 22 ['2014/01/01_foo.md'],
20 [(2014, 1, 1, 'foo')]), 23 [(2014, 1, 1, 'foo')]),
21 ]) 24 ])
22 def test_post_source_factories(fs_fac, src_type, expected_paths, 25 def test_post_source_items(fs_fac, src_type, expected_paths,
23 expected_metadata): 26 expected_metadata):
24 fs = fs_fac() 27 fs = fs_fac()
25 fs.withConfig({ 28 fs.withConfig({
26 'site': { 29 'site': {
27 'sources': { 30 'sources': {
28 'test': {'type': 'posts/%s' % src_type}}, 31 'test': {'type': 'posts/%s' % src_type}},
29 'routes': [ 32 'routes': [
30 {'url': '/%slug%', 'source': 'test'}] 33 {'url': '/%slug%', 'source': 'test'}]
31 } 34 }
32 }) 35 })
33 fs.withDir('kitchen/test') 36 fs.withDir('kitchen/test')
34 with mock_fs_scope(fs): 37 with mock_fs_scope(fs):
35 app = fs.getApp(cache=False) 38 app = fs.getApp()
36 s = app.getSource('test') 39 s = app.getSource('test')
37 facs = list(s.buildPageFactories()) 40 items = list(s.getAllContents())
38 paths = [f.rel_path for f in facs] 41 paths = [os.path.relpath(f.spec, s.fs_endpoint_path) for f in items]
39 assert paths == expected_paths 42 assert paths == expected_paths
40 metadata = [ 43 metadata = [
41 (f.metadata['year'], f.metadata['month'], 44 (f.metadata['route_params']['year'],
42 f.metadata['day'], f.metadata['slug']) 45 f.metadata['route_params']['month'],
43 for f in facs] 46 f.metadata['route_params']['day'],
47 f.metadata['route_params']['slug'])
48 for f in items]
44 assert metadata == expected_metadata 49 assert metadata == expected_metadata
45 50