annotate tests/test_sources_base.py @ 286:a2d283d1033d

tests: Fixes for running on Windows. Mostly about those damn backslashes, as usual.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Mar 2015 22:40:50 -0800
parents f130365568ff
children dd25bd3ce1f9
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
242
f130365568ff internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents: 241
diff changeset
4 from piecrust.sources.pageref 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
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
6 from .pathutil import slashfix
30
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
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 @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
10 (mock_fs(), [], []),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 (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
12 ['foo.html'], ['foo']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 (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
14 ['foo.md'], ['foo']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 (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
16 ['foo.ext'], ['foo.ext']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 (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
18 ['foo/bar.html'], ['foo/bar']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 (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
20 ['foo/bar.md'], ['foo/bar']),
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 (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
22 ['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
23 ])
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 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
25 fs.withConfig({
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 'site': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 'sources': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 'test': {}},
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 'routes': [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 {'url': '/%path%', 'source': 'test'}]
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 }
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 })
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
33 fs.withDir('kitchen/test')
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 with mock_fs_scope(fs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 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
36 s = app.getSource('test')
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 facs = list(s.buildPageFactories())
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 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
39 assert paths == expected_paths
241
85a6c7ba5e3b tests: Fix tests for base sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 144
diff changeset
40 slugs = [f.metadata['slug'] for f in facs]
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 assert slugs == expected_slugs
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
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 @pytest.mark.parametrize('ref_path, expected', [
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
46 ('foo.html', '/kitchen/test/foo.html'),
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 30
diff changeset
47 ('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
48 ])
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 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
50 fs = mock_fs()
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 fs.withConfig({
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 'site': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 'sources': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 'test': {}},
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 'routes': [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 {'url': '/%path%', 'source': 'test'}]
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 })
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 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
60 with mock_fs_scope(fs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 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
62 s = app.getSource('test')
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 actual = s.resolveRef(ref_path)
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 assert actual == expected
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65
144
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
66
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
67 @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
68 '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
69 ('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
70 ['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
71 ('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
72 ['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
73 ('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
74 ['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.%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
76 ['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
77 ('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
78 ['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.%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
80 ['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
81 '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
82 ('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
83 ['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
84 ('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
85 ['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
86 '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
87 ('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
88 ['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
89 ])
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
90 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
91 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
92 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
93 .withConfig({
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
94 'site': {
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
95 'sources': {
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
96 'foo': {},
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
97 'bar': {}
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 })
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/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
102 .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
103 .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
104 .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
105 .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
106 .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
107 .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
108 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
109 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
110 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
111
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
112 assert r.possible_paths == slashfix(
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
113 [os.path.join(fs.path('/kitchen'), p)
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
114 for p in expected_possible_paths])
144
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
115
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.exists
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.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
118 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
119 assert r.rel_path == expected_rel_path
286
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
120 assert r.path == slashfix(fs.path(os.path.join(
a2d283d1033d tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
121 'kitchen', expected_source_name, expected_rel_path)))
144
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
122
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
123
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
132
8d16ca75075f Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 94
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
139 '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
140 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
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.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
143 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
144 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
145 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
146