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.
 
 
 

153 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.generator import Generator
  8. from hyde.site import Site
  9. from fswrap import File, Folder
  10. COMBINE_SOURCE = File(__file__).parent.child_folder('combine')
  11. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  12. class CombineTester(object):
  13. def _test_combine(self, content):
  14. s = Site(TEST_SITE)
  15. s.config.plugins = [
  16. 'hyde.ext.plugins.meta.MetaPlugin',
  17. 'hyde.ext.plugins.structure.CombinePlugin']
  18. source = TEST_SITE.child('content/media/js/script.js')
  19. target = File(
  20. Folder(s.config.deploy_root_path).child('media/js/script.js'))
  21. File(source).write(content)
  22. gen = Generator(s)
  23. gen.generate_resource_at_path(source)
  24. assert target.exists
  25. text = target.read_all()
  26. return text, s
  27. class TestCombine(CombineTester):
  28. def setUp(self):
  29. TEST_SITE.make()
  30. TEST_SITE.parent.child_folder(
  31. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  32. TEST_SITE.child_folder('content/media/js').make()
  33. COMBINE_SOURCE.copy_contents_to(TEST_SITE.child('content/media/js'))
  34. def tearDown(self):
  35. TEST_SITE.delete()
  36. def test_combine_top(self):
  37. text, _ = self._test_combine("""
  38. ---
  39. combine:
  40. files: script.*.js
  41. where: top
  42. ---
  43. Last line""")
  44. assert text == """var a = 1 + 2;
  45. var b = a + 3;
  46. var c = a + 5;
  47. Last line"""
  48. return
  49. def test_combine_bottom(self):
  50. text, _ = self._test_combine("""
  51. ---
  52. combine:
  53. files: script.*.js
  54. where: bottom
  55. ---
  56. First line
  57. """)
  58. expected = """First line
  59. var a = 1 + 2;
  60. var b = a + 3;
  61. var c = a + 5;
  62. """
  63. assert text.strip() == expected.strip()
  64. return
  65. def test_combine_bottom_unsorted(self):
  66. text, _ = self._test_combine("""
  67. ---
  68. combine:
  69. sort: false
  70. files:
  71. - script.3.js
  72. - script.1.js
  73. - script.2.js
  74. where: bottom
  75. ---
  76. First line
  77. """)
  78. expected = """First line
  79. var c = a + 5;
  80. var a = 1 + 2;
  81. var b = a + 3;
  82. """
  83. assert text.strip() == expected.strip()
  84. return
  85. def test_combine_remove(self):
  86. _, s = self._test_combine("""
  87. ---
  88. combine:
  89. files: script.*.js
  90. remove: yes
  91. ---
  92. First line""")
  93. for i in range(1, 4):
  94. assert not File(Folder(s.config.deploy_root_path).
  95. child('media/js/script.%d.js' % i)).exists
  96. class TestCombinePaths(CombineTester):
  97. def setUp(self):
  98. TEST_SITE.make()
  99. TEST_SITE.parent.child_folder(
  100. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  101. TEST_SITE.child_folder('content/media/js').make()
  102. JS = TEST_SITE.child_folder('content/scripts').make()
  103. S1 = JS.child_folder('s1').make()
  104. S2 = JS.child_folder('s2').make()
  105. S3 = JS.child_folder('s3').make()
  106. File(COMBINE_SOURCE.child('script.1.js')).copy_to(S1)
  107. File(COMBINE_SOURCE.child('script.2.js')).copy_to(S2)
  108. File(COMBINE_SOURCE.child('script.3.js')).copy_to(S3)
  109. def tearDown(self):
  110. TEST_SITE.delete()
  111. def test_combine_top(self):
  112. text, _ = self._test_combine("""
  113. ---
  114. combine:
  115. root: scripts
  116. recurse: true
  117. files: script.*.js
  118. where: top
  119. ---
  120. Last line""")
  121. assert text == """var a = 1 + 2;
  122. var b = a + 3;
  123. var c = a + 5;
  124. Last line"""
  125. return