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.
 
 
 

81 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.engine import Engine
  8. from hyde.exceptions import HydeException
  9. from hyde.fs import FS, File, Folder
  10. from hyde.layout import Layout
  11. from nose.tools import raises, with_setup, nottest
  12. TEST_SITE = File(__file__).parent.child_folder('_test')
  13. TEST_SITE_AT_USER = Folder('~/_test')
  14. @nottest
  15. def create_test_site():
  16. TEST_SITE.make()
  17. @nottest
  18. def delete_test_site():
  19. TEST_SITE.delete()
  20. @nottest
  21. def create_test_site_at_user():
  22. TEST_SITE_AT_USER.make()
  23. @nottest
  24. def delete_test_site_at_user():
  25. TEST_SITE_AT_USER.delete()
  26. @raises(HydeException)
  27. @with_setup(create_test_site, delete_test_site)
  28. def test_ensure_exception_when_sitepath_exists():
  29. e = Engine()
  30. e.run(e.parse(['-s', str(TEST_SITE), 'create']))
  31. @with_setup(create_test_site, delete_test_site)
  32. def test_ensure_no_exception_when_sitepath_exists_when_forced():
  33. e = Engine()
  34. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  35. assert True #No Exception
  36. @with_setup(create_test_site, delete_test_site)
  37. def test_ensure_no_exception_when_sitepath_does_not_exist():
  38. e = Engine()
  39. TEST_SITE.delete()
  40. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
  41. verify_site_contents(TEST_SITE, Layout.find_layout())
  42. @with_setup(create_test_site_at_user, delete_test_site_at_user)
  43. def test_ensure_can_create_site_at_user():
  44. e = Engine()
  45. TEST_SITE_AT_USER.delete()
  46. e.run(e.parse(['-s', str(TEST_SITE_AT_USER), 'create', '-f']))
  47. verify_site_contents(TEST_SITE_AT_USER, Layout.find_layout())
  48. @nottest
  49. def verify_site_contents(site, layout):
  50. assert site.exists
  51. assert site.child_folder('layout').exists
  52. assert File(site.child('info.yaml')).exists
  53. expected = map(lambda f: f.get_relative_path(layout), layout.walker.walk_all())
  54. actual = map(lambda f: f.get_relative_path(site), site.walker.walk_all())
  55. assert actual
  56. assert expected
  57. expected.sort()
  58. actual.sort()
  59. assert actual == expected
  60. @raises(HydeException)
  61. @with_setup(create_test_site, delete_test_site)
  62. def test_ensure_exception_when_layout_is_invalid():
  63. e = Engine()
  64. e.run(e.parse(['-s', str(TEST_SITE), 'create', '-l', 'junk']))