Mercurial > piecrust2
comparison tests/test_sources_posts.py @ 95:cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 07 Sep 2014 21:37:10 -0700 |
parents | |
children | e7b865f8f335 |
comparison
equal
deleted
inserted
replaced
94:b536022078a2 | 95:cb6eadea0845 |
---|---|
1 import os | |
2 import pytest | |
3 from .mockutil import mock_fs, mock_fs_scope | |
4 | |
5 | |
6 @pytest.mark.parametrize('fs, src_type, expected_paths, expected_metadata', [ | |
7 (mock_fs(), 'flat', [], []), | |
8 (mock_fs().withPage('test/2014-01-01_foo.md'), | |
9 'flat', | |
10 ['2014-01-01_foo.md'], | |
11 [(2014, 1, 1, 'foo')]), | |
12 (mock_fs(), 'shallow', [], []), | |
13 (mock_fs().withPage('test/2014/01-01_foo.md'), | |
14 'shallow', | |
15 ['2014/01-01_foo.md'], | |
16 [(2014, 1, 1, 'foo')]), | |
17 (mock_fs(), 'hierarchy', [], []), | |
18 (mock_fs().withPage('test/2014/01/01_foo.md'), | |
19 'hierarchy', | |
20 ['2014/01/01_foo.md'], | |
21 [(2014, 1, 1, 'foo')]), | |
22 ]) | |
23 def test_post_source_factories(fs, src_type, expected_paths, expected_metadata): | |
24 fs.withConfig({ | |
25 'site': { | |
26 'sources': { | |
27 'test': {'type': 'posts/%s' % src_type}}, | |
28 'routes': [ | |
29 {'url': '/%slug%', 'source': 'test'}] | |
30 } | |
31 }) | |
32 fs.withDir('kitchen/test') | |
33 with mock_fs_scope(fs): | |
34 app = fs.getApp(cache=False) | |
35 s = app.getSource('test') | |
36 facs = list(s.buildPageFactories()) | |
37 paths = [f.rel_path for f in facs] | |
38 assert paths == expected_paths | |
39 metadata = [ | |
40 (f.metadata['year'], f.metadata['month'], | |
41 f.metadata['day'], f.metadata['slug']) | |
42 for f in facs] | |
43 assert metadata == expected_metadata | |
44 |