Merge pull request #1795 from ingwinlu/add_warning_to_replacer

Add warning for unknown replacement indicators
This commit is contained in:
Justin Mayer 2015-08-08 09:12:36 -07:00
commit a55217ef36
2 changed files with 26 additions and 3 deletions

View file

@ -248,6 +248,11 @@ class Content(object):
origin = '/'.join((siteurl, Category(path, self.settings).url))
elif what == 'tag':
origin = '/'.join((siteurl, Tag(path, self.settings).url))
else:
logger.warning(
"Replacement Indicator '%s' not recognized, "
"skipping replacement",
what)
# keep all other parts, such as query, fragment, etc.
parts = list(value)

View file

@ -1,5 +1,6 @@
from __future__ import unicode_literals, absolute_import
import logging
import locale
import os.path
import six
@ -11,7 +12,7 @@ from pelican.contents import (Page, Article, Static, URLWrapper,
Author, Category)
from pelican.settings import DEFAULT_CONFIG
from pelican.signals import content_object_init
from pelican.tests.support import unittest, get_settings
from pelican.tests.support import LoggedTestCase, mute, unittest, get_settings
from pelican.utils import (path_to_url, truncate_html_words, SafeDatetime,
posix_join)
@ -413,10 +414,10 @@ class TestArticle(TestPage):
self.assertEqual(article.save_as, 'obrien/csharp-stuff/fnord/index.html')
class TestStatic(unittest.TestCase):
class TestStatic(LoggedTestCase):
def setUp(self):
super(TestStatic, self).setUp()
self.settings = get_settings(
STATIC_SAVE_AS='{path}',
STATIC_URL='{path}',
@ -578,3 +579,20 @@ class TestStatic(unittest.TestCase):
content = page.get_content('')
self.assertNotEqual(content, html)
def test_unknown_link_syntax(self):
"{unknown} link syntax should trigger warning."
html = '<a href="{unknown}foo">link</a>'
page = Page(content=html,
metadata={'title': 'fakepage'}, settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertEqual(content, html)
self.assertLogCountEqual(
count=1,
msg="Replacement Indicator 'unknown' not recognized, "
"skipping replacement",
level=logging.WARNING)