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.
 
 
 

127 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde._compat import str
  8. from hyde.engine import Engine
  9. from hyde.exceptions import HydeException
  10. from hyde.layout import Layout
  11. from fswrap import File, Folder
  12. from nose.tools import raises, with_setup, nottest
  13. TEST_SITE = File(__file__).parent.child_folder('_test')
  14. TEST_SITE_AT_USER = Folder('~/_test')
  15. @nottest
  16. def create_test_site():
  17. TEST_SITE.make()
  18. @nottest
  19. def delete_test_site():
  20. TEST_SITE.delete()
  21. @nottest
  22. def create_test_site_at_user():
  23. TEST_SITE_AT_USER.make()
  24. @nottest
  25. def delete_test_site_at_user():
  26. TEST_SITE_AT_USER.delete()
  27. @raises(HydeException)
  28. @with_setup(create_test_site, delete_test_site)
  29. def test_ensure_exception_when_site_yaml_exists():
  30. e = Engine(raise_exceptions=True)
  31. File(TEST_SITE.child('site.yaml')).write("Hey")
  32. e.run(e.parse(['-s', str(TEST_SITE), 'create']))
  33. @raises(HydeException)
  34. @with_setup(create_test_site, delete_test_site)
  35. def test_ensure_exception_when_content_folder_exists():
  36. e = Engine(raise_exceptions=True)
  37. TEST_SITE.child_folder('content').make()
  38. e.run(e.parse(['-s', str(TEST_SITE), 'create']))
  39. @raises(HydeException)
  40. @with_setup(create_test_site, delete_test_site)
  41. def test_ensure_exception_when_layout_folder_exists():
  42. e = Engine(raise_exceptions=True)
  43. TEST_SITE.child_folder('layout').make()
  44. e.run(e.parse(['-s', str(TEST_SITE), 'create']))
  45. @with_setup(create_test_site, delete_test_site)
  46. def test_ensure_no_exception_when_empty_site_exists():
  47. e = Engine(raise_exceptions=True)
  48. e.run(e.parse(['-s', str(TEST_SITE), 'create']))
  49. verify_site_contents(TEST_SITE, Layout.find_layout())
  50. @with_setup(create_test_site, delete_test_site)
  51. def test_ensure_no_exception_when_forced():
  52. e = Engine(raise_exceptions=True)
  53. TEST_SITE.child_folder('layout').make()
  54. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  55. verify_site_contents(TEST_SITE, Layout.find_layout())
  56. TEST_SITE.delete()
  57. TEST_SITE.child_folder('content').make()
  58. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  59. verify_site_contents(TEST_SITE, Layout.find_layout())
  60. TEST_SITE.delete()
  61. TEST_SITE.make()
  62. File(TEST_SITE.child('site.yaml')).write("Hey")
  63. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  64. verify_site_contents(TEST_SITE, Layout.find_layout())
  65. @with_setup(create_test_site, delete_test_site)
  66. def test_ensure_no_exception_when_sitepath_does_not_exist():
  67. e = Engine(raise_exceptions=True)
  68. TEST_SITE.delete()
  69. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  70. verify_site_contents(TEST_SITE, Layout.find_layout())
  71. @with_setup(create_test_site_at_user, delete_test_site_at_user)
  72. def test_ensure_can_create_site_at_user():
  73. e = Engine(raise_exceptions=True)
  74. TEST_SITE_AT_USER.delete()
  75. e.run(e.parse(['-s', str(TEST_SITE_AT_USER), 'create', '-f']))
  76. verify_site_contents(TEST_SITE_AT_USER, Layout.find_layout())
  77. @nottest
  78. def verify_site_contents(site, layout):
  79. assert site.exists
  80. assert site.child_folder('layout').exists
  81. assert File(site.child('info.yaml')).exists
  82. expected = list(map(
  83. lambda f: f.get_relative_path(layout), layout.walker.walk_all()))
  84. actual = list(map(
  85. lambda f: f.get_relative_path(site), site.walker.walk_all()))
  86. assert actual
  87. assert expected
  88. expected.sort()
  89. actual.sort()
  90. assert actual == expected
  91. @raises(HydeException)
  92. @with_setup(create_test_site, delete_test_site)
  93. def test_ensure_exception_when_layout_is_invalid():
  94. e = Engine(raise_exceptions=True)
  95. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-l', 'junk']))