annotate tests/test_sources_base.py @ 158:1187739e5a19

Fix some indentation and line lengths.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 31 Dec 2014 16:56:55 -0800
parents 8d16ca75075f
children 85a6c7ba5e3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pytest
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from piecrust.app import PieCrust
144
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
4 from piecrust.sources.base import PageRef, PageNotFoundError
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 from .mockutil import mock_fs, mock_fs_scope
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 @pytest.mark.parametrize('fs, expected_paths, expected_slugs', [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 (mock_fs(), [], []),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 (mock_fs().withPage('test/foo.html'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 ['foo.html'], ['foo']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 (mock_fs().withPage('test/foo.md'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 ['foo.md'], ['foo']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 (mock_fs().withPage('test/foo.ext'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 ['foo.ext'], ['foo.ext']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 (mock_fs().withPage('test/foo/bar.html'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 ['foo/bar.html'], ['foo/bar']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 (mock_fs().withPage('test/foo/bar.md'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 ['foo/bar.md'], ['foo/bar']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 (mock_fs().withPage('test/foo/bar.ext'),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 ['foo/bar.ext'], ['foo/bar.ext']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 ])
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 def test_default_source_factories(fs, expected_paths, expected_slugs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 fs.withConfig({
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 'site': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 'sources': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 'test': {}},
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 'routes': [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 {'url': '/%path%', 'source': 'test'}]
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 }
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 })
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
32 fs.withDir('kitchen/test')
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 with mock_fs_scope(fs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 app = PieCrust(fs.path('kitchen'), cache=False)
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 s = app.getSource('test')
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 facs = list(s.buildPageFactories())
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 paths = [f.rel_path for f in facs]
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 assert paths == expected_paths
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 slugs = [f.metadata['path'] for f in facs]
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 assert slugs == expected_slugs
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 @pytest.mark.parametrize('ref_path, expected', [
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
45 ('foo.html', '/kitchen/test/foo.html'),
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
46 ('foo/bar.html', '/kitchen/test/foo/bar.html'),
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 ])
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 def test_default_source_resolve_ref(ref_path, expected):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 fs = mock_fs()
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 fs.withConfig({
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 'site': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 'sources': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 'test': {}},
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 'routes': [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 {'url': '/%path%', 'source': 'test'}]
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 }
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 })
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 expected = fs.path(expected).replace('/', os.sep)
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 with mock_fs_scope(fs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 app = PieCrust(fs.path('kitchen'), cache=False)
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 s = app.getSource('test')
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 actual = s.resolveRef(ref_path)
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 assert actual == expected
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64
144
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
65
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
66 @pytest.mark.parametrize('page_ref, expected_source_name, expected_rel_path, '
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
67 'expected_possible_paths', [
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
68 ('foo:one.md', 'foo', 'one.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
69 ['foo/one.md']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
70 ('foo:two.md', 'foo', 'two.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
71 ['foo/two.md']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
72 ('foo:two.html', 'foo', 'two.html',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
73 ['foo/two.html']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
74 ('foo:two.%ext%', 'foo', 'two.html',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
75 ['foo/two.html', 'foo/two.md', 'foo/two.textile']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
76 ('foo:subdir/four.md', 'foo', 'subdir/four.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
77 ['foo/subdir/four.md']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
78 ('foo:subdir/four.%ext%', 'foo', 'subdir/four.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
79 ['foo/subdir/four.html', 'foo/subdir/four.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
80 'foo/subdir/four.textile']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
81 ('foo:three.md;bar:three.md', 'foo', 'three.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
82 ['foo/three.md', 'bar/three.md']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
83 ('foo:three.%ext%;bar:three.%ext%', 'foo', 'three.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
84 ['foo/three.html', 'foo/three.md', 'foo/three.textile',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
85 'bar/three.html', 'bar/three.md', 'bar/three.textile']),
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
86 ('foo:special.md;bar:special.md', 'bar', 'special.md',
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
87 ['foo/special.md', 'bar/special.md'])
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
88 ])
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
89 def test_page_ref(page_ref, expected_source_name, expected_rel_path,
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
90 expected_possible_paths):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
91 fs = (mock_fs()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
92 .withConfig({
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
93 'site': {
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
94 'sources': {
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
95 'foo': {},
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
96 'bar': {}
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
97 }
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
98 }
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
99 })
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
100 .withPage('foo/one.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
101 .withPage('foo/two.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
102 .withPage('foo/two.html')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
103 .withPage('foo/three.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
104 .withPage('foo/subdir/four.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
105 .withPage('bar/three.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
106 .withPage('bar/special.md'))
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
107 with mock_fs_scope(fs):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
108 app = fs.getApp()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
109 r = PageRef(app, page_ref)
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
110
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
111 assert r.possible_paths == [os.path.join(fs.path('/kitchen'), p)
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
112 for p in expected_possible_paths]
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
113
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
114 assert r.exists
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
115 assert r.source_name == expected_source_name
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
116 assert r.source == app.getSource(expected_source_name)
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
117 assert r.rel_path == expected_rel_path
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
118 assert r.path == fs.path(os.path.join(
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
119 'kitchen', expected_source_name, expected_rel_path))
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
120
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
121
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
122 def test_page_ref_with_missing_source():
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
123 fs = mock_fs()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
124 with mock_fs_scope(fs):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
125 app = fs.getApp()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
126 r = PageRef(app, 'whatever:doesnt_exist.md')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
127 with pytest.raises(Exception):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
128 r.possible_rel_paths
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
129
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
130
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
131 def test_page_ref_with_missing_file():
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
132 fs = mock_fs()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
133 with mock_fs_scope(fs):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
134 app = fs.getApp()
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
135 r = PageRef(app, 'pages:doesnt_exist.%ext%')
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
136 assert r.possible_rel_paths == [
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
137 'doesnt_exist.html', 'doesnt_exist.md', 'doesnt_exist.textile']
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
138 assert r.source_name == 'pages'
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
139 with pytest.raises(PageNotFoundError):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
140 r.rel_path
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
141 with pytest.raises(PageNotFoundError):
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
142 r.path
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
143 assert not r.exists
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
144