comparison tests/test_processing_base.py @ 205:e725af1d48fb

bake: Changes in how assets directories are configured. Change `skip_patterns` and `force_patterns` to `ignore` and `force`. Put less responsibility on the `bake` command to specify all those settings, and more on the `Baker` and `ProcessorPipeline` themselves. Add some tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 18 Jan 2015 12:12:57 -0800
parents 133845647083
children e7b865f8f335
comparison
equal deleted inserted replaced
204:f98451237371 205:e725af1d48fb
32 self.processed.append(in_path) 32 self.processed.append(in_path)
33 shutil.copyfile(in_path, out_path) 33 shutil.copyfile(in_path, out_path)
34 return True 34 return True
35 35
36 36
37 def _get_pipeline(fs, cache=True, **kwargs): 37 def _get_pipeline(fs, app=None):
38 app = fs.getApp(cache=cache) 38 app = app or fs.getApp()
39 mounts = [os.path.join(app.root_dir, 'assets')] 39 app.config.set('baker/num_workers', 1)
40 return ProcessorPipeline(app, mounts, fs.path('counter'), 40 return ProcessorPipeline(app, fs.path('counter'))
41 num_workers=1, **kwargs)
42 41
43 42
44 def test_empty(): 43 def test_empty():
45 fs = mock_fs() 44 fs = mock_fs()
46 with mock_fs_scope(fs): 45 with mock_fs_scope(fs):
170 fs = (mock_fs() 169 fs = (mock_fs()
171 .withFile('kitchen/assets/something.html', 'A test file.') 170 .withFile('kitchen/assets/something.html', 'A test file.')
172 .withFile('kitchen/assets/_hidden.html', 'Shhh') 171 .withFile('kitchen/assets/_hidden.html', 'Shhh')
173 .withFile('kitchen/assets/foo/_important.html', 'Important!')) 172 .withFile('kitchen/assets/foo/_important.html', 'Important!'))
174 with mock_fs_scope(fs): 173 with mock_fs_scope(fs):
175 pp = _get_pipeline(fs, skip_patterns=['/^_/']) 174 pp = _get_pipeline(fs)
175 pp.addSkipPatterns(patterns)
176 pp.filterProcessors(['copy']) 176 pp.filterProcessors(['copy'])
177 expected = {} 177 assert {} == fs.getStructure('counter')
178 assert expected == fs.getStructure('counter')
179 pp.run() 178 pp.run()
180 expected = {
181 'something.html': 'A test file.',
182 'foo': {
183 '_important.html': 'Important!'}
184 }
185 assert expected == fs.getStructure('counter') 179 assert expected == fs.getStructure('counter')
186 180
181
182 @pytest.mark.parametrize('names, expected', [
183 ('all', ['copy', 'concat', 'less', 'sass', 'sitemap']),
184 ('all -sitemap', ['copy', 'concat', 'less', 'sass']),
185 ('-sitemap -less -sass all', ['copy', 'concat']),
186 ('copy', ['copy']),
187 ('less sass', ['less', 'sass'])
188 ])
189 def test_filter_processor(names, expected):
190 fs = mock_fs()
191 with mock_fs_scope(fs):
192 app = fs.getApp()
193 pp = _get_pipeline(fs, app=app)
194 pp.filterProcessors('copy concat less sass sitemap')
195 procs = pp.getFilteredProcessors(names)
196 actual = [p.PROCESSOR_NAME for p in procs]
197 assert sorted(actual) == sorted(expected)
198