Mercurial > piecrust2
annotate tests/test_processing_base.py @ 111:208c652551a3
Quick fix for making the server correctly update referenced pages.
Disable the file-system cache for rendered segments when in server mode. We
can bring this optimization back when we're actually using the baking record
in the server too in order to know dependencies.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 16 Oct 2014 17:03:42 -0700 |
parents | 3471ffa059b2 |
children | 133845647083 |
rev | line source |
---|---|
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
1 import os.path |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from piecrust.processing.base import ProcessorPipeline |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 from .mockutil import mock_fs, mock_fs_scope |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 def _get_pipeline(fs, **kwargs): |
85
3471ffa059b2
Add a `BakeScheduler` to handle build dependencies. Add unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
8 app = fs.getApp(cache=False) |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
9 mounts = [os.path.join(app.root_dir, 'assets')] |
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
10 return ProcessorPipeline(app, mounts, fs.path('counter'), |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 num_workers=1, **kwargs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
13 |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 def test_empty(): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 fs = mock_fs() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 pp = _get_pipeline(fs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 def test_one_file(): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 fs = (mock_fs() |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
28 .withFile('kitchen/assets/something.html', 'A test file.')) |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 pp = _get_pipeline(fs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 expected = {'something.html': 'A test file.'} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 @pytest.mark.parametrize('patterns, expected', [ |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 (['_'], |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 {'something.html': 'A test file.'}), |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 (['html'], |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 {}), |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 (['/^_/'], |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 {'something.html': 'A test file.', |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 'foo': {'_important.html': 'Important!'}}) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 ]) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 def test_skip_pattern(patterns, expected): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 fs = (mock_fs() |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
50 .withFile('kitchen/assets/something.html', 'A test file.') |
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
51 .withFile('kitchen/assets/_hidden.html', 'Shhh') |
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
52 .withFile('kitchen/assets/foo/_important.html', 'Important!')) |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 pp = _get_pipeline(fs, skip_patterns=['/^_/']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 expected = { |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 'something.html': 'A test file.', |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 'foo': { |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 '_important.html': 'Important!'} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 } |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 |