Fix config.from_pyfile on Python 3 (#2123)

* Fix config.from_pyfile on Python 3

Fix #2118

* Support Python 2.6

* Fix tests on Python 2
This commit is contained in:
Markus Unterwaditzer 2016-12-26 03:50:47 +01:00 committed by GitHub
parent 8cd0b03bee
commit 789715adb9
3 changed files with 24 additions and 3 deletions

View file

@ -7,11 +7,14 @@
:license: BSD, see LICENSE for more details.
"""
import pytest
import os
from datetime import timedelta
import os
import textwrap
import flask
from flask._compat import PY2
import pytest
# config keys used for the TestConfig
@ -187,3 +190,18 @@ def test_get_namespace():
assert 2 == len(bar_options)
assert 'bar stuff 1' == bar_options['BAR_STUFF_1']
assert 'bar stuff 2' == bar_options['BAR_STUFF_2']
@pytest.mark.parametrize('encoding', ['utf-8', 'iso-8859-15', 'latin-1'])
def test_from_pyfile_weird_encoding(tmpdir, encoding):
f = tmpdir.join('my_config.py')
f.write_binary(textwrap.dedent(u'''
# -*- coding: {0} -*-
TEST_VALUE = "föö"
'''.format(encoding)).encode(encoding))
app = flask.Flask(__name__)
app.config.from_pyfile(str(f))
value = app.config['TEST_VALUE']
if PY2:
value = value.decode(encoding)
assert value == u'föö'