2011-05-11 09:42:37 +06:00
|
|
|
# coding: utf-8
|
2012-02-28 01:43:36 +09:00
|
|
|
|
2011-05-11 09:42:37 +06:00
|
|
|
import datetime
|
2012-02-21 17:53:53 +01:00
|
|
|
import os
|
|
|
|
|
|
2011-05-11 09:42:37 +06:00
|
|
|
from pelican import readers
|
2012-03-18 21:08:43 +00:00
|
|
|
from .support import unittest
|
2011-05-11 09:42:37 +06:00
|
|
|
|
|
|
|
|
CUR_DIR = os.path.dirname(__file__)
|
2011-07-02 15:15:21 -05:00
|
|
|
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
2011-05-11 09:42:37 +06:00
|
|
|
|
2012-03-11 01:16:02 +01:00
|
|
|
|
2011-05-11 09:42:37 +06:00
|
|
|
def _filename(*args):
|
|
|
|
|
return os.path.join(CONTENT_PATH, *args)
|
|
|
|
|
|
|
|
|
|
|
2012-03-11 01:16:02 +01:00
|
|
|
class RstReaderTest(unittest.TestCase):
|
2011-05-11 09:42:37 +06:00
|
|
|
|
2011-07-02 15:15:21 -05:00
|
|
|
def test_article_with_metadata(self):
|
2012-03-05 23:33:25 +01:00
|
|
|
reader = readers.RstReader({})
|
2011-07-02 15:15:21 -05:00
|
|
|
content, metadata = reader.read(_filename('article_with_metadata.rst'))
|
2011-05-11 09:42:37 +06:00
|
|
|
expected = {
|
|
|
|
|
'category': 'yeah',
|
|
|
|
|
'author': u'Alexis Métaireau',
|
|
|
|
|
'title': 'This is a super article !',
|
2012-03-25 21:39:41 +04:00
|
|
|
'summary': u'<p class="first last">Multi-line metadata should be'\
|
|
|
|
|
u' supported\nas well as <strong>inline'\
|
|
|
|
|
u' markup</strong>.</p>\n',
|
2011-05-11 09:42:37 +06:00
|
|
|
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
|
|
|
|
'tags': ['foo', 'bar', 'foobar'],
|
2012-03-18 15:12:06 +01:00
|
|
|
'custom_field': 'http://notmyidea.org',
|
2011-05-11 09:42:37 +06:00
|
|
|
}
|
2012-03-11 01:16:02 +01:00
|
|
|
|
|
|
|
|
for key, value in expected.items():
|
|
|
|
|
self.assertEquals(value, metadata[key], key)
|
2012-03-11 02:48:36 +01:00
|
|
|
|
2012-03-12 02:24:26 +09:00
|
|
|
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.")
|
|
|
|
|
|
2012-03-11 02:48:36 +01:00
|
|
|
def test_typogrify(self):
|
|
|
|
|
# if nothing is specified in the settings, the content should be
|
|
|
|
|
# unmodified
|
|
|
|
|
content, _ = readers.read_file(_filename('article.rst'))
|
|
|
|
|
expected = "<p>This is some content. With some stuff to "\
|
2012-07-17 13:30:06 +02:00
|
|
|
""typogrify".</p>\n<p>Now with added "\
|
|
|
|
|
'support for <abbr title="three letter acronym">'\
|
|
|
|
|
'TLA</abbr>.</p>\n'
|
2012-03-11 02:48:36 +01:00
|
|
|
|
|
|
|
|
self.assertEqual(content, expected)
|
|
|
|
|
|
2012-03-11 17:05:46 +01:00
|
|
|
try:
|
|
|
|
|
# otherwise, typogrify should be applied
|
|
|
|
|
content, _ = readers.read_file(_filename('article.rst'),
|
|
|
|
|
settings={'TYPOGRIFY': True})
|
2012-07-27 00:34:47 +02:00
|
|
|
expected = u"<p>This is some content. With some stuff to "\
|
2012-07-17 13:30:06 +02:00
|
|
|
"“typogrify”.</p>\n<p>Now with added "\
|
|
|
|
|
'support for <abbr title="three letter acronym">'\
|
2012-07-27 00:34:47 +02:00
|
|
|
'<span class="caps">TLA</span></abbr>.</p>\n'
|
2012-03-11 02:48:36 +01:00
|
|
|
|
2012-03-11 17:05:46 +01:00
|
|
|
self.assertEqual(content, expected)
|
|
|
|
|
except ImportError:
|
|
|
|
|
return unittest.skip('need the typogrify distribution')
|
2012-05-01 23:30:23 -04:00
|
|
|
|
2012-06-10 12:39:51 +02:00
|
|
|
|
2012-05-01 23:30:23 -04:00
|
|
|
class MdReaderTest(unittest.TestCase):
|
|
|
|
|
|
2012-06-10 12:39:51 +02:00
|
|
|
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
2012-05-01 23:30:23 -04:00
|
|
|
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 = "<h1>Test Markdown File Header</h1>\n"\
|
|
|
|
|
"<h2>Used for pelican test</h2>\n"\
|
|
|
|
|
"<p>The quick brown fox jumped over the lazy dog's back.</p>"
|
|
|
|
|
|
|
|
|
|
self.assertEqual(content, expected)
|
|
|
|
|
|
2012-06-10 12:39:51 +02:00
|
|
|
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
2012-05-01 23:30:23 -04:00
|
|
|
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 = "<h1>Test Markdown File Header</h1>\n"\
|
|
|
|
|
"<h2>Used for pelican test</h2>\n"\
|
|
|
|
|
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
|
|
|
|
|
|
|
|
|
self.assertEqual(content, expected)
|
2012-09-02 10:09:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class HtmlReaderTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_article_with_metadata(self):
|
|
|
|
|
reader = readers.HtmlReader({})
|
|
|
|
|
content, metadata = reader.read(_filename('article_with_html_metadata.html'))
|
|
|
|
|
expected = {
|
|
|
|
|
'category': 'yeah',
|
|
|
|
|
'author': u'Alexis Métaireau',
|
|
|
|
|
'title': 'A great html article with metadata',
|
|
|
|
|
'summary': u'Multi-line metadata should be'\
|
|
|
|
|
u' supported\nas well as <strong>inline'\
|
|
|
|
|
u' markup</strong>.',
|
|
|
|
|
'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)
|