Mercurial > piecrust2
annotate tests/mockutil.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 | 65db6df28120 |
children | fd694f1297c7 |
rev | line source |
---|---|
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
1 import os.path |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import mock |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from piecrust.app import PieCrust, PieCrustConfiguration |
181
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
4 from piecrust.page import Page |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
349
diff
changeset
|
5 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 def get_mock_app(config=None): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 app = mock.MagicMock(spec=PieCrust) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 app.config = PieCrustConfiguration() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 return app |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
6
f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
13 |
181
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
14 def get_simple_page(app, rel_path): |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
15 source = app.getSource('pages') |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
349
diff
changeset
|
16 metadata = {'slug': os.path.splitext(rel_path)[0]} |
181
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
17 return Page(source, metadata, rel_path) |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
18 |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
19 |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
349
diff
changeset
|
20 def render_simple_page(page, route, route_metadata): |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
349
diff
changeset
|
21 qp = QualifiedPage(page, route, route_metadata) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
349
diff
changeset
|
22 ctx = PageRenderingContext(qp) |
181
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
23 rp = render_page(ctx) |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
24 return rp.content |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
25 |
d356f6178623
tests: Add help functions to get and render a simple page.
Ludovic Chabant <ludovic@chabant.com>
parents:
120
diff
changeset
|
26 |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
394
diff
changeset
|
27 from .tmpfs import ( |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
394
diff
changeset
|
28 TempDirFileSystem as mock_fs, |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
394
diff
changeset
|
29 TempDirScope as mock_fs_scope) |
35
e4c345dcf33c
More unit tests, fix a bug with the skip patterns.
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
30 |