mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #1850 from ingwinlu/deprecation_warnings
Make Pelican Python 3.5 compatible
This commit is contained in:
commit
880ba20a98
8 changed files with 83 additions and 11 deletions
|
|
@ -7,6 +7,11 @@ env:
|
||||||
- TOX_ENV=py27
|
- TOX_ENV=py27
|
||||||
- TOX_ENV=py33
|
- TOX_ENV=py33
|
||||||
- TOX_ENV=py34
|
- TOX_ENV=py34
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- python: 3.5
|
||||||
|
env:
|
||||||
|
- TOX_ENV=py35
|
||||||
addons:
|
addons:
|
||||||
apt_packages:
|
apt_packages:
|
||||||
- pandoc
|
- pandoc
|
||||||
|
|
|
||||||
|
|
@ -178,21 +178,49 @@ class LimitLogger(SafeLogger):
|
||||||
logging.setLoggerClass(LimitLogger)
|
logging.setLoggerClass(LimitLogger)
|
||||||
|
|
||||||
|
|
||||||
def init(level=None, handler=logging.StreamHandler()):
|
def supports_color():
|
||||||
|
"""
|
||||||
|
Returns True if the running system's terminal supports color,
|
||||||
|
and False otherwise.
|
||||||
|
|
||||||
logger = logging.getLogger()
|
from django.core.management.color
|
||||||
|
"""
|
||||||
|
plat = sys.platform
|
||||||
|
supported_platform = plat != 'Pocket PC' and \
|
||||||
|
(plat != 'win32' or 'ANSICON' in os.environ)
|
||||||
|
|
||||||
if os.isatty(sys.stdout.fileno()) and not sys.platform.startswith('win'):
|
# isatty is not always implemented, #6223.
|
||||||
fmt = ANSIFormatter()
|
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
||||||
|
if not supported_platform or not is_a_tty:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_formatter():
|
||||||
|
if supports_color():
|
||||||
|
return ANSIFormatter()
|
||||||
else:
|
else:
|
||||||
fmt = TextFormatter()
|
return TextFormatter()
|
||||||
handler.setFormatter(fmt)
|
|
||||||
|
|
||||||
|
def init(level=None, handler=logging.StreamHandler(), name=None):
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
|
||||||
|
handler.setFormatter(get_formatter())
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
if level:
|
if level:
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
|
||||||
|
def log_warnings():
|
||||||
|
import warnings
|
||||||
|
logging.captureWarnings(True)
|
||||||
|
warnings.simplefilter("default", DeprecationWarning)
|
||||||
|
init(logging.DEBUG, name='py.warnings')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init(level=logging.DEBUG)
|
init(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,15 @@
|
||||||
import logging
|
import logging
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pelican.log import log_warnings
|
||||||
|
|
||||||
|
# redirect warnings modulole to use logging instead
|
||||||
|
log_warnings()
|
||||||
|
|
||||||
|
# setup warnings to log DeprecationWarning's and error on
|
||||||
|
# warnings in pelican's codebase
|
||||||
|
warnings.simplefilter("default", DeprecationWarning)
|
||||||
|
warnings.filterwarnings("error", ".*", Warning, "pelican")
|
||||||
|
|
||||||
|
# Add a NullHandler to silence warning about no available handlers
|
||||||
logging.getLogger().addHandler(logging.NullHandler())
|
logging.getLogger().addHandler(logging.NullHandler())
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from pelican import readers
|
from pelican import readers
|
||||||
from pelican.tests.support import get_settings, unittest
|
from pelican.tests.support import get_settings, unittest
|
||||||
from pelican.utils import SafeDatetime
|
from pelican.utils import SafeDatetime
|
||||||
|
|
@ -55,7 +57,8 @@ class TestAssertDictHasSubset(ReaderTest):
|
||||||
self.assertDictHasSubset(self.dictionary, self.dictionary)
|
self.assertDictHasSubset(self.dictionary, self.dictionary)
|
||||||
|
|
||||||
def test_fail_not_set(self):
|
def test_fail_not_set(self):
|
||||||
self.assertRaisesRegexp(
|
six.assertRaisesRegex(
|
||||||
|
self,
|
||||||
AssertionError,
|
AssertionError,
|
||||||
'Expected.*key-c.*to have value.*val-c.*but was not in Dict',
|
'Expected.*key-c.*to have value.*val-c.*but was not in Dict',
|
||||||
self.assertDictHasSubset,
|
self.assertDictHasSubset,
|
||||||
|
|
@ -63,7 +66,8 @@ class TestAssertDictHasSubset(ReaderTest):
|
||||||
{'key-c': 'val-c'})
|
{'key-c': 'val-c'})
|
||||||
|
|
||||||
def test_fail_wrong_val(self):
|
def test_fail_wrong_val(self):
|
||||||
self.assertRaisesRegexp(
|
six.assertRaisesRegex(
|
||||||
|
self,
|
||||||
AssertionError,
|
AssertionError,
|
||||||
'Expected .*key-a.* to have value .*val-b.* but was .*val-a.*',
|
'Expected .*key-a.* to have value .*val-b.* but was .*val-a.*',
|
||||||
self.assertDictHasSubset,
|
self.assertDictHasSubset,
|
||||||
|
|
|
||||||
16
pelican/tests/test_testsuite.py
Normal file
16
pelican/tests/test_testsuite.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pelican.tests.support import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestSuiteTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.version_info[:2] == (3, 3),
|
||||||
|
"does not throw an exception on python 3.3")
|
||||||
|
def test_error_on_warning(self):
|
||||||
|
with self.assertRaises(UserWarning):
|
||||||
|
warnings.warn('test warning')
|
||||||
|
|
@ -429,7 +429,11 @@ class _HTMLWordTruncator(HTMLParser):
|
||||||
def __init__(self, max_words):
|
def __init__(self, max_words):
|
||||||
# In Python 2, HTMLParser is not a new-style class,
|
# In Python 2, HTMLParser is not a new-style class,
|
||||||
# hence super() cannot be used.
|
# hence super() cannot be used.
|
||||||
HTMLParser.__init__(self)
|
try:
|
||||||
|
HTMLParser.__init__(self, convert_charrefs=False)
|
||||||
|
except TypeError:
|
||||||
|
# pre Python 3.3
|
||||||
|
HTMLParser.__init__(self)
|
||||||
|
|
||||||
self.max_words = max_words
|
self.max_words = max_words
|
||||||
self.words_found = 0
|
self.words_found = 0
|
||||||
|
|
|
||||||
1
setup.py
1
setup.py
|
|
@ -55,6 +55,7 @@ setup(
|
||||||
'Programming Language :: Python :: 3',
|
'Programming Language :: Python :: 3',
|
||||||
'Programming Language :: Python :: 3.3',
|
'Programming Language :: Python :: 3.3',
|
||||||
'Programming Language :: Python :: 3.4',
|
'Programming Language :: Python :: 3.4',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
'Topic :: Internet :: WWW/HTTP',
|
'Topic :: Internet :: WWW/HTTP',
|
||||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
5
tox.ini
5
tox.ini
|
|
@ -1,11 +1,12 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py{27,33,34},docs,flake8
|
envlist = py{27,33,34,35},docs,flake8
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
basepython =
|
basepython =
|
||||||
py27: python2.7
|
py27: python2.7
|
||||||
py33: python3.3
|
py33: python3.3
|
||||||
py34: python3.4
|
py34: python3.4
|
||||||
|
py35: python3.5
|
||||||
passenv = *
|
passenv = *
|
||||||
usedevelop=True
|
usedevelop=True
|
||||||
deps =
|
deps =
|
||||||
|
|
@ -17,7 +18,7 @@ deps =
|
||||||
commands =
|
commands =
|
||||||
{envpython} --version
|
{envpython} --version
|
||||||
nosetests -sv --with-coverage --cover-package=pelican pelican
|
nosetests -sv --with-coverage --cover-package=pelican pelican
|
||||||
coveralls
|
- coveralls
|
||||||
|
|
||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue