Mercurial > piecrust2
annotate tests/mockutil.py @ 415:0e9a94b7fdfa
bake: Improve bake record information.
* Store things in the bake record that require less interaction between the
master process and the workers. For instance, don't store the paginator
object in the render pass info -- instead, just store whether pagination
was used, and whether it had more items.
* Simplify information passing between workers and bake passes by saving the
rendering info to the JSON cache. This means the "render first sub" job
doesn't have to return anything except errors now.
* Add more performance counter info.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 20 Jun 2015 19:23:16 -0700 |
parents | e7b865f8f335 |
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 |