summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2014-04-28 19:58:26 +0900
committershimizukawa <shimizukawa@gmail.com>2014-04-28 19:58:26 +0900
commit6f97da6fc4514d106008980fb44cad6d16e6318b (patch)
tree9ec72e17929e58cbecd42593febccf8593e9ad49
parent79462980ff1832dc7ebdbebbbeb9739e16654401 (diff)
downloadsphinx-6f97da6fc4514d106008980fb44cad6d16e6318b.tar.gz
remove tests.util.write_file duplicated implementation.
-rw-r--r--tests/test_config.py13
-rw-r--r--tests/test_intersphinx.py6
-rw-r--r--tests/util.py15
3 files changed, 11 insertions, 23 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index f1bea6f7..db9a2a01 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -11,7 +11,7 @@
"""
import sys
-from util import TestApp, with_app, with_tempdir, raises, raises_msg, write_file
+from util import TestApp, with_app, with_tempdir, raises, raises_msg
from sphinx.config import Config
from sphinx.errors import ExtensionError, ConfigError, VersionRequirementError
@@ -87,12 +87,13 @@ 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', u'project = \n', 'ascii')
+ (dir / 'conf.py').write_text(u'project = \n', encoding='ascii')
raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None)
# test the automatic conversion of 2.x only code in configs
- write_file(dir / 'conf.py', u'# -*- coding: utf-8\n\n'
- u'project = u"Jägermeister"\n', 'utf-8')
+ (dir / 'conf.py').write_text(
+ u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
+ encoding='utf-8')
cfg = Config(dir, 'conf.py', {}, None)
cfg.init_values(lambda warning: 1/0)
assert cfg.project == u'Jägermeister'
@@ -102,8 +103,8 @@ def test_errors_warnings(dir):
# skip the test there
if sys.version_info >= (3, 0):
return
- write_file(dir / 'conf.py', u'# -*- coding: latin-1\nproject = "fooä"\n',
- 'latin-1')
+ (dir / 'conf.py').write_text(
+ u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
cfg = Config(dir, 'conf.py', {}, None)
warned = [False]
def warn(msg):
diff --git a/tests/test_intersphinx.py b/tests/test_intersphinx.py
index 01f06fa0..d342590d 100644
--- a/tests/test_intersphinx.py
+++ b/tests/test_intersphinx.py
@@ -22,7 +22,7 @@ from sphinx import addnodes
from sphinx.ext.intersphinx import read_inventory_v1, read_inventory_v2, \
load_mappings, missing_reference
-from util import with_app, with_tempdir, write_file
+from util import with_app, with_tempdir
inventory_v1 = '''\
@@ -85,7 +85,7 @@ def test_read_inventory_v2():
@with_tempdir
def test_missing_reference(tempdir, app):
inv_file = tempdir / 'inventory'
- write_file(inv_file, inventory_v2)
+ inv_file.write_bytes(inventory_v2)
app.config.intersphinx_mapping = {
'http://docs.python.org/': inv_file,
'py3k': ('http://docs.python.org/py3k/', inv_file),
@@ -165,7 +165,7 @@ def test_load_mappings_warnings(tempdir, app):
identifiers are not alphanumeric
"""
inv_file = tempdir / 'inventory'
- write_file(inv_file, inventory_v2)
+ inv_file.write_bytes(inventory_v2)
app.config.intersphinx_mapping = {
'http://docs.python.org/': inv_file,
'py3k': ('http://docs.python.org/py3k/', inv_file),
diff --git a/tests/util.py b/tests/util.py
index 36c835f5..8c4ff3df 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -12,7 +12,6 @@ import StringIO
import tempfile
import shutil
import re
-from codecs import open
from functools import wraps
from sphinx import application
@@ -28,7 +27,7 @@ __all__ = [
'test_root', 'test_roots', 'raises', 'raises_msg',
'skip_if', 'skip_unless', 'skip_unless_importable', 'Struct',
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
- 'path', 'with_tempdir', 'write_file',
+ 'path', 'with_tempdir',
'sprint', 'remove_unicode_literals',
]
@@ -224,18 +223,6 @@ def with_tempdir(func):
return new_func
-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), mode, encoding=encoding)
- f.write(contents)
- f.close()
-
-
def sprint(*args):
sys.stderr.write(' '.join(map(str, args)) + '\n')