Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
34:bdb103c57168 | 35:e4c345dcf33c |
---|---|
1 import pytest | |
2 from piecrust.processing.base import ProcessorPipeline | |
3 from .mockutil import mock_fs, mock_fs_scope | |
4 | |
5 | |
6 def _get_pipeline(fs, **kwargs): | |
7 return ProcessorPipeline(fs.getApp(), fs.path('counter'), | |
8 num_workers=1, **kwargs) | |
9 | |
10 def test_empty(): | |
11 fs = mock_fs() | |
12 with mock_fs_scope(fs): | |
13 pp = _get_pipeline(fs) | |
14 pp.filterProcessors(['copy']) | |
15 expected = {} | |
16 assert expected == fs.getStructure('counter') | |
17 pp.run() | |
18 expected = {} | |
19 assert expected == fs.getStructure('counter') | |
20 | |
21 | |
22 def test_one_file(): | |
23 fs = (mock_fs() | |
24 .withFile('kitchen/something.html', 'A test file.')) | |
25 with mock_fs_scope(fs): | |
26 pp = _get_pipeline(fs) | |
27 pp.filterProcessors(['copy']) | |
28 expected = {} | |
29 assert expected == fs.getStructure('counter') | |
30 pp.run() | |
31 expected = {'something.html': 'A test file.'} | |
32 assert expected == fs.getStructure('counter') | |
33 | |
34 | |
35 @pytest.mark.parametrize('patterns, expected', [ | |
36 (['_'], | |
37 {'something.html': 'A test file.'}), | |
38 (['html'], | |
39 {}), | |
40 (['/^_/'], | |
41 {'something.html': 'A test file.', | |
42 'foo': {'_important.html': 'Important!'}}) | |
43 ]) | |
44 def test_skip_pattern(patterns, expected): | |
45 fs = (mock_fs() | |
46 .withFile('kitchen/something.html', 'A test file.') | |
47 .withFile('kitchen/_hidden.html', 'Shhh') | |
48 .withFile('kitchen/foo/_important.html', 'Important!')) | |
49 with mock_fs_scope(fs): | |
50 pp = _get_pipeline(fs, skip_patterns=['/^_/']) | |
51 pp.filterProcessors(['copy']) | |
52 expected = {} | |
53 assert expected == fs.getStructure('counter') | |
54 pp.run() | |
55 expected = { | |
56 'something.html': 'A test file.', | |
57 'foo': { | |
58 '_important.html': 'Important!'} | |
59 } | |
60 assert expected == fs.getStructure('counter') | |
61 |