Mercurial > piecrust2
annotate tests/test_sources_base.py @ 665:5dc13c816045
tests: Fix logic for making time-based tests not fail randomly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 03 Mar 2016 08:19:28 -0800 |
parents | e7b865f8f335 |
children | f987b29d6fab |
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 |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
9 @pytest.mark.parametrize('fs_fac, expected_paths, expected_slugs', [ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
10 (lambda: mock_fs(), [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
11 (lambda: mock_fs().withPage('test/foo.html'), |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 ['foo.html'], ['foo']), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
13 (lambda: mock_fs().withPage('test/foo.md'), |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 ['foo.md'], ['foo']), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
15 (lambda: mock_fs().withPage('test/foo.ext'), |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 ['foo.ext'], ['foo.ext']), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
17 (lambda: mock_fs().withPage('test/foo/bar.html'), |
30
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']), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
19 (lambda: mock_fs().withPage('test/foo/bar.md'), |
30
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']), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
21 (lambda: mock_fs().withPage('test/foo/bar.ext'), |
30
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 ]) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
24 def test_default_source_factories(fs_fac, expected_paths, expected_slugs): |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
25 fs = fs_fac() |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 fs.withConfig({ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 'site': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 'sources': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 'test': {}}, |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 'routes': [ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 {'url': '/%path%', 'source': 'test'}] |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 } |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 }) |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
30
diff
changeset
|
34 fs.withDir('kitchen/test') |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 with mock_fs_scope(fs): |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 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
|
37 s = app.getSource('test') |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 facs = list(s.buildPageFactories()) |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 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
|
40 assert paths == expected_paths |
241
85a6c7ba5e3b
tests: Fix tests for base sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
144
diff
changeset
|
41 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
|
42 assert slugs == expected_slugs |
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 |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
45 @pytest.mark.parametrize( |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
46 '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
|
47 [ |
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
48 ('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
|
49 ('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
|
50 {'slug': 'foo/bar'}), |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 ]) |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
52 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
|
53 expected_metadata): |
30
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 fs = mock_fs() |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 fs.withConfig({ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 'site': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 'sources': { |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 'test': {}}, |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 'routes': [ |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 {'url': '/%path%', 'source': 'test'}] |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 } |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 }) |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
63 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
|
64 with mock_fs_scope(fs): |
4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 |
144
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
71 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
72 @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
|
73 '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
|
74 ('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
|
75 ['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
|
76 ('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
|
77 ['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
|
78 ('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
|
79 ['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.%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
|
81 ['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
|
82 ('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
|
83 ['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.%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
|
85 ['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
|
86 '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
|
87 ('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
|
88 ['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
|
89 ('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
|
90 ['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
|
91 '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
|
92 ('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
|
93 ['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
|
94 ]) |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 .withConfig({ |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
99 'site': { |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
100 'sources': { |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
101 'foo': {}, |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
102 'bar': {} |
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 }) |
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/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
|
107 .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
|
108 .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
|
109 .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
|
110 .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
|
111 .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
|
112 .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
|
113 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
|
114 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
|
115 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
|
116 |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
117 assert r.possible_paths == slashfix( |
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
118 [os.path.join(fs.path('/kitchen'), p) |
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
119 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
|
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 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
|
122 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
|
123 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
|
124 assert r.rel_path == expected_rel_path |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
125 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
|
126 '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
|
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 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 with pytest.raises(Exception): |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
135 r.possible_ref_specs |
144
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 |
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 r = PageRef(app, 'pages:doesnt_exist.%ext%') |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
143 assert r.possible_ref_specs == [ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
144 'pages:doesnt_exist.html', 'pages:doesnt_exist.md', |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
145 'pages:doesnt_exist.textile'] |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
146 with pytest.raises(PageNotFoundError): |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
147 r.source_name |
144
8d16ca75075f
Fix a bug with page references in cases of failure. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 |