PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/hyde/tests/test_loader.py

http://github.com/hyde/hyde
Python | 81 lines | 60 code | 15 blank | 6 comment | 0 complexity | eaecd2729f2d203ffc807ebf15a18dfa MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Use nose
 4`$ pip install nose`
 5`$ nosetests`
 6"""
 7
 8from hyde.loader import load_python_object
 9from nose.tools import raises
10import os
11
12from hyde.exceptions import HydeException
13from hyde.fs import File, Folder
14from hyde.generator import Generator
15from hyde.site import Site
16
17
18
19def test_can_load_locals():
20
21    file_class = load_python_object('hyde.fs.File')
22    assert file_class
23
24    f = file_class(__file__)
25    assert f
26
27    assert f.name == os.path.basename(__file__)
28
29
30def test_can_load_from_python_path():
31
32    markdown = load_python_object('markdown.markdown')
33    assert markdown
34
35    assert "<h3>h3</h3>" == markdown("### h3")
36
37def test_can_load_module_without_dot():
38
39    yaml = load_python_object('yaml')
40
41    abc = yaml.load("""
42        d: efg
43        l: mno
44    """)
45
46    assert abc['d'] == 'efg'
47    assert abc['l'] == 'mno'
48
49def test_can_load_site_specific_plugins():
50    
51    TEST_SITE = File(__file__).parent.child_folder('_test')
52    TEST_SITE.make()
53    TEST_SITE.parent.child_folder(
54                  'sites/test_jinja').copy_contents_to(TEST_SITE)
55    TEST_SITE.parent.child_folder(
56                  'ssp').copy_contents_to(TEST_SITE)
57    s = Site(TEST_SITE)
58    gen = Generator(s)
59    gen.generate_all()
60    banner = """
61<!--
62This file was produced with infinite love, care & sweat.
63Please dont copy. If you have to, please drop me a note.
64-->
65"""
66    with TEST_SITE.child_folder('deploy').get_walker('*.html') as walker:
67        
68        @walker.file_visitor
69        def visit_file(f):
70            text = f.read_all()
71            assert text.strip().startswith(banner.strip())
72
73@raises(HydeException)
74def test_exception_raised_for_invalid_module():
75    load_python_object("junk.junk.junk")
76    assert False
77
78@raises(HydeException)
79def test_exception_raised_for_invalid_object():
80    load_python_object("markdown.junk")
81    assert False