comparison tests/test_data_linker.py @ 404:27b10024f8d8

linker: Add ability to return the parent and ancestors of a page. Add reference documentation. Add tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 24 May 2015 18:15:22 -0700
parents b51ddb0c260b
children e7b865f8f335
comparison
equal deleted inserted replaced
403:563e2e84ef6e 404:27b10024f8d8
1 import os.path
1 import pytest 2 import pytest
2 from piecrust.data.linker import Linker 3 from piecrust.data.linker import Linker
3 from .mockutil import mock_fs, mock_fs_scope 4 from .mockutil import mock_fs, mock_fs_scope
4 5
5 6
37 def test_linker_iteration(fs, page_path, expected): 38 def test_linker_iteration(fs, page_path, expected):
38 with mock_fs_scope(fs): 39 with mock_fs_scope(fs):
39 app = fs.getApp() 40 app = fs.getApp()
40 app.config.set('site/pretty_urls', True) 41 app.config.set('site/pretty_urls', True)
41 src = app.getSource('pages') 42 src = app.getSource('pages')
42 linker = Linker(src, page_path) 43 linker = Linker(src, os.path.dirname(page_path),
44 root_page_path=page_path)
43 actual = list(iter(linker)) 45 actual = list(iter(linker))
44 46
45 assert len(actual) == len(expected) 47 assert len(actual) == len(expected)
46 for (a, e) in zip(actual, expected): 48 for (a, e) in zip(actual, expected):
47 is_dir, name, is_self, url = e 49 is_dir, name, is_self, url = e
81 def test_recursive_linker_iteration(fs, page_path, expected): 83 def test_recursive_linker_iteration(fs, page_path, expected):
82 with mock_fs_scope(fs): 84 with mock_fs_scope(fs):
83 app = fs.getApp() 85 app = fs.getApp()
84 app.config.set('site/pretty_urls', True) 86 app.config.set('site/pretty_urls', True)
85 src = app.getSource('pages') 87 src = app.getSource('pages')
86 linker = Linker(src, page_path) 88 linker = Linker(src, os.path.dirname(page_path),
89 root_page_path=page_path)
87 actual = list(iter(linker.allpages)) 90 actual = list(iter(linker.allpages))
88 91
89 assert len(actual) == len(expected) 92 assert len(actual) == len(expected)
90 for i, (a, e) in enumerate(zip(actual, expected)): 93 for i, (a, e) in enumerate(zip(actual, expected)):
91 assert a.is_dir is False 94 assert a.is_dir is False