test_asciidoc_reader.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import datetime
  4. import os
  5. from pelican.readers import Readers
  6. from pelican.tests.support import unittest, get_settings
  7. from .asciidoc_reader import ENABLED
  8. CUR_DIR = os.path.dirname(__file__)
  9. CONTENT_PATH = os.path.join(CUR_DIR, 'test_data')
  10. @unittest.skipUnless(ENABLED, "asciidoc isn't installed")
  11. class AsciiDocReaderTest(unittest.TestCase):
  12. def read_file(self, path, **kwargs):
  13. # Isolate from future API changes to readers.read_file
  14. r = Readers(settings=get_settings(**kwargs))
  15. return r.read_file(base_path=CONTENT_PATH, path=path)
  16. def test_article_with_asc_extension(self):
  17. # Ensure the asc extension is being processed by the correct reader
  18. page = self.read_file(
  19. path='article_with_asc_extension.asc')
  20. expected = ('<div class="sect1">'
  21. '<h2 id="_used_for_pelican_test">'
  22. 'Used for pelican test</h2>'
  23. '<div class="sectionbody">'
  24. '<div class="paragraph">'
  25. '<p>The quick brown fox jumped over '
  26. 'the lazy dog&#8217;s back.</p>'
  27. '</div></div></div>')
  28. actual = "".join(page.content.splitlines())
  29. expected = "".join(expected.splitlines())
  30. self.assertEqual(actual, expected)
  31. expected = {
  32. 'category': 'Blog',
  33. 'author': 'Author O. Article',
  34. 'title': 'Test AsciiDoc File Header',
  35. 'date': datetime.datetime(2011, 9, 15, 9, 5),
  36. 'tags': ['Linux', 'Python', 'Pelican'],
  37. }
  38. for key, value in expected.items():
  39. self.assertEqual(value, page.metadata[key], (
  40. 'Metadata attribute \'%s\' does not match expected value.\n'
  41. 'Expected: %s\n'
  42. 'Actual: %s') % (key, value, page.metadata[key]))
  43. def test_article_with_asc_options(self):
  44. # test to ensure the ASCIIDOC_OPTIONS is being used
  45. page = self.read_file(path='article_with_asc_options.asc',
  46. ASCIIDOC_OPTIONS=["-a revision=1.0.42"])
  47. expected = ('<div class="sect1">'
  48. '<h2 id="_used_for_pelican_test">'
  49. 'Used for pelican test</h2>'
  50. '<div class="sectionbody">'
  51. '<div class="paragraph">'
  52. '<p>version 1.0.42</p></div>'
  53. '<div class="paragraph">'
  54. '<p>The quick brown fox jumped over '
  55. 'the lazy dog&#8217;s back.</p>'
  56. '</div></div></div>')
  57. actual = "".join(page.content.splitlines())
  58. expected = "".join(expected.splitlines())
  59. self.assertEqual(actual, expected)
  60. if __name__ == '__main__':
  61. unittest.main()