diff options
author | DasIch <dasdasich@gmail.com> | 2010-05-30 17:51:14 +0200 |
---|---|---|
committer | DasIch <dasdasich@gmail.com> | 2010-05-30 17:51:14 +0200 |
commit | efd37f2b4583bd415702ad43d51b76ca6298a03e (patch) | |
tree | eae4f11c2570513eb3a7d1111a7a9a2f84aceb80 | |
parent | 381fa7fe6cc6b83f0a2c5ca57ccdb27b303fe88f (diff) | |
download | sphinx-efd37f2b4583bd415702ad43d51b76ca6298a03e.tar.gz |
Fix encoding in config test and open configs in binary mode to warn for possible encoding errors
-rw-r--r-- | sphinx/config.py | 2 | ||||
-rw-r--r-- | tests/test_config.py | 5 | ||||
-rw-r--r-- | tests/util.py | 11 |
3 files changed, 13 insertions, 5 deletions
diff --git a/sphinx/config.py b/sphinx/config.py index 2ec76987..07c3d63a 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -165,7 +165,7 @@ class Config(object): try: try: os.chdir(dirname) - f = open(config_file, 'U') + f = open(config_file, 'Ub') try: code = compile(f.read(), config_file, 'exec') finally: diff --git a/tests/test_config.py b/tests/test_config.py index cb4e1105..23d92e39 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -84,11 +84,12 @@ def test_extension_values(app): @with_tempdir def test_errors_warnings(dir): # test the error for syntax errors in the config file - write_file(dir / 'conf.py', 'project = \n') + write_file(dir / 'conf.py', u'project = \n', 'ascii') raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None) # test the warning for bytestrings with non-ascii content - write_file(dir / 'conf.py', '# -*- coding: latin-1\nproject = "foo\xe4"\n') + write_file(dir / 'conf.py', + u'# -*- coding: latin-1\nproject = "fooƤ"\n', 'latin-1') cfg = Config(dir, 'conf.py', {}, None) warned = [False] def warn(msg): diff --git a/tests/util.py b/tests/util.py index 1b24af0e..2cf4a775 100644 --- a/tests/util.py +++ b/tests/util.py @@ -11,6 +11,7 @@ import sys import StringIO import tempfile import shutil +from codecs import open try: from functools import wraps @@ -191,8 +192,14 @@ def with_tempdir(func): return new_func -def write_file(name, contents): - f = open(str(name), 'wb') +def write_file(name, contents, encoding=None): + if encoding is None: + mode = 'wb' + if isinstance(contents, unicode): + contents = contents.encode('ascii') + else: + mode = 'w' + f = open(str(name), 'wb', encoding=encoding) f.write(contents) f.close() |