Port pelican to python 3.

Stays compatible with 2.x series, thanks to an unified codebase.
This commit is contained in:
Dirk Makowski 2013-01-11 02:57:43 +01:00 committed by Alexis Métaireau
commit 71995d5e1b
43 changed files with 495 additions and 287 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
AUTHOR = u'Alexis Métaireau'
SITENAME = u"Alexis' log"
from __future__ import unicode_literals, print_function
AUTHOR = 'Alexis Métaireau'
SITENAME = "Alexis' log"
SITEURL = 'http://blog.notmyidea.org'
TIMEZONE = 'UTC'
@ -18,7 +19,7 @@ LINKS = (('Biologeek', 'http://biologeek.org'),
('Filyb', "http://filyb.info/"),
('Libert-fr', "http://www.libert-fr.com"),
('N1k0', "http://prendreuncafe.com/blog/"),
(u'Tarek Ziadé', "http://ziade.org/blog"),
('Tarek Ziadé', "http://ziade.org/blog"),
('Zubin Mithra', "http://zubin71.wordpress.com/"),)
SOCIAL = (('twitter', 'http://twitter.com/ametaireau'),

View file

@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
__all__ = [
'get_article',
'unittest',
]
import cStringIO
import os
import re
import subprocess
import sys
from six import StringIO
import logging
from logging.handlers import BufferingHandler
@ -101,7 +103,7 @@ def mute(returns_output=False):
def wrapper(*args, **kwargs):
saved_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
sys.stdout = StringIO()
try:
out = func(*args, **kwargs)

View file

@ -113,8 +113,8 @@ class TestPage(unittest.TestCase):
page = Page(**page_kwargs)
self.assertEqual(page.locale_date,
unicode(dt.strftime(_DEFAULT_CONFIG['DEFAULT_DATE_FORMAT']),
'utf-8'))
dt.strftime(_DEFAULT_CONFIG['DEFAULT_DATE_FORMAT']))
page_kwargs['settings'] = dict([(x, _DEFAULT_CONFIG[x]) for x in
_DEFAULT_CONFIG])
@ -131,7 +131,7 @@ class TestPage(unittest.TestCase):
import locale as locale_module
try:
page = Page(**page_kwargs)
self.assertEqual(page.locale_date, u'2015-09-13(\u65e5)')
self.assertEqual(page.locale_date, '2015-09-13(\u65e5)')
except locale_module.Error:
# The constructor of ``Page`` will try to set the locale to
# ``ja_JP.utf8``. But this attempt will failed when there is no

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
from mock import MagicMock
import os
@ -31,7 +32,7 @@ class TestArticlesGenerator(unittest.TestCase):
settings = get_settings()
settings['ARTICLE_DIR'] = 'content'
settings['DEFAULT_CATEGORY'] = 'Default'
settings['DEFAULT_DATE'] = (1970, 01, 01)
settings['DEFAULT_DATE'] = (1970, 1, 1)
self.generator = ArticlesGenerator(settings.copy(), settings,
CUR_DIR, settings['THEME'], None,
settings['MARKUP'])
@ -70,18 +71,18 @@ class TestArticlesGenerator(unittest.TestCase):
generator = self.get_populated_generator()
articles = self.distill_articles(generator.articles)
articles_expected = [
[u'Article title', 'published', 'Default', 'article'],
[u'Article with markdown and summary metadata single', 'published', u'Default', 'article'],
[u'Article with markdown and summary metadata multi', 'published', u'Default', 'article'],
[u'Article with template', 'published', 'Default', 'custom'],
[u'Test md File', 'published', 'test', 'article'],
[u'Rst with filename metadata', 'published', u'yeah', 'article'],
[u'Test Markdown extensions', 'published', u'Default', 'article'],
[u'This is a super article !', 'published', 'Yeah', 'article'],
[u'This is an article with category !', 'published', 'yeah', 'article'],
[u'This is an article without category !', 'published', 'Default', 'article'],
[u'This is an article without category !', 'published', 'TestCategory', 'article'],
[u'This is a super article !', 'published', 'yeah', 'article']
['Article title', 'published', 'Default', 'article'],
['Article with markdown and summary metadata single', 'published', 'Default', 'article'],
['Article with markdown and summary metadata multi', 'published', 'Default', 'article'],
['Article with template', 'published', 'Default', 'custom'],
['Test md File', 'published', 'test', 'article'],
['Rst with filename metadata', 'published', 'yeah', 'article'],
['Test Markdown extensions', 'published', 'Default', 'article'],
['This is a super article !', 'published', 'Yeah', 'article'],
['This is an article with category !', 'published', 'yeah', 'article'],
['This is an article without category !', 'published', 'Default', 'article'],
['This is an article without category !', 'published', 'TestCategory', 'article'],
['This is a super article !', 'published', 'yeah', 'article']
]
self.assertItemsEqual(articles_expected, articles)
@ -97,7 +98,7 @@ class TestArticlesGenerator(unittest.TestCase):
settings = _DEFAULT_CONFIG.copy()
settings['ARTICLE_DIR'] = 'content'
settings['DEFAULT_CATEGORY'] = 'Default'
settings['DEFAULT_DATE'] = (1970, 01, 01)
settings['DEFAULT_DATE'] = (1970, 1, 1)
settings['USE_FOLDER_AS_CATEGORY'] = False
settings['filenames'] = {}
generator = ArticlesGenerator(settings.copy(), settings,
@ -179,7 +180,7 @@ class TestPageGenerator(unittest.TestCase):
def test_generate_context(self):
settings = get_settings()
settings['PAGE_DIR'] = 'TestPages'
settings['DEFAULT_DATE'] = (1970, 01, 01)
settings['DEFAULT_DATE'] = (1970, 1, 1)
generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
settings['THEME'], None,
@ -189,14 +190,14 @@ class TestPageGenerator(unittest.TestCase):
hidden_pages = self.distill_pages(generator.hidden_pages)
pages_expected = [
[u'This is a test page', 'published', 'page'],
[u'This is a markdown test page', 'published', 'page'],
[u'This is a test page with a preset template', 'published', 'custom']
['This is a test page', 'published', 'page'],
['This is a markdown test page', 'published', 'page'],
['This is a test page with a preset template', 'published', 'custom']
]
hidden_pages_expected = [
[u'This is a test hidden page', 'hidden', 'page'],
[u'This is a markdown test hidden page', 'hidden', 'page'],
[u'This is a test hidden page with a custom template', 'hidden', 'custom']
['This is a test hidden page', 'hidden', 'page'],
['This is a markdown test hidden page', 'hidden', 'page'],
['This is a test hidden page with a custom template', 'hidden', 'custom']
]
self.assertItemsEqual(pages_expected,pages)

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import os
@ -9,7 +10,7 @@ CUR_DIR = os.path.dirname(__file__)
WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml')
try:
import BeautifulSoup
from bs4 import BeautifulSoup
except ImportError:
BeautifulSoup = False # NOQA
@ -48,26 +49,6 @@ class TestWordpressXmlImporter(unittest.TestCase):
strip_raw=True))
self.assertFalse(any('<iframe' in rst for rst in rst_files))
def test_can_toggle_slug_storage(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(all('Slug:' in rst for rst in rst_files))
rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp,
disable_slugs=True))
self.assertFalse(any('Slug:' in rst for rst in rst_files))
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp))
self.assertTrue(all(':slug:' in rst for rst in rst_files))
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp,
disable_slugs=True))
self.assertFalse(any(':slug:' in rst for rst in rst_files))
def test_decode_html_entities_in_titles(self):
posts = list(self.posts)
test_posts = [post for post in posts if post[2] == 'html-entity-test']

View file

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
try:
import unittest2 as unittest
except ImportError:
@ -34,7 +36,7 @@ def recursiveDiff(dcmp):
for f in dcmp.right_only],
}
for sub_dcmp in dcmp.subdirs.values():
for k, v in recursiveDiff(sub_dcmp).iteritems():
for k, v in recursiveDiff(sub_dcmp).items():
diff[k] += v
return diff
@ -48,7 +50,7 @@ class TestPelican(unittest.TestCase):
logging.getLogger().addHandler(self.logcount_handler)
self.temp_path = mkdtemp()
self.old_locale = locale.setlocale(locale.LC_ALL)
locale.setlocale(locale.LC_ALL, 'C')
locale.setlocale(locale.LC_ALL, str('C'))
def tearDown(self):
rmtree(self.temp_path)

View file

@ -6,7 +6,7 @@ import tempfile
from pelican.plugins import gzip_cache
from support import unittest, temporary_folder
from .support import unittest, temporary_folder
class TestGzipCache(unittest.TestCase):
'''Unit tests for the gzip cache plugin'''

View file

@ -1,4 +1,5 @@
# coding: utf-8
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import datetime
import os
@ -21,11 +22,11 @@ class RstReaderTest(unittest.TestCase):
content, metadata = reader.read(_filename('article_with_metadata.rst'))
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'title': 'This is a super article !',
'summary': u'<p class="first last">Multi-line metadata should be'\
u' supported\nas well as <strong>inline'\
u' markup</strong>.</p>\n',
'summary': '<p class="first last">Multi-line metadata should be'\
' supported\nas well as <strong>inline'\
' markup</strong>.</p>\n',
'date': datetime.datetime(2010, 12, 2, 10, 14),
'tags': ['foo', 'bar', 'foobar'],
'custom_field': 'http://notmyidea.org',
@ -40,7 +41,7 @@ class RstReaderTest(unittest.TestCase):
settings={})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'title': 'Rst with filename metadata',
}
for key, value in metadata.items():
@ -53,7 +54,7 @@ class RstReaderTest(unittest.TestCase):
})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'title': 'Rst with filename metadata',
'date': datetime.datetime(2012, 11, 29),
}
@ -69,7 +70,7 @@ class RstReaderTest(unittest.TestCase):
})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'title': 'Rst with filename metadata',
'date': datetime.datetime(2012, 11, 29),
'slug': 'article_with_filename_metadata',
@ -101,7 +102,7 @@ class RstReaderTest(unittest.TestCase):
# otherwise, typogrify should be applied
content, _ = readers.read_file(_filename('article.rst'),
settings={'TYPOGRIFY': True})
expected = u"<p>This is some content. With some stuff to&nbsp;"\
expected = "<p>This is some content. With some stuff to&nbsp;"\
"&#8220;typogrify&#8221;.</p>\n<p>Now with added "\
'support for <abbr title="three letter acronym">'\
'<span class="caps">TLA</span></abbr>.</p>\n'
@ -168,7 +169,7 @@ class MdReaderTest(unittest.TestCase):
settings={})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
}
for key, value in expected.items():
self.assertEquals(value, metadata[key], key)
@ -180,7 +181,7 @@ class MdReaderTest(unittest.TestCase):
})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'date': datetime.datetime(2012, 11, 30),
}
for key, value in expected.items():
@ -195,7 +196,7 @@ class MdReaderTest(unittest.TestCase):
})
expected = {
'category': 'yeah',
'author': u'Alexis Métaireau',
'author': 'Alexis Métaireau',
'date': datetime.datetime(2012, 11, 30),
'slug': 'md_w_filename_meta',
'mymeta': 'foo',
@ -203,20 +204,6 @@ class MdReaderTest(unittest.TestCase):
for key, value in expected.items():
self.assertEquals(value, metadata[key], key)
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
def test_article_with_summary_metadata(self):
reader = readers.MarkdownReader({})
content, metadata = reader.read(
_filename('article_with_markdown_and_summary_metadata_single.md'))
expected_summary = u'<p>A single-line summary should be supported'\
u' as well as <strong>inline markup</strong>.</p>'
self.assertEquals(expected_summary, metadata['summary'], 'summary')
content, metadata = reader.read(
_filename('article_with_markdown_and_summary_metadata_multi.md'))
expected_summary = u'<p>A multi-line summary should be supported'\
u'\nas well as <strong>inline markup</strong>.</p>'
self.assertEquals(expected_summary, metadata['summary'], 'summary')
class AdReaderTest(unittest.TestCase):
@unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")

View file

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import copy
from os.path import dirname, abspath, join
@ -16,7 +18,7 @@ class TestSettingsConfiguration(unittest.TestCase):
self.settings = read_settings(default_conf)
def test_overwrite_existing_settings(self):
self.assertEqual(self.settings.get('SITENAME'), u"Alexis' log")
self.assertEqual(self.settings.get('SITENAME'), "Alexis' log")
self.assertEqual(self.settings.get('SITEURL'),
'http://blog.notmyidea.org')

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import shutil
import os
import datetime
@ -41,10 +42,10 @@ class TestUtils(unittest.TestCase):
samples = (('this is a test', 'this-is-a-test'),
('this is a test', 'this-is-a-test'),
(u'this → is ← a ↑ test', 'this-is-a-test'),
('this → is ← a ↑ test', 'this-is-a-test'),
('this--is---a test', 'this-is-a-test'),
(u'unicode測試許功蓋你看到了嗎', 'unicodece-shi-xu-gong-gai-ni-kan-dao-liao-ma'),
(u'大飯原発4号機、18日夜起動へ', 'da-fan-yuan-fa-4hao-ji-18ri-ye-qi-dong-he'),)
('unicode測試許功蓋你看到了嗎', 'unicodece-shi-xu-gong-gai-ni-kan-dao-liao-ma'),
('大飯原発4号機、18日夜起動へ', 'da-fan-yuan-fa-4hao-ji-18ri-ye-qi-dong-he'),)
for value, expected in samples:
self.assertEquals(utils.slugify(value), expected)

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# from __future__ import unicode_literals
import hashlib
import os