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.
 
 
 

171 lines
5.2 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 fswrap import File, Folder
  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. def test_expando_update():
  26. d1 = {"a": 123, "b": "abc"}
  27. x = Expando(d1)
  28. assert x.a == d1['a']
  29. assert x.b == d1['b']
  30. d = {"b": {"c": 456, "d": {"e": "abc"}}, "f": "lmn"}
  31. x.update(d)
  32. assert x.a == d1['a']
  33. assert x.b.c == d['b']['c']
  34. assert x.b.d.e == d['b']['d']['e']
  35. assert x.f == d["f"]
  36. d2 = {"a": 789, "f": "opq"}
  37. y = Expando(d2)
  38. x.update(y)
  39. assert x.a == 789
  40. assert x.f == "opq"
  41. def test_expando_to_dict():
  42. d = {"a": 123, "b": {"c": 456, "d": {"e": "abc"}}}
  43. x = Expando(d)
  44. assert d == x.to_dict()
  45. def test_expando_to_dict_with_update():
  46. d1 = {"a": 123, "b": "abc"}
  47. x = Expando(d1)
  48. d = {"b": {"c": 456, "d": {"e": "abc"}}, "f": "lmn"}
  49. x.update(d)
  50. expected = {}
  51. expected.update(d1)
  52. expected.update(d)
  53. assert expected == x.to_dict()
  54. d2 = {"a": 789, "f": "opq"}
  55. y = Expando(d2)
  56. x.update(y)
  57. expected.update(d2)
  58. assert expected == x.to_dict()
  59. TEST_SITE = File(__file__).parent.child_folder('_test')
  60. import yaml # NOQA
  61. class TestConfig(object):
  62. @classmethod
  63. def setup_class(cls):
  64. cls.conf1 = """
  65. mode: development
  66. content_root: stuff # Relative path from site root
  67. media_root: media # Relative path from site root
  68. media_url: /media
  69. widgets:
  70. plugins:
  71. aggregators:
  72. """
  73. cls.conf2 = """
  74. mode: development
  75. deploy_root: ~/deploy_site
  76. content_root: site/stuff # Relative path from site root
  77. media_root: mmm # Relative path from site root
  78. media_url: /media
  79. widgets:
  80. plugins:
  81. aggregators:
  82. """
  83. def setUp(self):
  84. TEST_SITE.make()
  85. TEST_SITE.parent.child_folder(
  86. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  87. def tearDown(self):
  88. TEST_SITE.delete()
  89. def test_default_configuration(self):
  90. c = Config(sitepath=TEST_SITE, config_dict={})
  91. for root in ['content', 'layout']:
  92. name = root + '_root'
  93. path = name + '_path'
  94. assert hasattr(c, name)
  95. assert getattr(c, name) == root
  96. assert hasattr(c, path)
  97. assert getattr(c, path) == TEST_SITE.child_folder(root)
  98. assert c.media_root_path == c.content_root_path.child_folder('media')
  99. assert hasattr(c, 'plugins')
  100. assert len(c.plugins) == 0
  101. assert hasattr(c, 'ignore')
  102. assert c.ignore == ["*~", "*.bak", ".hg", ".git", ".svn"]
  103. assert c.deploy_root_path == TEST_SITE.child_folder('deploy')
  104. assert c.not_found == '404.html'
  105. assert c.meta.nodemeta == 'meta.yaml'
  106. def test_conf1(self):
  107. c = Config(sitepath=TEST_SITE, config_dict=yaml.load(self.conf1))
  108. assert c.content_root_path == TEST_SITE.child_folder('stuff')
  109. def test_conf2(self):
  110. c = Config(sitepath=TEST_SITE, config_dict=yaml.load(self.conf2))
  111. assert c.content_root_path == TEST_SITE.child_folder('site/stuff')
  112. assert c.media_root_path == c.content_root_path.child_folder('mmm')
  113. assert c.media_url == TEST_SITE.child_folder('/media')
  114. assert c.deploy_root_path == Folder('~/deploy_site')
  115. def test_read_from_file_by_default(self):
  116. File(TEST_SITE.child('site.yaml')).write(self.conf2)
  117. c = Config(sitepath=TEST_SITE)
  118. assert c.content_root_path == TEST_SITE.child_folder('site/stuff')
  119. assert c.media_root_path == c.content_root_path.child_folder('mmm')
  120. assert c.media_url == TEST_SITE.child_folder('/media')
  121. assert c.deploy_root_path == Folder('~/deploy_site')
  122. def test_read_from_specified_file(self):
  123. File(TEST_SITE.child('another.yaml')).write(self.conf2)
  124. c = Config(sitepath=TEST_SITE, config_file='another.yaml')
  125. assert c.content_root_path == TEST_SITE.child_folder('site/stuff')
  126. assert c.media_root_path == c.content_root_path.child_folder('mmm')
  127. assert c.media_url == TEST_SITE.child_folder('/media')
  128. assert c.deploy_root_path == Folder('~/deploy_site')
  129. def test_extends(self):
  130. another = """
  131. extends: site.yaml
  132. mode: production
  133. media_root: xxx
  134. """
  135. File(TEST_SITE.child('site.yaml')).write(self.conf2)
  136. File(TEST_SITE.child('another.yaml')).write(another)
  137. c = Config(sitepath=TEST_SITE, config_file='another.yaml')
  138. assert c.mode == 'production'
  139. assert c.content_root_path == TEST_SITE.child_folder('site/stuff')
  140. assert c.media_root_path == c.content_root_path.child_folder('xxx')
  141. assert c.media_url == TEST_SITE.child_folder('/media')
  142. assert c.deploy_root_path == Folder('~/deploy_site')