Mercurial > piecrust2
comparison tests/mockutil.py @ 181:d356f6178623
tests: Add help functions to get and render a simple page.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jan 2015 14:53:13 -0800 |
parents | 133845647083 |
children | a54d3c0b5f4a |
comparison
equal
deleted
inserted
replaced
180:ede1a59f481d | 181:d356f6178623 |
---|---|
2 import time | 2 import time |
3 import random | 3 import random |
4 import codecs | 4 import codecs |
5 import shutil | 5 import shutil |
6 import os.path | 6 import os.path |
7 import functools | |
8 import mock | 7 import mock |
9 import yaml | 8 import yaml |
10 from piecrust.app import PieCrust, PieCrustConfiguration | 9 from piecrust.app import PieCrust, PieCrustConfiguration |
10 from piecrust.page import Page | |
11 from piecrust.rendering import PageRenderingContext, render_page | |
11 | 12 |
12 | 13 |
13 resources_path = os.path.abspath( | 14 resources_path = os.path.abspath( |
14 os.path.join( | 15 os.path.join( |
15 os.path.dirname(__file__), | 16 os.path.dirname(__file__), |
18 | 19 |
19 def get_mock_app(config=None): | 20 def get_mock_app(config=None): |
20 app = mock.MagicMock(spec=PieCrust) | 21 app = mock.MagicMock(spec=PieCrust) |
21 app.config = PieCrustConfiguration() | 22 app.config = PieCrustConfiguration() |
22 return app | 23 return app |
24 | |
25 | |
26 def get_simple_page(app, rel_path): | |
27 source = app.getSource('pages') | |
28 metadata = {'path': os.path.splitext(rel_path)[0]} | |
29 return Page(source, metadata, rel_path) | |
30 | |
31 | |
32 def render_simple_page(page, uri): | |
33 ctx = PageRenderingContext(page, uri) | |
34 rp = render_page(ctx) | |
35 return rp.content | |
23 | 36 |
24 | 37 |
25 class _MockFsEntry(object): | 38 class _MockFsEntry(object): |
26 def __init__(self, contents): | 39 def __init__(self, contents): |
27 self.contents = contents | 40 self.contents = contents |