annotate tests/test_sources_autoconfig.py @ 436:2aa879d63133

tests: Add pipeline processing tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 27 Jun 2015 21:48:26 -0700
parents e7b865f8f335
children 72f17534d58e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import pytest
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 from piecrust.sources.base import MODE_PARSING
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from .mockutil import mock_fs, mock_fs_scope
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 267
diff changeset
4 from .pathutil import slashfix
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 @pytest.mark.parametrize(
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
8 'fs_fac, src_config, expected_paths, expected_metadata',
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 [
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
10 (lambda: mock_fs(), {}, [], []),
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
11 (lambda: mock_fs().withPage('test/_index.md'),
267
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
12 {},
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
13 ['_index.md'],
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
14 [{'slug': '', 'config': {'foo': []}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
15 (lambda: mock_fs().withPage('test/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 [{'slug': 'something', 'config': {'foo': []}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
19 (lambda: mock_fs().withPage('test/bar/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 [{'slug': 'something', 'config': {'foo': ['bar']}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
23 (lambda: mock_fs().withPage('test/bar1/bar2/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 ['bar1/bar2/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 [{'slug': 'something', 'config': {'foo': ['bar1', 'bar2']}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
28 (lambda: mock_fs().withPage('test/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 [{'slug': 'something', 'config': {'foo': None}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
32 (lambda: mock_fs().withPage('test/bar/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 [{'slug': 'something', 'config': {'foo': 'bar'}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
36 (lambda: mock_fs().withPage('test/bar1/bar2/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 ['bar1/bar2/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 [{'slug': 'something', 'config': {'foo': ['bar1', 'bar2']}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
41 (lambda: mock_fs().withPage('test/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 {'only_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 [{'slug': 'something', 'config': {'foo': None}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
45 (lambda: mock_fs().withPage('test/bar/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 {'only_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 [{'slug': 'something', 'config': {'foo': 'bar'}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 ])
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
50 def test_autoconfig_source_factories(fs_fac, src_config, expected_paths,
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 expected_metadata):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 'test': {'type': 'autoconfig',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 site_config['sources']['test'].update(src_config)
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
61 fs = fs_fac()
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 facs = list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 paths = [f.rel_path for f in facs]
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 267
diff changeset
69 assert paths == slashfix(expected_paths)
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 metadata = [f.metadata for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 assert metadata == expected_metadata
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 def test_autoconfig_fails_if_multiple_folders():
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 'test': {'type': 'autoconfig',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 'setting_name': 'foo',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 'only_single_values': True}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 fs = mock_fs().withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 fs.withPage('test/bar1/bar2/something.md')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 with pytest.raises(Exception):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 @pytest.mark.parametrize(
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
92 'fs_fac, expected_paths, expected_metadata',
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 [
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
94 (lambda: mock_fs(), [], []),
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
95 (lambda: mock_fs().withPage('test/_index.md'),
267
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
96 ['_index.md'],
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
97 [{'slug': '',
f512905ae812 sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
98 'config': {'foo': 0, 'foo_trail': [0]}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
99 (lambda: mock_fs().withPage('test/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 ['something.md'],
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
101 [{'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
102 'config': {'foo': 0, 'foo_trail': [0]}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
103 (lambda: mock_fs().withPage('test/08_something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 ['08_something.md'],
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
105 [{'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
106 'config': {'foo': 8, 'foo_trail': [8]}}]),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
107 (lambda: mock_fs().withPage('test/02_there/08_something.md'),
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
108 ['02_there/08_something.md'],
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
109 [{'slug': 'there/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
110 'config': {'foo': 8, 'foo_trail': [2, 8]}}]),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 ])
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
112 def test_ordered_source_factories(fs_fac, expected_paths, expected_metadata):
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 'test': {'type': 'ordered',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 }
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
121 fs = fs_fac()
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 facs = list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 paths = [f.rel_path for f in facs]
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 267
diff changeset
129 assert paths == slashfix(expected_paths)
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 metadata = [f.metadata for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 assert metadata == expected_metadata
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 @pytest.mark.parametrize(
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
135 'fs_fac, route_path, expected_path, expected_metadata',
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 [
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
137 (lambda: mock_fs(), 'missing', None, None),
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
138 (lambda: mock_fs().withPage('test/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 'something', 'something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
140 {'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
141 'config': {'foo': 0, 'foo_trail': [0]}}),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
142 (lambda: mock_fs().withPage('test/bar/something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 'bar/something', 'bar/something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
144 {'slug': 'bar/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
145 'config': {'foo': 0, 'foo_trail': [0]}}),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
146 (lambda: mock_fs().withPage('test/42_something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 'something', '42_something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
148 {'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
149 'config': {'foo': 42, 'foo_trail': [42]}}),
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
150 (lambda: mock_fs().withPage('test/bar/42_something.md'),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 'bar/something', 'bar/42_something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
152 {'slug': 'bar/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
153 'config': {'foo': 42, 'foo_trail': [42]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
155 ((lambda: mock_fs()
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 .withPage('test/42_something.md')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 .withPage('test/43_other_something.md')),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 'something', '42_something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
159 {'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
160 'config': {'foo': 42, 'foo_trail': [42]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 ])
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
162 def test_ordered_source_find(fs_fac, route_path, expected_path,
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 expected_metadata):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 'test': {'type': 'ordered',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171 }
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
172 fs = fs_fac()
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 s = app.getSource('test')
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
178 route_metadata = {'slug': route_path}
363
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
179 factory = s.findPageFactory(route_metadata, MODE_PARSING)
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
180 if factory is None:
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
181 assert expected_path is None and expected_metadata is None
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
182 return
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
183 assert factory.rel_path == slashfix(expected_path)
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
184 assert factory.metadata == expected_metadata
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185