test_asciidoc_reader.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 asciidoc_enabled
  8. CUR_DIR = os.path.dirname(__file__)
  9. CONTENT_PATH = os.path.join(CUR_DIR, 'test_data')
  10. @unittest.skipUnless(asciidoc_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">\n'
  21. '<h2 id="_used_for_pelican_test">'
  22. 'Used for pelican test</h2>\n'
  23. '<div class="sectionbody">\n'
  24. '<div class="paragraph">'
  25. '<p>The quick brown fox jumped over '
  26. 'the lazy dog&#8217;s back.</p>'
  27. '</div>\n</div>\n</div>\n')
  28. self.assertEqual(page.content, expected)
  29. expected = {
  30. 'category': 'Blog',
  31. 'author': 'Author O. Article',
  32. 'title': 'Test AsciiDoc File Header',
  33. 'date': datetime.datetime(2011, 9, 15, 9, 5),
  34. 'tags': ['Linux', 'Python', 'Pelican'],
  35. }
  36. for key, value in expected.items():
  37. self.assertEqual(value, page.metadata[key], key)
  38. def test_article_with_asc_options(self):
  39. # test to ensure the ASCIIDOC_OPTIONS is being used
  40. page = self.read_file(path='article_with_asc_options.asc',
  41. ASCIIDOC_OPTIONS=["-a revision=1.0.42"])
  42. expected = ('<div class="sect1">\n'
  43. '<h2 id="_used_for_pelican_test">'
  44. 'Used for pelican test</h2>\n'
  45. '<div class="sectionbody">\n'
  46. '<div class="paragraph">'
  47. '<p>version 1.0.42</p></div>\n'
  48. '<div class="paragraph">'
  49. '<p>The quick brown fox jumped over '
  50. 'the lazy dog&#8217;s back.</p>'
  51. '</div>\n</div>\n</div>\n')
  52. self.assertEqual(page.content, expected)