annotate tests/test_sources_autoconfig.py @ 242:f130365568ff

internal: Code reorganization to put less stuff in `sources.base`. Interfaces that sources can implement are in `sources.interfaces`. The default page source is in `sources.default`. The `SimplePageSource` is gone since most subclasses only wanted to do *some* stuff the same, but *lots* of stuff slightly different. I may have to revisit the code to extract exactly the code that's in common.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 18 Feb 2015 18:35:03 -0800
parents f43f19975671
children f512905ae812
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
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
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 @pytest.mark.parametrize(
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 'fs, src_config, expected_paths, expected_metadata',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 (mock_fs(), {}, [], []),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 (mock_fs().withPage('test/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 [{'slug': 'something', 'config': {'foo': []}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 (mock_fs().withPage('test/bar/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 [{'slug': 'something', 'config': {'foo': ['bar']}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 (mock_fs().withPage('test/bar1/bar2/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 {},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 ['bar1/bar2/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 [{'slug': 'something', 'config': {'foo': ['bar1', 'bar2']}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 (mock_fs().withPage('test/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 [{'slug': 'something', 'config': {'foo': None}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 (mock_fs().withPage('test/bar/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 [{'slug': 'something', 'config': {'foo': 'bar'}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 (mock_fs().withPage('test/bar1/bar2/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 {'collapse_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 ['bar1/bar2/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 [{'slug': 'something', 'config': {'foo': ['bar1', 'bar2']}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 (mock_fs().withPage('test/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 {'only_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 ['something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 [{'slug': 'something', 'config': {'foo': None}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 (mock_fs().withPage('test/bar/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 {'only_single_values': True},
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 ['bar/something.md'],
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 [{'slug': 'something', 'config': {'foo': 'bar'}}]),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 ])
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 def test_autoconfig_source_factories(fs, src_config, expected_paths,
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 expected_metadata):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 'test': {'type': 'autoconfig',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 site_config['sources']['test'].update(src_config)
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 facs = list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 paths = [f.rel_path for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 assert paths == expected_paths
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 metadata = [f.metadata for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 assert metadata == expected_metadata
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 def test_autoconfig_fails_if_multiple_folders():
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 'test': {'type': 'autoconfig',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 'setting_name': 'foo',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 'only_single_values': True}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 fs = mock_fs().withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 fs.withPage('test/bar1/bar2/something.md')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 with pytest.raises(Exception):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 @pytest.mark.parametrize(
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 'fs, expected_paths, expected_metadata',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 (mock_fs(), [], []),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 (mock_fs().withPage('test/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 ['something.md'],
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
91 [{'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
92 'config': {'foo': 0, 'foo_trail': [0]}}]),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 (mock_fs().withPage('test/08_something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 ['08_something.md'],
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
95 [{'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
96 'config': {'foo': 8, 'foo_trail': [8]}}]),
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
97 (mock_fs().withPage('test/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
98 ['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
99 [{'slug': 'there/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
100 'config': {'foo': 8, 'foo_trail': [2, 8]}}]),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 ])
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 def test_ordered_source_factories(fs, expected_paths, expected_metadata):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 'test': {'type': 'ordered',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 s = app.getSource('test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 facs = list(s.buildPageFactories())
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 paths = [f.rel_path for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 assert paths == expected_paths
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 metadata = [f.metadata for f in facs]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 assert metadata == expected_metadata
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 @pytest.mark.parametrize(
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 'fs, route_path, expected_path, expected_metadata',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 (mock_fs(), 'missing', None, None),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 (mock_fs().withPage('test/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 'something', 'something.md',
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
129 {'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
130 'config': {'foo': 0, 'foo_trail': [0]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 (mock_fs().withPage('test/bar/something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 '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
133 {'slug': 'bar/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
134 'config': {'foo': 0, 'foo_trail': [0]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 (mock_fs().withPage('test/42_something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 '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
137 {'slug': 'something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
138 'config': {'foo': 42, 'foo_trail': [42]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 (mock_fs().withPage('test/bar/42_something.md'),
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 '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
141 {'slug': 'bar/something',
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 239
diff changeset
142 'config': {'foo': 42, 'foo_trail': [42]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 ((mock_fs()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 .withPage('test/42_something.md')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 .withPage('test/43_other_something.md')),
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]}}),
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 ])
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 def test_ordered_source_find(fs, route_path, expected_path,
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 expected_metadata):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 site_config = {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 'sources': {
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 'test': {'type': 'ordered',
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 'setting_name': 'foo'}
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 },
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 'routes': [
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 {'url': '/%slug%', 'source': 'test'}]
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 }
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 fs.withConfig({'site': site_config})
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162 fs.withDir('kitchen/test')
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 with mock_fs_scope(fs):
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 app = fs.getApp()
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 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
166 route_metadata = {'slug': route_path}
239
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 fac_path, metadata = s.findPagePath(route_metadata, MODE_PARSING)
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 assert fac_path == expected_path
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 assert metadata == expected_metadata
f43f19975671 sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170