2011-05-11 09:42:37 +06:00
|
|
|
# coding: utf-8
|
2012-02-28 01:43:36 +09:00
|
|
|
try:
|
2012-03-11 01:16:02 +01:00
|
|
|
import unittest2 as unittest
|
2012-02-28 01:43:36 +09:00
|
|
|
except ImportError, e:
|
2012-03-11 01:16:02 +01:00
|
|
|
import unittest
|
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
|
|
|
|
|
|
|
|
|
|
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-11 17:05:46 +01:00
|
|
|
'summary': 'Multi-line metadata should be supported\nas well as'\
|
|
|
|
|
' <strong>inline markup</strong>.',
|
2011-05-11 09:42:37 +06:00
|
|
|
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
|
|
|
|
'tags': ['foo', 'bar', 'foobar'],
|
|
|
|
|
}
|
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 "\
|
|
|
|
|
""typogrify".</p>\n"
|
|
|
|
|
|
|
|
|
|
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})
|
|
|
|
|
expected = "<p>This is some content. With some stuff to "\
|
|
|
|
|
"“typogrify”.</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')
|