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.8 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from textwrap import dedent
  8. from hyde.generator import Generator
  9. from hyde.site import Site
  10. from fswrap import File
  11. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  12. class TestPaginator(object):
  13. def setUp(self):
  14. TEST_SITE.make()
  15. TEST_SITE.parent.child_folder(
  16. 'sites/test_paginator').copy_contents_to(TEST_SITE)
  17. self.s = Site(TEST_SITE)
  18. self.deploy = TEST_SITE.child_folder('deploy')
  19. self.gen = Generator(self.s)
  20. self.gen.load_site_if_needed()
  21. self.gen.load_template_if_needed()
  22. self.gen.generate_all()
  23. def tearDown(self):
  24. TEST_SITE.delete()
  25. def test_page_no_paginator(self):
  26. f = File(self.deploy.child('empty.txt'))
  27. assert f.exists
  28. def test_pages_of_one(self):
  29. pages = ['pages_of_one.txt', 'page2/pages_of_one.txt',
  30. 'page3/pages_of_one.txt', 'page4/pages_of_one.txt']
  31. files = [File(self.deploy.child(p)) for p in pages]
  32. for f in files:
  33. assert f.exists
  34. page5 = File(self.deploy.child('page5/pages_of_one.txt'))
  35. assert not page5.exists
  36. def test_pages_of_one_content(self):
  37. expected_page1_content = dedent('''\
  38. Another Sad Post
  39. /page2/pages_of_one.txt''')
  40. expected_page2_content = dedent('''\
  41. A Happy Post
  42. /pages_of_one.txt
  43. /page3/pages_of_one.txt''')
  44. expected_page3_content = dedent('''\
  45. An Angry Post
  46. /page2/pages_of_one.txt
  47. /page4/pages_of_one.txt''')
  48. expected_page4_content = dedent('''\
  49. A Sad Post
  50. /page3/pages_of_one.txt
  51. ''')
  52. page1 = self.deploy.child('pages_of_one.txt')
  53. content = File(page1).read_all()
  54. assert expected_page1_content == content
  55. page2 = self.deploy.child('page2/pages_of_one.txt')
  56. content = File(page2).read_all()
  57. assert expected_page2_content == content
  58. page3 = self.deploy.child('page3/pages_of_one.txt')
  59. content = File(page3).read_all()
  60. assert expected_page3_content == content
  61. page4 = self.deploy.child('page4/pages_of_one.txt')
  62. content = File(page4).read_all()
  63. assert expected_page4_content == content
  64. def test_pages_of_ten(self):
  65. page1 = self.deploy.child('pages_of_ten.txt')
  66. page2 = self.deploy.child('page2/pages_of_ten.txt')
  67. assert File(page1).exists
  68. assert not File(page2).exists
  69. def test_pages_of_ten_depends(self):
  70. depends = self.gen.deps['pages_of_ten.txt']
  71. assert depends
  72. assert len(depends) == 4
  73. assert 'blog/sad-post.html' in depends
  74. assert 'blog/another-sad-post.html' in depends
  75. assert 'blog/angry-post.html' in depends
  76. assert 'blog/happy-post.html' in depends
  77. def test_pages_of_ten_content(self):
  78. expected_content = dedent('''\
  79. Another Sad Post
  80. A Happy Post
  81. An Angry Post
  82. A Sad Post
  83. ''')
  84. page = self.deploy.child('pages_of_ten.txt')
  85. content = File(page).read_all()
  86. assert expected_content == content
  87. def test_pages_of_one_depends(self):
  88. depends = self.gen.deps['pages_of_one.txt']
  89. assert depends
  90. assert len(depends) == 4
  91. assert 'blog/sad-post.html' in depends
  92. assert 'blog/another-sad-post.html' in depends
  93. assert 'blog/angry-post.html' in depends
  94. assert 'blog/happy-post.html' in depends
  95. def test_custom_file_pattern(self):
  96. page1 = self.deploy.child('custom_file_pattern.txt')
  97. page2 = self.deploy.child('custom_file_pattern-2.txt')
  98. assert File(page1).exists
  99. assert File(page2).exists