mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
pandoc was checked directly with a `os.system` call, and the output with version and copyright of pandoc was displayed when running tests. - replace the pandoc check with the `skipIfNoExecutable` function. - in `skipIfNoExecutable`, the `valid_exit_code` is not needed, the executable is not found if an `OSError` exception is catched.
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
from pelican.tools.pelican_import import wp2fields, fields2pelican
|
|
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')
|
|
|
|
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)
|
|
|
|
def test_ignore_empty_posts(self):
|
|
|
|
posts = list(self.posts)
|
|
self.assertTrue(posts)
|
|
for title, content, fname, date, author, categ, tags, format in posts:
|
|
self.assertTrue(title.strip())
|
|
|
|
def test_can_toggle_raw_html_code_parsing(self):
|
|
|
|
posts = list(self.posts)
|
|
r = lambda f: open(f).read()
|
|
silent_f2p = mute(True)(fields2pelican)
|
|
|
|
with temporary_folder() as temp:
|
|
|
|
rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp))
|
|
self.assertTrue(any('<iframe' in rst for rst in rst_files))
|
|
rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp,
|
|
strip_raw=True))
|
|
self.assertFalse(any('<iframe' in rst for rst in rst_files))
|
|
# no effect in rst
|
|
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp))
|
|
self.assertFalse(any('<iframe' in rst for rst in rst_files))
|
|
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp,
|
|
strip_raw=True))
|
|
self.assertFalse(any('<iframe' in rst for rst in rst_files))
|