annotate tests/test_processing_base.py @ 411:e7b865f8f335

bake: Enable multiprocess baking. Baking is now done by running a worker per CPU, and sending jobs to them. This changes several things across the codebase: * Ability to not cache things related to pages other than the 'main' page (i.e. the page at the bottom of the execution stack). * Decouple the baking process from the bake records, so only the main process keeps track (and modifies) the bake record. * Remove the need for 'batch page getters' and loading a page directly from the page factories. There are various smaller changes too included here, including support for scope performance timers that are saved with the bake record and can be printed out to the console. Yes I got carried away. For testing, the in-memory 'mock' file-system doesn't work anymore, since we're spawning processes, so this is replaced by a 'tmpfs' file-system which is saved in temporary files on disk and deleted after tests have run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 12 Jun 2015 17:09:19 -0700
parents e725af1d48fb
children c4b3a7fd2f87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
1 import time
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
2 import os.path
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
3 import shutil
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import pytest
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
5 from piecrust.processing.base import (ProcessorPipeline, SimpleFileProcessor)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
6 from piecrust.processing.records import ProcessorPipelineRecord
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 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
8
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
10 class FooProcessor(SimpleFileProcessor):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
11 def __init__(self, exts=None, open_func=None):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
12 exts = exts or {'foo', 'foo'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
13 super(FooProcessor, self).__init__({exts[0]: exts[1]})
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
14 self.PROCESSOR_NAME = exts[0]
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
15 self.open_func = open_func or open
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
16
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
17 def _doProcess(self, in_path, out_path):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
18 with self.open_func(in_path, 'r') as f:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
19 text = f.read()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
20 with self.open_func(out_path, 'w') as f:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
21 f.write("%s: %s" % (self.PROCESSOR_NAME.upper(), text))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
22 return True
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
23
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
24
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
25 class NoopProcessor(SimpleFileProcessor):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
26 def __init__(self, exts):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
27 super(NoopProcessor, self).__init__({exts[0]: exts[1]})
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
28 self.PROCESSOR_NAME = exts[0]
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
29 self.processed = []
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
30
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
31 def _doProcess(self, in_path, out_path):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
32 self.processed.append(in_path)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
33 shutil.copyfile(in_path, out_path)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
34 return True
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
35
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
36
205
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
37 def _get_pipeline(fs, app=None):
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
38 app = app or fs.getApp()
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
39 app.config.set('baker/num_workers', 1)
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
40 return ProcessorPipeline(app, fs.path('counter'))
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
42
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 def test_empty():
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 fs = mock_fs()
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 with mock_fs_scope(fs):
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 pp = _get_pipeline(fs)
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 pp.filterProcessors(['copy'])
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 expected = {}
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 assert expected == fs.getStructure('counter')
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 pp.run()
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 expected = {}
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 assert expected == fs.getStructure('counter')
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 def test_one_file():
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 fs = (mock_fs()
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
57 .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
58 with mock_fs_scope(fs):
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 pp = _get_pipeline(fs)
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 pp.filterProcessors(['copy'])
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 expected = {}
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 assert expected == fs.getStructure('counter')
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 pp.run()
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 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
65 assert expected == fs.getStructure('counter')
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
68 def test_one_level_dirtyness():
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
69 fs = (mock_fs()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
70 .withFile('kitchen/assets/blah.foo', 'A test file.'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
71 with mock_fs_scope(fs):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
72 pp = _get_pipeline(fs)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
73 pp.filterProcessors(['copy'])
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
74 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
75 expected = {'blah.foo': 'A test file.'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
76 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
77 mtime = os.path.getmtime(fs.path('/counter/blah.foo'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
78 assert abs(time.time() - mtime) <= 2
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
79
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 205
diff changeset
80 time.sleep(1)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
81 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
82 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
83 assert mtime == os.path.getmtime(fs.path('/counter/blah.foo'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
84
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 205
diff changeset
85 time.sleep(1)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
86 fs.withFile('kitchen/assets/blah.foo', 'A new test file.')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
87 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
88 expected = {'blah.foo': 'A new test file.'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
89 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
90 assert mtime < os.path.getmtime(fs.path('/counter/blah.foo'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
91
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
92
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
93 def test_two_levels_dirtyness():
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
94 fs = (mock_fs()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
95 .withFile('kitchen/assets/blah.foo', 'A test file.'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
96 with mock_fs_scope(fs) as scope:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
97 pp = _get_pipeline(fs)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
98 pp.processors.append(FooProcessor(('foo', 'bar'), scope._open))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
99 pp.filterProcessors(['foo', 'copy'])
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
100 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
101 expected = {'blah.bar': 'FOO: A test file.'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
102 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
103 mtime = os.path.getmtime(fs.path('/counter/blah.bar'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
104 assert abs(time.time() - mtime) <= 2
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
105
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 205
diff changeset
106 time.sleep(1)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
107 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
108 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
109 assert mtime == os.path.getmtime(fs.path('/counter/blah.bar'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
110
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 205
diff changeset
111 time.sleep(1)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
112 fs.withFile('kitchen/assets/blah.foo', 'A new test file.')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
113 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
114 expected = {'blah.bar': 'FOO: A new test file.'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
115 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
116 assert mtime < os.path.getmtime(fs.path('/counter/blah.bar'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
117
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
118
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
119 def test_removed():
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
120 fs = (mock_fs()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
121 .withFile('kitchen/assets/blah1.foo', 'A test file.')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
122 .withFile('kitchen/assets/blah2.foo', 'Ooops'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
123 with mock_fs_scope(fs):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
124 expected = {
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
125 'blah1.foo': 'A test file.',
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
126 'blah2.foo': 'Ooops'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
127 assert expected == fs.getStructure('kitchen/assets')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
128 pp = _get_pipeline(fs)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
129 pp.filterProcessors(['copy'])
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
130 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
131 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
132
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 205
diff changeset
133 time.sleep(1)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
134 os.remove(fs.path('/kitchen/assets/blah2.foo'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
135 expected = {
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
136 'blah1.foo': 'A test file.'}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
137 assert expected == fs.getStructure('kitchen/assets')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
138 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
139 assert expected == fs.getStructure('counter')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
140
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
141
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
142 def test_record_version_change():
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
143 fs = (mock_fs()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
144 .withFile('kitchen/assets/blah.foo', 'A test file.'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
145 with mock_fs_scope(fs):
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
146 pp = _get_pipeline(fs)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
147 noop = NoopProcessor(('foo', 'foo'))
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
148 pp.processors.append(noop)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
149 pp.filterProcessors(['foo', 'copy'])
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
150 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
151 assert 1 == len(noop.processed)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
152
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
153 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
154 assert 1 == len(noop.processed)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
155
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
156 ProcessorPipelineRecord.RECORD_VERSION += 1
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
157 try:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
158 pp.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
159 assert 2 == len(noop.processed)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
160 finally:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
161 ProcessorPipelineRecord.RECORD_VERSION -= 1
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
162
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 85
diff changeset
163
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 @pytest.mark.parametrize('patterns, expected', [
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 (['_'],
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 {'something.html': 'A test file.'}),
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 (['html'],
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 {}),
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 (['/^_/'],
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 {'something.html': 'A test file.',
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171 'foo': {'_important.html': 'Important!'}})
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 ])
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 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
174 fs = (mock_fs()
36
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
175 .withFile('kitchen/assets/something.html', 'A test file.')
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
176 .withFile('kitchen/assets/_hidden.html', 'Shhh')
485682a6de50 New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents: 35
diff changeset
177 .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
178 with mock_fs_scope(fs):
205
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
179 pp = _get_pipeline(fs)
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
180 pp.addSkipPatterns(patterns)
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 pp.filterProcessors(['copy'])
205
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
182 assert {} == fs.getStructure('counter')
35
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 pp.run()
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 assert expected == fs.getStructure('counter')
e4c345dcf33c More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185
205
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
186
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
187 @pytest.mark.parametrize('names, expected', [
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
188 ('all', ['copy', 'concat', 'less', 'sass', 'sitemap']),
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
189 ('all -sitemap', ['copy', 'concat', 'less', 'sass']),
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
190 ('-sitemap -less -sass all', ['copy', 'concat']),
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
191 ('copy', ['copy']),
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
192 ('less sass', ['less', 'sass'])
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
193 ])
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
194 def test_filter_processor(names, expected):
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
195 fs = mock_fs()
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
196 with mock_fs_scope(fs):
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
197 app = fs.getApp()
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
198 pp = _get_pipeline(fs, app=app)
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
199 pp.filterProcessors('copy concat less sass sitemap')
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
200 procs = pp.getFilteredProcessors(names)
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
201 actual = [p.PROCESSOR_NAME for p in procs]
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
202 assert sorted(actual) == sorted(expected)
e725af1d48fb bake: Changes in how assets directories are configured.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
203