Mercurial > piecrust2
view tests/test_processing_base.py @ 95:cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 07 Sep 2014 21:37:10 -0700 |
parents | 3471ffa059b2 |
children | 133845647083 |
line wrap: on
line source
import os.path import pytest from piecrust.processing.base import ProcessorPipeline from .mockutil import mock_fs, mock_fs_scope def _get_pipeline(fs, **kwargs): app = fs.getApp(cache=False) mounts = [os.path.join(app.root_dir, 'assets')] return ProcessorPipeline(app, mounts, fs.path('counter'), num_workers=1, **kwargs) def test_empty(): fs = mock_fs() with mock_fs_scope(fs): pp = _get_pipeline(fs) pp.filterProcessors(['copy']) expected = {} assert expected == fs.getStructure('counter') pp.run() expected = {} assert expected == fs.getStructure('counter') def test_one_file(): fs = (mock_fs() .withFile('kitchen/assets/something.html', 'A test file.')) with mock_fs_scope(fs): pp = _get_pipeline(fs) pp.filterProcessors(['copy']) expected = {} assert expected == fs.getStructure('counter') pp.run() expected = {'something.html': 'A test file.'} assert expected == fs.getStructure('counter') @pytest.mark.parametrize('patterns, expected', [ (['_'], {'something.html': 'A test file.'}), (['html'], {}), (['/^_/'], {'something.html': 'A test file.', 'foo': {'_important.html': 'Important!'}}) ]) def test_skip_pattern(patterns, expected): fs = (mock_fs() .withFile('kitchen/assets/something.html', 'A test file.') .withFile('kitchen/assets/_hidden.html', 'Shhh') .withFile('kitchen/assets/foo/_important.html', 'Important!')) with mock_fs_scope(fs): pp = _get_pipeline(fs, skip_patterns=['/^_/']) pp.filterProcessors(['copy']) expected = {} assert expected == fs.getStructure('counter') pp.run() expected = { 'something.html': 'A test file.', 'foo': { '_important.html': 'Important!'} } assert expected == fs.getStructure('counter')