Merge branch 'master' of github.com:getpelican/pelican

This commit is contained in:
Alexis Métaireau 2012-10-28 23:50:49 +01:00
commit 92d8208309
9 changed files with 42 additions and 20 deletions

View file

@ -114,7 +114,6 @@ def mute(returns_output=False):
return decorator
def get_article(title, slug, content, lang, extra_metadata=None):
metadata = {'slug': slug, 'title': title, 'lang': lang}
if extra_metadata is not None:
@ -122,19 +121,20 @@ def get_article(title, slug, content, lang, extra_metadata=None):
return Article(content, metadata=metadata)
def skipIfNoExecutable(executable, valid_exit_code=1):
"""Tries to run an executable to make sure it's in the path, Skips the tests
if not found.
def skipIfNoExecutable(executable):
"""Skip test if `executable` is not found
Tries to run `executable` with subprocess to make sure it's in the path,
and skips the tests if not found (if subprocess raises a `OSError`).
"""
# calling with no params the command should exit with 1
with open(os.devnull, 'w') as fnull:
try:
res = subprocess.call(executable, stdout=fnull, stderr=fnull)
except OSError:
res = None
if res != valid_exit_code:
return unittest.skip('{0} compiler not found'.format(executable))
if res is None:
return unittest.skip('{0} executable not found'.format(executable))
return lambda func: func

View file

@ -86,6 +86,20 @@ class TestArticlesGenerator(unittest.TestCase):
categories_expected = ['Default', 'TestCategory', 'Yeah', 'test', 'yeah']
self.assertEquals(categories, categories_expected)
def test_do_not_use_folder_as_category(self):
settings = _DEFAULT_CONFIG.copy()
settings['ARTICLE_DIR'] = 'content'
settings['DEFAULT_CATEGORY'] = 'Default'
settings['USE_FOLDER_AS_CATEGORY'] = False
generator = ArticlesGenerator(settings.copy(), settings,
CUR_DIR, _DEFAULT_CONFIG['THEME'], None,
_DEFAULT_CONFIG['MARKUP'])
generator.generate_context()
categories = [cat.name for cat, _ in generator.categories]
self.assertEquals(categories, ['Default', 'Yeah', 'test', 'yeah'])
def test_direct_templates_save_as_default(self):
settings = _DEFAULT_CONFIG.copy()

View file

@ -3,25 +3,24 @@
import os
from pelican.tools.pelican_import import wp2fields, fields2pelican
from .support import unittest, temporary_folder, mute
from .support import unittest, temporary_folder, mute, skipIfNoExecutable
CUR_DIR = os.path.dirname(__file__)
WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml')
PANDOC = os.system('pandoc --version') == 0
try:
import BeautifulSoup
except ImportError:
BeautifulSoup = False # NOQA
@skipIfNoExecutable(['pandoc', '--version'])
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')
class TestWordpressXmlImporter(unittest.TestCase):
def setUp(self):
self.posts = wp2fields(WORDPRESS_XML_SAMPLE)
@unittest.skipUnless(PANDOC and BeautifulSoup,
'Needs Pandoc and BeautifulSoup')
def test_ignore_empty_posts(self):
posts = list(self.posts)
@ -29,8 +28,6 @@ class TestWordpressXmlImporter(unittest.TestCase):
for title, content, fname, date, author, categ, tags, format in posts:
self.assertTrue(title.strip())
@unittest.skipUnless(PANDOC and BeautifulSoup,
'Needs Pandoc and BeautifulSoup')
def test_can_toggle_raw_html_code_parsing(self):
posts = list(self.posts)