Mercurial > piecrust2
comparison tests/test_templating_jinjaengine.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | 72f17534d58e |
children |
comparison
equal
deleted
inserted
replaced
978:7e51d14097cb | 979:45ad976712ec |
---|---|
24 def test_simple(contents, expected): | 24 def test_simple(contents, expected): |
25 fs = (mock_fs() | 25 fs = (mock_fs() |
26 .withConfig(app_config) | 26 .withConfig(app_config) |
27 .withPage('pages/foo', config=page_config, contents=contents)) | 27 .withPage('pages/foo', config=page_config, contents=contents)) |
28 with mock_fs_scope(fs, open_patches=open_patches): | 28 with mock_fs_scope(fs, open_patches=open_patches): |
29 app = fs.getApp() | |
30 page = fs.getSimplePage('foo.md') | 29 page = fs.getSimplePage('foo.md') |
31 route = app.getSourceRoute('pages') | 30 output = render_simple_page(page) |
32 route_metadata = {'slug': 'foo'} | |
33 output = render_simple_page(page, route, route_metadata) | |
34 assert output == expected | 31 assert output == expected |
35 | 32 |
36 | 33 |
37 def test_layout(): | 34 def test_layout(): |
38 contents = "Blah\n" | 35 contents = "Blah\n" |
39 layout = "{{content}}\nFor site: {{foo}}\n" | 36 layout = "{{content}}\nFor site: {{foo}}\n" |
40 expected = "Blah\n\nFor site: bar" | 37 expected = "Blah\n\nFor site: bar" |
41 fs = (mock_fs() | 38 fs = (mock_fs() |
42 .withConfig(app_config) | 39 .withConfig(app_config) |
43 .withAsset('templates/blah.jinja', layout) | 40 .withAsset('templates/blah.jinja', layout) |
44 .withPage('pages/foo', config={'layout': 'blah'}, | 41 .withPage('pages/foo', config={'layout': 'blah.jinja'}, |
45 contents=contents)) | 42 contents=contents)) |
46 with mock_fs_scope(fs, open_patches=open_patches): | 43 with mock_fs_scope(fs, open_patches=open_patches): |
47 app = fs.getApp() | |
48 page = fs.getSimplePage('foo.md') | 44 page = fs.getSimplePage('foo.md') |
49 route = app.getSourceRoute('pages', None) | 45 output = render_simple_page(page) |
50 route_metadata = {'slug': 'foo'} | |
51 output = render_simple_page(page, route, route_metadata) | |
52 assert output == expected | 46 assert output == expected |
53 | 47 |
54 | 48 |
55 def test_partial(): | 49 def test_partial(): |
56 contents = "Info:\n{% include 'page_info.jinja' %}\n" | 50 contents = "Info:\n{% include 'page_info.jinja' %}\n" |
57 partial = "- URL: {{page.url}}\n- SLUG: {{page.slug}}\n" | 51 partial = "- URL: {{page.url}}\n- SLUG: {{page.route.slug}}\n" |
58 expected = "Info:\n- URL: /foo.html\n- SLUG: foo" | 52 expected = "Info:\n- URL: /foo.html\n- SLUG: foo" |
59 fs = (mock_fs() | 53 fs = (mock_fs() |
60 .withConfig(app_config) | 54 .withConfig(app_config) |
61 .withAsset('templates/page_info.jinja', partial) | 55 .withAsset('templates/page_info.jinja', partial) |
62 .withPage('pages/foo', config=page_config, contents=contents)) | 56 .withPage('pages/foo', config=page_config, contents=contents)) |
63 with mock_fs_scope(fs, open_patches=open_patches): | 57 with mock_fs_scope(fs, open_patches=open_patches): |
64 app = fs.getApp() | |
65 page = fs.getSimplePage('foo.md') | 58 page = fs.getSimplePage('foo.md') |
66 route = app.getSourceRoute('pages', None) | 59 output = render_simple_page(page) |
67 route_metadata = {'slug': 'foo'} | |
68 output = render_simple_page(page, route, route_metadata) | |
69 assert output == expected | 60 assert output == expected |
70 | 61 |