1
0
Fork 0
forked from github/pelican

replace get_summary with _get_summary

When memoizing summary a dummy get_summary function was introduced to
properly work. This has multiple problems:
* The siteurl argument is actually not used in the function, it is only
  used so it properly memoizes.
* It differs from how content is accessed and memoized.

This commit brings summary inline with how content is accessed and
processed. It also removes the old get_summary function with the unused
siteurl argument.

Additionally _get_summary is marked as deprecated and calls .summary
instead while also issueing a warning.
This commit is contained in:
derwinlu 2015-10-19 16:38:07 +02:00
commit 2cb2bf05df
2 changed files with 36 additions and 12 deletions

View file

@ -23,7 +23,7 @@ TEST_CONTENT = str(generate_lorem_ipsum(n=1))
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
class TestPage(unittest.TestCase):
class TestPage(LoggedTestCase):
def setUp(self):
super(TestPage, self).setUp()
@ -41,9 +41,19 @@ class TestPage(unittest.TestCase):
},
'source_path': '/path/to/file/foo.ext'
}
self._disable_limit_filter()
def tearDown(self):
locale.setlocale(locale.LC_ALL, self.old_locale)
self._enable_limit_filter()
def _disable_limit_filter(self):
from pelican.contents import logger
logger.disable_filter()
def _enable_limit_filter(self):
from pelican.contents import logger
logger.enable_filter()
def test_use_args(self):
# Creating a page with arguments passed to the constructor should use
@ -87,6 +97,18 @@ class TestPage(unittest.TestCase):
page = Page(**page_kwargs)
self.assertEqual(page.summary, '')
def test_summary_get_summary_warning(self):
"""calling ._get_summary() should issue a warning"""
page_kwargs = self._copy_page_kwargs()
page = Page(**page_kwargs)
self.assertEqual(page.summary, TEST_SUMMARY)
self.assertEqual(page._get_summary(), TEST_SUMMARY)
self.assertLogCountEqual(
count=1,
msg="_get_summary\(\) has been deprecated since 3\.6\.4\. "
"Use the summary decorator instead",
level=logging.WARNING)
def test_slug(self):
page_kwargs = self._copy_page_kwargs()
settings = get_settings()