Mercurial > piecrust2
annotate tests/test_processing_base.py @ 35:e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 20 Aug 2014 21:46:27 -0700 |
parents | |
children | 485682a6de50 |
rev | line source |
---|---|
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import pytest |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 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
|
3 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
|
4 |
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 def _get_pipeline(fs, **kwargs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 return ProcessorPipeline(fs.getApp(), fs.path('counter'), |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 num_workers=1, **kwargs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 def test_empty(): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 fs = mock_fs() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 pp = _get_pipeline(fs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 def test_one_file(): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 fs = (mock_fs() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 .withFile('kitchen/something.html', 'A test file.')) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 pp = _get_pipeline(fs) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 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
|
32 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 @pytest.mark.parametrize('patterns, expected', [ |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 (['_'], |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 {'something.html': 'A test file.'}), |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 (['html'], |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 {}), |
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 'foo': {'_important.html': 'Important!'}}) |
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 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
|
45 fs = (mock_fs() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 .withFile('kitchen/something.html', 'A test file.') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 .withFile('kitchen/_hidden.html', 'Shhh') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 .withFile('kitchen/foo/_important.html', 'Important!')) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 with mock_fs_scope(fs): |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 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
|
51 pp.filterProcessors(['copy']) |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 expected = {} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 pp.run() |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 expected = { |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 'something.html': 'A test file.', |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 'foo': { |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 '_important.html': 'Important!'} |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 } |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 assert expected == fs.getStructure('counter') |
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 |