Mercurial > piecrust2
diff tests/test_baking_baker.py @ 347:76c838453dbe
tests: Support for YAML-based baking tests. Convert old code-based ones.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 15 Apr 2015 16:39:35 -0700 |
parents | 422052d2e978 |
children | e7b865f8f335 |
line wrap: on
line diff
--- a/tests/test_baking_baker.py Wed Apr 15 16:38:55 2015 -0700 +++ b/tests/test_baking_baker.py Wed Apr 15 16:39:35 2015 -0700 @@ -49,44 +49,6 @@ assert expected == path -def test_empty_bake(): - fs = mock_fs() - with mock_fs_scope(fs): - out_dir = fs.path('kitchen/_counter') - assert not os.path.isdir(out_dir) - app = fs.getApp() - baker = Baker(app, out_dir) - baker.bake() - assert os.path.isdir(out_dir) - structure = fs.getStructure('kitchen/_counter') - assert list(structure.keys()) == ['index.html'] - - -@pytest.mark.parametrize( - 'site_root', - [ - ('/'), ('/whatever') - ]) -def test_simple_bake(site_root): - pconf = {'layout': 'none', 'format': 'none'} - fs = (mock_fs() - .withConfig({'site': {'root': site_root}}) - .withPage('posts/2010-01-01_post1.md', pconf, 'post one') - .withPage('pages/about.md', pconf, 'URL: {{page.url}}') - .withPage('pages/_index.md', pconf, "something")) - with mock_fs_scope(fs): - out_dir = fs.path('kitchen/_counter') - app = fs.getApp() - baker = Baker(app, out_dir) - baker.bake() - structure = fs.getStructure('kitchen/_counter') - assert structure == { - '2010': {'01': {'01': {'post1.html': 'post one'}}}, - 'about.html': 'URL: %s' % ( - site_root.rstrip('/') + '/about.html'), - 'index.html': 'something'} - - def test_removed(): fs = (mock_fs() .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page') @@ -135,65 +97,3 @@ finally: BakeRecord.RECORD_VERSION -= 1 - -def test_bake_tags(): - tags = [ - ['foo'], - ['bar', 'whatever'], - ['foo', 'bar']] - - def config_factory(i): - c = {'title': 'Post %d' % (i + 1)} - c['tags'] = tags[i] - return c - - fs = (mock_fs() - .withPages(3, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', - config_factory) - .withPage('pages/_tag.md', {'layout': 'none', 'format': 'none'}, - "Pages in {{tag}}\n" - "{%for p in pagination.posts -%}\n" - "{{p.title}}\n" - "{%endfor%}")) - with mock_fs_scope(fs): - out_dir = fs.path('kitchen/_counter') - app = fs.getApp() - baker = Baker(app, out_dir) - r = baker.bake() - assert r.success is True - - s = fs.getStructure('kitchen/_counter/tag') - assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n" - assert s['bar.html'] == "Pages in bar\nPost 3\nPost 2\n" - assert s['whatever.html'] == "Pages in whatever\nPost 2\n" - - -def test_bake_categories(): - categories = [ - 'foo', 'bar', 'foo'] - - def config_factory(i): - c = {'title': 'Post %d' % (i + 1)} - c['category'] = categories[i] - return c - - fs = (mock_fs() - .withConfig({'site': {'category_url': 'cat/%category%'}}) - .withPages(3, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', - config_factory) - .withPage('pages/_category.md', {'layout': 'none', 'format': 'none'}, - "Pages in {{category}}\n" - "{%for p in pagination.posts -%}\n" - "{{p.title}}\n" - "{%endfor%}")) - with mock_fs_scope(fs): - out_dir = fs.path('kitchen/_counter') - app = fs.getApp() - baker = Baker(app, out_dir) - baker.bake() - - print(fs.getStructure('kitchen/_counter').keys()) - s = fs.getStructure('kitchen/_counter/cat') - assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n" - assert s['bar.html'] == "Pages in bar\nPost 2\n" -