Mercurial > piecrust2
changeset 492:d90ccdf18156
tests: Fix processing tests on Windows.
See the comment in `pipeline.py` for more info but basically I was passing
already initialized processors to the worker pool, which means pickling the
whole app. Pretty bad. Interesting that it only broke on Windows, though.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 23 Jul 2015 22:07:32 -0700 |
parents | 152a15046b41 |
children | 95b77239c3b7 |
files | piecrust/processing/pipeline.py tests/test_processing_base.py |
diffstat | 2 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/processing/pipeline.py Wed Jul 22 22:21:42 2015 -0700 +++ b/piecrust/processing/pipeline.py Thu Jul 23 22:07:32 2015 -0700 @@ -57,8 +57,15 @@ self.force_patterns = make_re(baker_params.get('force', [])) # Those things are mostly for unit-testing. + # + # Note that additiona processors can't be passed as instances. + # Instead, we need some factory functions because we need to create + # one instance right away to use during the initialization phase, and + # another instance to pass to the worker pool. The initialized one will + # be tied to the PieCrust app instance, which can't be pickled across + # processes. self.enabled_processors = None - self.additional_processors = None + self.additional_processors_factories = None def addIgnorePatterns(self, patterns): self.ignore_patterns += make_re(patterns) @@ -74,10 +81,11 @@ self.enabled_processors) processors = get_filtered_processors(processors, self.enabled_processors) - if self.additional_processors is not None: + if self.additional_processors_factories is not None: logger.debug("Adding %s additional processors." % - len(self.additional_processors)) - for proc in self.additional_processors: + len(self.additional_processors_factories)) + for proc_fac in self.additional_processors_factories: + proc = proc_fac() self.app.env.registerTimer(proc.__class__.__name__, raise_if_registered=False) proc.initialize(self.app) @@ -248,7 +256,10 @@ self.app.root_dir, self.out_dir, self.tmp_dir, self.force, self.app.debug) ctx.enabled_processors = self.enabled_processors - ctx.additional_processors = self.additional_processors + if self.additional_processors_factories is not None: + ctx.additional_processors = [ + proc_fac() + for proc_fac in self.additional_processors_factories] pool = WorkerPool( worker_class=ProcessingWorker,
--- a/tests/test_processing_base.py Wed Jul 22 22:21:42 2015 -0700 +++ b/tests/test_processing_base.py Thu Jul 23 22:07:32 2015 -0700 @@ -97,7 +97,8 @@ with mock_fs_scope(fs): pp = _get_pipeline(fs) pp.enabled_processors = ['copy'] - pp.additional_processors = [FooProcessor(('foo', 'bar'))] + pp.additional_processors_factories = [ + lambda: FooProcessor(('foo', 'bar'))] pp.run() expected = {'blah.bar': 'FOO: A test file.'} assert expected == fs.getStructure('counter') @@ -145,9 +146,9 @@ .withFile('kitchen/assets/blah.foo', 'A test file.')) with mock_fs_scope(fs): pp = _get_pipeline(fs) - noop = NoopProcessor(('foo', 'foo')) pp.enabled_processors = ['copy'] - pp.additional_processors = [noop] + pp.additional_processors_factories = [ + lambda: NoopProcessor(('foo', 'foo'))] pp.run() assert os.path.exists(fs.path('/counter/blah.foo')) is True mtime = os.path.getmtime(fs.path('/counter/blah.foo'))