Mercurial > piecrust2
annotate tests/test_sources_autoconfig.py @ 351:1f22d4b10fef
tests: Improve bake tests output, add support for partial output checks.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 17 Apr 2015 16:08:23 -0700 |
parents | a2d283d1033d |
children | dd25bd3ce1f9 |
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( |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 'fs, src_config, expected_paths, expected_metadata', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 [ |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 (mock_fs(), {}, [], []), |
267
f512905ae812
sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
11 (mock_fs().withPage('test/_index.md'), |
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': []}}]), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 (mock_fs().withPage('test/something.md'), |
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': []}}]), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 (mock_fs().withPage('test/bar/something.md'), |
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']}}]), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 (mock_fs().withPage('test/bar1/bar2/something.md'), |
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 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 (mock_fs().withPage('test/something.md'), |
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}}]), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 (mock_fs().withPage('test/bar/something.md'), |
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'}}]), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 (mock_fs().withPage('test/bar1/bar2/something.md'), |
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 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 (mock_fs().withPage('test/something.md'), |
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}}]), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 (mock_fs().withPage('test/bar/something.md'), |
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 ]) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 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
|
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) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 s = app.getSource('test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 facs = list(s.buildPageFactories()) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 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
|
68 assert paths == slashfix(expected_paths) |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 metadata = [f.metadata for f in facs] |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 assert metadata == expected_metadata |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 |
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 def test_autoconfig_fails_if_multiple_folders(): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 site_config = { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 'sources': { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 'test': {'type': 'autoconfig', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 'setting_name': 'foo', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 'only_single_values': True} |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 } |
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 fs = mock_fs().withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
82 fs.withPage('test/bar1/bar2/something.md') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 s = app.getSource('test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 with pytest.raises(Exception): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 list(s.buildPageFactories()) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 |
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 @pytest.mark.parametrize( |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 'fs, expected_paths, expected_metadata', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 [ |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 (mock_fs(), [], []), |
267
f512905ae812
sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
94 (mock_fs().withPage('test/_index.md'), |
f512905ae812
sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
95 ['_index.md'], |
f512905ae812
sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
96 [{'slug': '', |
f512905ae812
sources: Generate proper slugs in the `autoconfig` and `ordered` sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
97 'config': {'foo': 0, 'foo_trail': [0]}}]), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 (mock_fs().withPage('test/something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 ['something.md'], |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
100 [{'slug': 'something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
101 'config': {'foo': 0, 'foo_trail': [0]}}]), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 (mock_fs().withPage('test/08_something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 ['08_something.md'], |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
104 [{'slug': 'something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
105 '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
|
106 (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
|
107 ['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
|
108 [{'slug': 'there/something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
109 'config': {'foo': 8, 'foo_trail': [2, 8]}}]), |
239
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 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
|
112 site_config = { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 'sources': { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 'test': {'type': 'ordered', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 'setting_name': 'foo'} |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 }, |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 'routes': [ |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 {'url': '/%slug%', 'source': 'test'}] |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 } |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
120 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
122 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
123 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 s = app.getSource('test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 facs = list(s.buildPageFactories()) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 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
|
127 assert paths == slashfix(expected_paths) |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 metadata = [f.metadata for f in facs] |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 assert metadata == expected_metadata |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 @pytest.mark.parametrize( |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
133 'fs, route_path, expected_path, expected_metadata', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 [ |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
135 (mock_fs(), 'missing', None, None), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
136 (mock_fs().withPage('test/something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
137 'something', 'something.md', |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
138 {'slug': 'something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
139 'config': {'foo': 0, 'foo_trail': [0]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
140 (mock_fs().withPage('test/bar/something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
141 '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
|
142 {'slug': 'bar/something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
143 'config': {'foo': 0, 'foo_trail': [0]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
144 (mock_fs().withPage('test/42_something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
145 '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
|
146 {'slug': 'something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
147 'config': {'foo': 42, 'foo_trail': [42]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
148 (mock_fs().withPage('test/bar/42_something.md'), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
149 '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
|
150 {'slug': 'bar/something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
151 'config': {'foo': 42, 'foo_trail': [42]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
152 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
153 ((mock_fs() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
154 .withPage('test/42_something.md') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
155 .withPage('test/43_other_something.md')), |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
156 '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
|
157 {'slug': 'something', |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
158 'config': {'foo': 42, 'foo_trail': [42]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
159 ]) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
160 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
|
161 expected_metadata): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
162 site_config = { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
163 'sources': { |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
164 'test': {'type': 'ordered', |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
165 'setting_name': 'foo'} |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
166 }, |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
167 'routes': [ |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
168 {'url': '/%slug%', 'source': 'test'}] |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
169 } |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
170 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
171 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
172 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
173 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
174 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
|
175 route_metadata = {'slug': route_path} |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
176 fac_path, metadata = s.findPagePath(route_metadata, MODE_PARSING) |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
267
diff
changeset
|
177 assert fac_path == slashfix(expected_path) |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
178 assert metadata == expected_metadata |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
179 |