comparison tests/test_templating_pystacheengine.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', None) 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\n" 37 expected = "Blah\n\nFor site: bar\n"
41 fs = (mock_fs() 38 fs = (mock_fs()
42 .withConfig(app_config) 39 .withConfig(app_config)
43 .withAsset('templates/blah.mustache', layout) 40 .withAsset('templates/blah.mustache', layout)
44 .withPage('pages/foo', config={'layout': 'blah'}, 41 .withPage('pages/foo', config={'layout': 'blah.mustache'},
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 # On Windows, pystache unexplicably adds `\r` to some newlines... wtf. 46 # On Windows, pystache unexplicably adds `\r` to some newlines... wtf.
53 output = output.replace('\r', '') 47 output = output.replace('\r', '')
54 assert output == expected 48 assert output == expected
55 49
56 50
57 def test_partial(): 51 def test_partial():
58 contents = "Info:\n{{#page}}\n{{> page_info}}\n{{/page}}\n" 52 contents = "Info:\n{{#page}}\n{{> page_info}}\n{{/page}}\n"
59 partial = "- URL: {{url}}\n- SLUG: {{slug}}\n" 53 partial = "- URL: {{url}}\n- SLUG: {{route.slug}}\n"
60 expected = "Info:\n- URL: /foo.html\n- SLUG: foo\n" 54 expected = "Info:\n- URL: /foo.html\n- SLUG: foo\n"
61 fs = (mock_fs() 55 fs = (mock_fs()
62 .withConfig(app_config) 56 .withConfig(app_config)
63 .withAsset('templates/page_info.mustache', partial) 57 .withAsset('templates/page_info.mustache', partial)
64 .withPage('pages/foo', config=page_config, contents=contents)) 58 .withPage('pages/foo', config=page_config, contents=contents))
65 with mock_fs_scope(fs, open_patches=open_patches): 59 with mock_fs_scope(fs, open_patches=open_patches):
66 app = fs.getApp()
67 page = fs.getSimplePage('foo.md') 60 page = fs.getSimplePage('foo.md')
68 route = app.getSourceRoute('pages', None) 61 output = render_simple_page(page)
69 route_metadata = {'slug': 'foo'}
70 output = render_simple_page(page, route, route_metadata)
71 # On Windows, pystache unexplicably adds `\r` to some newlines... wtf. 62 # On Windows, pystache unexplicably adds `\r` to some newlines... wtf.
72 output = output.replace('\r', '') 63 output = output.replace('\r', '')
73 assert output == expected 64 assert output == expected
74 65