PageRenderTime 28ms CodeModel.GetById 19ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_depends.py

http://github.com/hyde/hyde
Python | 55 lines | 42 code | 7 blank | 6 comment | 0 complexity | 89f45bc218a041d48606b188033717dc 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
10from fswrap import File
11
12TEST_SITE = File(__file__).parent.parent.child_folder('_test')
13
14
15class TestDepends(object):
16
17    def setUp(self):
18        TEST_SITE.make()
19        TEST_SITE.parent.child_folder(
20                    'sites/test_jinja').copy_contents_to(TEST_SITE)
21        TEST_SITE.parent.child_folder(
22                    'templates/jinja2').copy_contents_to(
23                        TEST_SITE.child_folder('content'))
24
25    def tearDown(self):
26        TEST_SITE.delete()
27
28    def test_depends(self):
29        s = Site(TEST_SITE)
30        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin',
31                            'hyde.ext.plugins.depends.DependsPlugin']
32        text = """
33===
34depends: index.html
35===
36
37"""
38        inc = File(TEST_SITE.child('content/inc.md'))
39        inc.write(text)
40        gen = Generator(s)
41        gen.load_site_if_needed()
42        gen.load_template_if_needed()
43        def dateformat(x):
44            return x.strftime('%Y-%m-%d')
45        gen.template.env.filters['dateformat'] = dateformat
46        gen.generate_resource_at_path(inc.name)
47        res = s.content.resource_from_relative_path(inc.name)
48        assert len(res.depends) == 1
49        assert 'index.html' in res.depends
50        deps = list(gen.get_dependencies(res))
51        assert len(deps) == 3
52
53        assert 'helpers.html' in deps
54        assert 'layout.html' in deps
55        assert 'index.html' in deps