PageRenderTime 6ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/hyde/tests/ext/test_auto_extend.py

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