# coding: utf-8 import datetime import os from pelican import readers from .support import unittest CUR_DIR = os.path.dirname(__file__) CONTENT_PATH = os.path.join(CUR_DIR, 'content') def _filename(*args): return os.path.join(CONTENT_PATH, *args) class RstReaderTest(unittest.TestCase): def test_article_with_metadata(self): reader = readers.RstReader({}) content, metadata = reader.read(_filename('article_with_metadata.rst')) expected = { 'category': 'yeah', 'author': u'Alexis Métaireau', 'title': 'This is a super article !', 'summary': u'

Multi-line metadata should be'\ u' supported\nas well as inline'\ u' markup.

\n', 'date': datetime.datetime(2010, 12, 2, 10, 14), 'tags': ['foo', 'bar', 'foobar'], 'custom_field': 'http://notmyidea.org', } for key, value in expected.items(): self.assertEquals(value, metadata[key], key) def test_article_metadata_key_lowercase(self): """Keys of metadata should be lowercase.""" reader = readers.RstReader({}) content, metadata = reader.read(_filename('article_with_uppercase_metadata.rst')) self.assertIn('category', metadata, "Key should be lowercase.") self.assertEquals('Yeah', metadata.get('category'), "Value keeps cases.") def test_typogrify(self): # if nothing is specified in the settings, the content should be # unmodified content, _ = readers.read_file(_filename('article.rst')) expected = "

This is some content. With some stuff to "\ ""typogrify".

\n

Now with added "\ 'support for '\ 'TLA.

\n' self.assertEqual(content, expected) try: # otherwise, typogrify should be applied content, _ = readers.read_file(_filename('article.rst'), settings={'TYPOGRIFY': True}) expected = u"

This is some content. With some stuff to "\ "“typogrify”.

\n

Now with added "\ 'support for '\ 'TLA.

\n' self.assertEqual(content, expected) except ImportError: return unittest.skip('need the typogrify distribution') class MdReaderTest(unittest.TestCase): @unittest.skipUnless(readers.Markdown, "markdown isn't installed") def test_article_with_md_extention(self): # test to ensure the md extension is being processed by the correct reader reader = readers.MarkdownReader({}) content, metadata = reader.read(_filename('article_with_md_extension.md')) expected = "

Test Markdown File Header

\n"\ "

Used for pelican test

\n"\ "

The quick brown fox jumped over the lazy dog's back.

" self.assertEqual(content, expected) @unittest.skipUnless(readers.Markdown, "markdown isn't installed") def test_article_with_mkd_extension(self): # test to ensure the mkd extension is being processed by the correct reader reader = readers.MarkdownReader({}) content, metadata = reader.read(_filename('article_with_mkd_extension.mkd')) expected = "

Test Markdown File Header

\n"\ "

Used for pelican test

\n"\ "

This is another markdown test file. Uses the mkd extension.

" self.assertEqual(content, expected)