A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.model import Config, Expando
  8. from hyde.fs import *
  9. def test_expando_one_level():
  10. d = {"a": 123, "b": "abc"}
  11. x = Expando(d)
  12. assert x.a == d['a']
  13. assert x.b == d['b']
  14. def test_expando_two_levels():
  15. d = {"a": 123, "b": {"c": 456}}
  16. x = Expando(d)
  17. assert x.a == d['a']
  18. assert x.b.c == d['b']['c']
  19. def test_expando_three_levels():
  20. d = {"a": 123, "b": {"c": 456, "d": {"e": "abc"}}}
  21. x = Expando(d)
  22. assert x.a == d['a']
  23. assert x.b.c == d['b']['c']
  24. assert x.b.d.e == d['b']['d']['e']
  25. TEST_SITE_ROOT = File(__file__).parent.child_folder('sites/test_jinja')
  26. import yaml
  27. class TestConfig(object):
  28. @classmethod
  29. def setup_class(cls):
  30. cls.conf1 = """
  31. mode: development
  32. content_root: stuff # Relative path from site root
  33. media_root: media # Relative path from site root
  34. media_url: /media
  35. widgets:
  36. plugins:
  37. aggregators:
  38. """
  39. cls.conf2 = """
  40. mode: development
  41. deploy_root: ~/deploy_site
  42. content_root: site/stuff # Relative path from site root
  43. media_root: mmm # Relative path from site root
  44. media_url: /media
  45. widgets:
  46. plugins:
  47. aggregators:
  48. """
  49. def test_default_configuration(self):
  50. c = Config(sitepath=TEST_SITE_ROOT)
  51. for root in ['content', 'layout', 'media']:
  52. name = root + '_root'
  53. path = name + '_path'
  54. assert hasattr(c, name)
  55. assert getattr(c, name) == root
  56. assert hasattr(c, path)
  57. assert getattr(c, path) == TEST_SITE_ROOT.child_folder(root)
  58. assert c.deploy_root_path == TEST_SITE_ROOT.child_folder('deploy')
  59. def test_conf1(self):
  60. c = Config(sitepath=TEST_SITE_ROOT, config_dict=yaml.load(self.conf1))
  61. assert c.content_root_path == TEST_SITE_ROOT.child_folder('stuff')
  62. def test_conf2(self):
  63. c = Config(sitepath=TEST_SITE_ROOT, config_dict=yaml.load(self.conf2))
  64. assert c.content_root_path == TEST_SITE_ROOT.child_folder('site/stuff')
  65. assert c.media_root_path == TEST_SITE_ROOT.child_folder('mmm')
  66. assert c.media_url == TEST_SITE_ROOT.child_folder('/media')
  67. print c.deploy_root_path
  68. assert c.deploy_root_path == Folder('~/deploy_site')