/hyde/tests/test_loader.py

http://github.com/hyde/hyde · Python · 81 lines · 54 code · 21 blank · 6 comment · 1 complexity · eaecd2729f2d203ffc807ebf15a18dfa MD5 · raw file

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