mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
remove tests.util.write_file duplicated implementation.
This commit is contained in:
parent
638458038d
commit
1e4b390b22
@ -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):
|
||||
|
@ -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),
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user