PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_auto_extend.py

http://github.com/hyde/hyde
Python | 72 lines | 57 code | 9 blank | 6 comment | 0 complexity | ddfbaa9a30b0a321732d3bd987cbc346 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Use nose
 4`$ pip install nose`
 5`$ nosetests`
 6"""
 7from hyde.generator import Generator
 8from hyde.site import Site
 9
10
11from fswrap import File
12from nose.tools import nottest
13from pyquery import PyQuery
14
15TEST_SITE = File(__file__).parent.parent.child_folder('_test')
16
17
18class TestAutoExtend(object):
19
20    def setUp(self):
21        TEST_SITE.make()
22        TEST_SITE.parent.child_folder(
23                    'sites/test_jinja').copy_contents_to(TEST_SITE)
24
25    def tearDown(self):
26        TEST_SITE.delete()
27
28    @nottest
29    def assert_extended(self, s, txt, templ):
30        content = (templ.strip() % txt).strip()
31        bd = File(TEST_SITE.child('content/auto_extend.html'))
32        bd.write(content)
33        gen = Generator(s)
34        gen.generate_resource_at_path(bd.path)
35        res = s.content.resource_from_path(bd.path)
36        target = File(s.config.deploy_root_path.child(res.relative_deploy_path))
37        assert target.exists
38        text = target.read_all()
39        q = PyQuery(text)
40        assert q('title').text().strip() == txt.strip()
41
42    def test_can_auto_extend(self):
43        s = Site(TEST_SITE)
44        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin',
45                            'hyde.ext.plugins.meta.AutoExtendPlugin',
46                            'hyde.ext.plugins.text.BlockdownPlugin']
47        txt ="This template tests to make sure blocks can be replaced with markdownish syntax."
48        templ = """
49---
50extends: base.html
51---
52=====title========
53%s
54====/title========"""
55        self.assert_extended(s, txt, templ)
56
57
58
59    def test_can_auto_extend_with_default_blocks(self):
60        s = Site(TEST_SITE)
61        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin',
62                            'hyde.ext.plugins.meta.AutoExtendPlugin',
63                            'hyde.ext.plugins.text.BlockdownPlugin']
64        txt ="This template tests to make sure blocks can be replaced with markdownish syntax."
65        templ = """
66---
67extends: base.html
68default_block: title
69---
70%s
71"""
72        self.assert_extended(s, txt, templ)