Merge branch 'master' of git://github.com/ametaireau/pelican

This commit is contained in:
dave mankoff 2012-07-09 22:15:04 -04:00
commit 3c30425276
27 changed files with 485 additions and 243 deletions

View file

@ -0,0 +1,8 @@
This is a test bad page
#######################
:status: invalid
The quick brown fox jumped over the lazy dog's back.
The status here is invalid, the page should not render.

View file

@ -0,0 +1,8 @@
This is a test hidden page
##########################
:status: hidden
The quick brown fox jumped over the lazy dog's back.
This page is hidden

View file

@ -0,0 +1,12 @@
title: This is a markdown test hidden page
status: hidden
Test Markdown File Header
=========================
Used for pelican test
---------------------
The quick brown fox jumped over the lazy dog's back.
This page is hidden

4
tests/TestPages/page.rst Normal file
View file

@ -0,0 +1,4 @@
This is a test page
###################
The quick brown fox jumped over the lazy dog's back.

View file

@ -0,0 +1,9 @@
title: This is a markdown test page
Test Markdown File Header
=========================
Used for pelican test
---------------------
The quick brown fox jumped over the lazy dog's back.

View file

@ -4,7 +4,7 @@ from mock import MagicMock
import os
import re
from pelican.generators import ArticlesGenerator, LessCSSGenerator
from pelican.generators import ArticlesGenerator, LessCSSGenerator, PagesGenerator
from pelican.settings import _DEFAULT_CONFIG
from .support import unittest, temporary_folder, skipIfNoExecutable
@ -94,6 +94,48 @@ class TestArticlesGenerator(unittest.TestCase):
write.assert_called_count == 0
class TestPageGenerator(unittest.TestCase):
"""
Every time you want to test for a new field;
Make sure the test pages in "TestPages" have all the fields
Add it to distilled in distill_pages
Then update the assertItemsEqual in test_generate_context to match expected
"""
def distill_pages(self, pages):
distilled = []
for page in pages:
distilled.append([
page.title,
page.status
]
)
return distilled
def test_generate_context(self):
settings = _DEFAULT_CONFIG.copy()
settings['PAGE_DIR'] = 'TestPages'
generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
_DEFAULT_CONFIG['THEME'], None,
_DEFAULT_CONFIG['MARKUP'])
generator.generate_context()
pages = self.distill_pages(generator.pages)
hidden_pages = self.distill_pages(generator.hidden_pages)
pages_expected = [
[u'This is a test page', 'published'],
[u'This is a markdown test page', 'published']
]
hidden_pages_expected = [
[u'This is a test hidden page', 'hidden'],
[u'This is a markdown test hidden page', 'hidden']
]
self.assertItemsEqual(pages_expected,pages)
self.assertItemsEqual(hidden_pages_expected,hidden_pages)
class TestLessCSSGenerator(unittest.TestCase):
LESS_CONTENT = """

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import shutil
import os
import datetime
import time
@ -86,3 +87,12 @@ class TestUtils(unittest.TestCase):
changed = utils.files_changed(path, 'rst')
self.assertEquals(changed, True)
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
def test_clean_output_dir(self):
test_directory = os.path.join(os.path.dirname(__file__), 'clean_output')
content = os.path.join(os.path.dirname(__file__), 'content')
shutil.copytree(content, test_directory)
utils.clean_output_dir(test_directory)
self.assertTrue(os.path.isdir(test_directory))
self.assertListEqual([], os.listdir(test_directory))
shutil.rmtree(test_directory)