PageRenderTime 45ms CodeModel.GetById 38ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_markings.py

http://github.com/hyde/hyde
Python | 118 lines | 103 code | 9 blank | 6 comment | 12 complexity | e4a8896615f31d9c757460655e049f46 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
 11from pyquery import PyQuery
 12
 13TEST_SITE = File(__file__).parent.parent.child_folder('_test')
 14
 15def assert_valid_conversion(html):
 16    assert html
 17    q = PyQuery(html)
 18    assert "is_processable" not in html
 19    assert q("h1")
 20    assert "This is a" in q("h1").text()
 21    assert "heading" in q("h1").text()
 22    assert q(".amp").length == 1
 23    assert "mark" not in html
 24    assert "reference" not in html
 25    assert '.' not in q.text()
 26    assert '/' not in q.text()
 27
 28class TestMarkings(object):
 29
 30    def setUp(self):
 31        TEST_SITE.make()
 32        TEST_SITE.parent.child_folder(
 33                    'sites/test_jinja').copy_contents_to(TEST_SITE)
 34
 35    def tearDown(self):
 36        TEST_SITE.delete()
 37
 38
 39
 40    def test_mark(self):
 41        text = u"""
 42===
 43is_processable: False
 44===
 45{% filter markdown|typogrify %}
 46§§ heading
 47This is a heading
 48=================
 49§§ /heading
 50
 51§§ content
 52Hyde & Jinja
 53§§ /
 54
 55{% endfilter %}
 56"""
 57
 58        text2 = """
 59{% refer to "inc.md" as inc %}
 60{% filter markdown|typogrify %}
 61{{ inc.heading }}
 62{{ inc.content }}
 63{% endfilter %}
 64"""
 65        site = Site(TEST_SITE)
 66        site.config.plugins = [
 67            'hyde.ext.plugins.meta.MetaPlugin',
 68            'hyde.ext.plugins.text.MarkingsPlugin']
 69        inc = File(TEST_SITE.child('content/inc.md'))
 70        inc.write(text)
 71        site.load()
 72        gen = Generator(site)
 73        gen.load_template_if_needed()
 74
 75        template = gen.template
 76        html = template.render(text2, {}).strip()
 77        assert_valid_conversion(html)
 78
 79    def test_reference(self):
 80        text = u"""
 81===
 82is_processable: False
 83===
 84{% filter markdown|typogrify %}
 85§§ heading
 86This is a heading
 87=================
 88§§ /heading
 89
 90§§ content
 91Hyde & Jinja
 92§§ /
 93
 94{% endfilter %}
 95"""
 96
 97        text2 = u"""
 98※ inc.md as inc
 99{% filter markdown|typogrify %}
100{{ inc.heading }}
101{{ inc.content }}
102{% endfilter %}
103"""
104        site = Site(TEST_SITE)
105        site.config.plugins = [
106            'hyde.ext.plugins.meta.MetaPlugin',
107            'hyde.ext.plugins.text.MarkingsPlugin',
108            'hyde.ext.plugins.text.ReferencePlugin']
109        inc = File(site.content.source_folder.child('inc.md'))
110        inc.write(text.strip())
111        src = File(site.content.source_folder.child('src.html'))
112        src.write(text2.strip())
113        gen = Generator(site)
114        gen.generate_all()
115        f = File(site.config.deploy_root_path.child(src.name))
116        assert f.exists
117        html = f.read_all()
118        assert_valid_conversion(html)