Mercurial > piecrust2
annotate tests/test_baking_baker.py @ 29:7e44f6092a1d
More unit tests for output bake paths.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 19 Aug 2014 11:51:09 -0700 |
parents | 617191dec18e |
children | 3471ffa059b2 |
rev | line source |
---|---|
11
617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
1 import os.path |
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from piecrust.baking.baker import PageBaker |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 from .mockutil import get_mock_app |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 @pytest.mark.parametrize('uri, page_num, pretty, expected', [ |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 # Pretty URLs |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 ('', 1, True, 'index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 ('', 2, True, '2/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 ('foo', 1, True, 'foo/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 ('foo', 2, True, 'foo/2/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 ('foo/bar', 1, True, 'foo/bar/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 ('foo/bar', 2, True, 'foo/bar/2/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 ('foo.ext', 1, True, 'foo.ext/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 ('foo.ext', 2, True, 'foo.ext/2/index.html'), |
29
7e44f6092a1d
More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
17 ('foo/bar.ext', 1, True, 'foo/bar.ext/index.html'), |
7e44f6092a1d
More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
18 ('foo/bar.ext', 2, True, 'foo/bar.ext/2/index.html'), |
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 ('foo.bar.ext', 1, True, 'foo.bar.ext/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 ('foo.bar.ext', 2, True, 'foo.bar.ext/2/index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 # Ugly URLs |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 ('', 1, False, 'index.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 ('', 2, False, '2.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 ('foo', 1, False, 'foo.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 ('foo', 2, False, 'foo/2.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 ('foo/bar', 1, False, 'foo/bar.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 ('foo/bar', 2, False, 'foo/bar/2.html'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 ('foo.ext', 1, False, 'foo.ext'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 ('foo.ext', 2, False, 'foo/2.ext'), |
29
7e44f6092a1d
More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
30 ('foo/bar.ext', 1, False, 'foo/bar.ext'), |
7e44f6092a1d
More unit tests for output bake paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
31 ('foo/bar.ext', 2, False, 'foo/bar/2.ext'), |
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 ('foo.bar.ext', 1, False, 'foo.bar.ext'), |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 ('foo.bar.ext', 2, False, 'foo.bar/2.ext') |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 ]) |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 def test_get_output_path(uri, page_num, pretty, expected): |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 app = get_mock_app() |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 if pretty: |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 app.config.set('site/pretty_urls', True) |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 assert app.config.get('site/pretty_urls') == pretty |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 baker = PageBaker(app, '/destination') |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 sub_uri = baker.getOutputUri(uri, page_num) |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 path = baker.getOutputPath(sub_uri) |
11
617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
44 expected = os.path.normpath( |
617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
45 os.path.join('/destination', expected)) |
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 assert expected == path |
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 |