mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Replace get_populated_generator with setUpClass
This commit is contained in:
parent
a14dc4dad2
commit
577a3d116e
1 changed files with 14 additions and 25 deletions
|
|
@ -38,25 +38,17 @@ class TestGenerator(unittest.TestCase):
|
||||||
|
|
||||||
class TestArticlesGenerator(unittest.TestCase):
|
class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
@classmethod
|
||||||
super(TestArticlesGenerator, self).setUp()
|
def setUpClass(cls):
|
||||||
self.generator = None
|
settings = get_settings(filenames={})
|
||||||
|
settings['DEFAULT_CATEGORY'] = 'Default'
|
||||||
|
settings['DEFAULT_DATE'] = (1970, 1, 1)
|
||||||
|
|
||||||
def get_populated_generator(self):
|
cls.generator = ArticlesGenerator(
|
||||||
"""
|
context=settings.copy(), settings=settings,
|
||||||
We only need to pull all the test articles once, but read from it
|
path=CONTENT_DIR, theme=settings['THEME'],
|
||||||
for each test.
|
output_path=None, markup=settings['MARKUP'])
|
||||||
"""
|
cls.generator.generate_context()
|
||||||
if self.generator is None:
|
|
||||||
settings = get_settings(filenames={})
|
|
||||||
settings['DEFAULT_CATEGORY'] = 'Default'
|
|
||||||
settings['DEFAULT_DATE'] = (1970, 1, 1)
|
|
||||||
self.generator = ArticlesGenerator(
|
|
||||||
context=settings.copy(), settings=settings,
|
|
||||||
path=CONTENT_DIR, theme=settings['THEME'],
|
|
||||||
output_path=None, markup=settings['MARKUP'])
|
|
||||||
self.generator.generate_context()
|
|
||||||
return self.generator
|
|
||||||
|
|
||||||
def distill_articles(self, articles):
|
def distill_articles(self, articles):
|
||||||
distilled = []
|
distilled = []
|
||||||
|
|
@ -91,8 +83,7 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
def test_generate_context(self):
|
def test_generate_context(self):
|
||||||
|
|
||||||
generator = self.get_populated_generator()
|
articles = self.distill_articles(self.generator.articles)
|
||||||
articles = self.distill_articles(generator.articles)
|
|
||||||
articles_expected = [
|
articles_expected = [
|
||||||
['Article title', 'published', 'Default', 'article'],
|
['Article title', 'published', 'Default', 'article'],
|
||||||
['Article with markdown and summary metadata single', 'published',
|
['Article with markdown and summary metadata single', 'published',
|
||||||
|
|
@ -120,19 +111,18 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
def test_generate_categories(self):
|
def test_generate_categories(self):
|
||||||
|
|
||||||
generator = self.get_populated_generator()
|
|
||||||
# test for name
|
# test for name
|
||||||
# categories are grouped by slug; if two categories have the same slug
|
# categories are grouped by slug; if two categories have the same slug
|
||||||
# but different names they will be grouped together, the first one in
|
# but different names they will be grouped together, the first one in
|
||||||
# terms of process order will define the name for that category
|
# terms of process order will define the name for that category
|
||||||
categories = [cat.name for cat, _ in generator.categories]
|
categories = [cat.name for cat, _ in self.generator.categories]
|
||||||
categories_alternatives = (
|
categories_alternatives = (
|
||||||
sorted(['Default', 'TestCategory', 'Yeah', 'test', '指導書']),
|
sorted(['Default', 'TestCategory', 'Yeah', 'test', '指導書']),
|
||||||
sorted(['Default', 'TestCategory', 'yeah', 'test', '指導書']),
|
sorted(['Default', 'TestCategory', 'yeah', 'test', '指導書']),
|
||||||
)
|
)
|
||||||
self.assertIn(sorted(categories), categories_alternatives)
|
self.assertIn(sorted(categories), categories_alternatives)
|
||||||
# test for slug
|
# test for slug
|
||||||
categories = [cat.slug for cat, _ in generator.categories]
|
categories = [cat.slug for cat, _ in self.generator.categories]
|
||||||
categories_expected = ['default', 'testcategory', 'yeah', 'test',
|
categories_expected = ['default', 'testcategory', 'yeah', 'test',
|
||||||
'zhi-dao-shu']
|
'zhi-dao-shu']
|
||||||
self.assertEqual(sorted(categories), sorted(categories_expected))
|
self.assertEqual(sorted(categories), sorted(categories_expected))
|
||||||
|
|
@ -209,8 +199,7 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Custom template articles get the field but standard/unset are None
|
Custom template articles get the field but standard/unset are None
|
||||||
"""
|
"""
|
||||||
generator = self.get_populated_generator()
|
articles = self.distill_articles(self.generator.articles)
|
||||||
articles = self.distill_articles(generator.articles)
|
|
||||||
custom_template = ['Article with template', 'published', 'Default',
|
custom_template = ['Article with template', 'published', 'Default',
|
||||||
'custom']
|
'custom']
|
||||||
standard_template = ['This is a super article !', 'published', 'Yeah',
|
standard_template = ['This is a super article !', 'published', 'Yeah',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue