Mercurial > piecrust2
annotate tests/test_sources_base.py @ 386:5f0e5276c7cb 2.0.0a9
tests: Add a Chef test for the `find` command.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 11 May 2015 22:25:33 -0700 |
parents | dd25bd3ce1f9 |
children | e7b865f8f335 |
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 |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
44 @pytest.mark.parametrize( |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
45 'ref_path, expected_path, expected_metadata', |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
46 [ |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
47 ('foo.html', '/kitchen/test/foo.html', {'slug': 'foo'}), |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
48 ('foo/bar.html', '/kitchen/test/foo/bar.html', |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
49 {'slug': 'foo/bar'}), |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 ]) |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
51 def test_default_source_resolve_ref(ref_path, expected_path, |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
52 expected_metadata): |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 fs = mock_fs() |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 fs.withConfig({ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 'site': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 'sources': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 'test': {}}, |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 'routes': [ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 {'url': '/%path%', 'source': 'test'}] |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 } |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 }) |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
62 expected_path = fs.path(expected_path).replace('/', os.sep) |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 with mock_fs_scope(fs): |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 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
|
65 s = app.getSource('test') |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
66 actual_path, actual_metadata = s.resolveRef(ref_path) |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
67 assert actual_path == expected_path |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
68 assert actual_metadata == expected_metadata |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 |
144
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
70 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
71 @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
|
72 '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
|
73 ('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
|
74 ['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
|
75 ('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
|
76 ['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
|
77 ('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
|
78 ['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
|
79 ('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
|
80 ['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
|
81 ('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
|
82 ['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
|
83 ('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
|
84 ['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
|
85 '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
|
86 ('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
|
87 ['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
|
88 ('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
|
89 ['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
|
90 '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
|
91 ('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
|
92 ['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
|
93 ]) |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 .withConfig({ |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
98 'site': { |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
99 'sources': { |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
100 'foo': {}, |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
101 'bar': {} |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
102 } |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
103 } |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
104 }) |
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/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
|
106 .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
|
107 .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
|
108 .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
|
109 .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
|
110 .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
|
111 .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
|
112 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
|
113 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
|
114 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
|
115 |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
116 assert r.possible_paths == slashfix( |
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
117 [os.path.join(fs.path('/kitchen'), p) |
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
118 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
|
119 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 assert r.rel_path == expected_rel_path |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
124 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
|
125 '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
|
126 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
127 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
136 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 '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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 |