annotate tests/test_sources_base.py @ 975:a0a62d0da723

internal: Check that the `Assetor` has an asset URL format to work with.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 17 Oct 2017 01:08:56 -0700
parents 72f17534d58e
children 45ad976712ec
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
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 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
5
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
7 @pytest.mark.parametrize('fs_fac, expected_paths, expected_slugs', [
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
8 (lambda: mock_fs(), [], []),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
9 (lambda: mock_fs().withPage('test/foo.html'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
10 ['foo.html'], ['foo']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
11 (lambda: mock_fs().withPage('test/foo.md'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
12 ['foo.md'], ['foo']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
13 (lambda: mock_fs().withPage('test/foo.ext'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
14 ['foo.ext'], ['foo.ext']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
15 (lambda: mock_fs().withPage('test/foo/bar.html'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
16 ['foo/bar.html'], ['foo/bar']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
17 (lambda: mock_fs().withPage('test/foo/bar.md'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
18 ['foo/bar.md'], ['foo/bar']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
19 (lambda: mock_fs().withPage('test/foo/bar.ext'),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
20 ['foo/bar.ext'], ['foo/bar.ext']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
21 ])
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 363
diff changeset
22 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
23 fs = fs_fac()
30
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'}]
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
30 }
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
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
241
85a6c7ba5e3b tests: Fix tests for base sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 144
diff changeset
39 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
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
363
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
43 @pytest.mark.parametrize(
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
44 'ref_path, expected_path, expected_metadata',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
45 [
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
46 ('foo.html', '/kitchen/test/foo.html', {'slug': 'foo'}),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
47 ('foo/bar.html', '/kitchen/test/foo/bar.html',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
48 {'slug': 'foo/bar'}),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
49 ])
363
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
50 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
51 expected_metadata):
30
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 fs = mock_fs()
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 fs.withConfig({
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 'site': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 'sources': {
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 'test': {}},
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 'routes': [
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 {'url': '/%path%', 'source': 'test'}]
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
59 }
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
60 })
363
dd25bd3ce1f9 serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 286
diff changeset
61 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
62 with mock_fs_scope(fs):
4bd840ae75cd Fix stupid bug in default source, add some unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 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
64 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
65 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
66 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
67 assert actual_metadata == expected_metadata