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
|
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.config import Config
|
||||||
from sphinx.errors import ExtensionError, ConfigError, VersionRequirementError
|
from sphinx.errors import ExtensionError, ConfigError, VersionRequirementError
|
||||||
@ -87,12 +87,13 @@ def test_extension_values(app):
|
|||||||
@with_tempdir
|
@with_tempdir
|
||||||
def test_errors_warnings(dir):
|
def test_errors_warnings(dir):
|
||||||
# test the error for syntax errors in the config file
|
# 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)
|
raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None)
|
||||||
|
|
||||||
# test the automatic conversion of 2.x only code in configs
|
# test the automatic conversion of 2.x only code in configs
|
||||||
write_file(dir / 'conf.py', u'# -*- coding: utf-8\n\n'
|
(dir / 'conf.py').write_text(
|
||||||
u'project = u"Jägermeister"\n', 'utf-8')
|
u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
|
||||||
|
encoding='utf-8')
|
||||||
cfg = Config(dir, 'conf.py', {}, None)
|
cfg = Config(dir, 'conf.py', {}, None)
|
||||||
cfg.init_values(lambda warning: 1/0)
|
cfg.init_values(lambda warning: 1/0)
|
||||||
assert cfg.project == u'Jägermeister'
|
assert cfg.project == u'Jägermeister'
|
||||||
@ -102,8 +103,8 @@ def test_errors_warnings(dir):
|
|||||||
# skip the test there
|
# skip the test there
|
||||||
if sys.version_info >= (3, 0):
|
if sys.version_info >= (3, 0):
|
||||||
return
|
return
|
||||||
write_file(dir / 'conf.py', u'# -*- coding: latin-1\nproject = "fooä"\n',
|
(dir / 'conf.py').write_text(
|
||||||
'latin-1')
|
u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
|
||||||
cfg = Config(dir, 'conf.py', {}, None)
|
cfg = Config(dir, 'conf.py', {}, None)
|
||||||
warned = [False]
|
warned = [False]
|
||||||
def warn(msg):
|
def warn(msg):
|
||||||
|
@ -22,7 +22,7 @@ from sphinx import addnodes
|
|||||||
from sphinx.ext.intersphinx import read_inventory_v1, read_inventory_v2, \
|
from sphinx.ext.intersphinx import read_inventory_v1, read_inventory_v2, \
|
||||||
load_mappings, missing_reference
|
load_mappings, missing_reference
|
||||||
|
|
||||||
from util import with_app, with_tempdir, write_file
|
from util import with_app, with_tempdir
|
||||||
|
|
||||||
|
|
||||||
inventory_v1 = '''\
|
inventory_v1 = '''\
|
||||||
@ -85,7 +85,7 @@ def test_read_inventory_v2():
|
|||||||
@with_tempdir
|
@with_tempdir
|
||||||
def test_missing_reference(tempdir, app):
|
def test_missing_reference(tempdir, app):
|
||||||
inv_file = tempdir / 'inventory'
|
inv_file = tempdir / 'inventory'
|
||||||
write_file(inv_file, inventory_v2)
|
inv_file.write_bytes(inventory_v2)
|
||||||
app.config.intersphinx_mapping = {
|
app.config.intersphinx_mapping = {
|
||||||
'http://docs.python.org/': inv_file,
|
'http://docs.python.org/': inv_file,
|
||||||
'py3k': ('http://docs.python.org/py3k/', 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
|
identifiers are not alphanumeric
|
||||||
"""
|
"""
|
||||||
inv_file = tempdir / 'inventory'
|
inv_file = tempdir / 'inventory'
|
||||||
write_file(inv_file, inventory_v2)
|
inv_file.write_bytes(inventory_v2)
|
||||||
app.config.intersphinx_mapping = {
|
app.config.intersphinx_mapping = {
|
||||||
'http://docs.python.org/': inv_file,
|
'http://docs.python.org/': inv_file,
|
||||||
'py3k': ('http://docs.python.org/py3k/', inv_file),
|
'py3k': ('http://docs.python.org/py3k/', inv_file),
|
||||||
|
@ -12,7 +12,6 @@ import StringIO
|
|||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import re
|
import re
|
||||||
from codecs import open
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from sphinx import application
|
from sphinx import application
|
||||||
@ -28,7 +27,7 @@ __all__ = [
|
|||||||
'test_root', 'test_roots', 'raises', 'raises_msg',
|
'test_root', 'test_roots', 'raises', 'raises_msg',
|
||||||
'skip_if', 'skip_unless', 'skip_unless_importable', 'Struct',
|
'skip_if', 'skip_unless', 'skip_unless_importable', 'Struct',
|
||||||
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
||||||
'path', 'with_tempdir', 'write_file',
|
'path', 'with_tempdir',
|
||||||
'sprint', 'remove_unicode_literals',
|
'sprint', 'remove_unicode_literals',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -224,18 +223,6 @@ def with_tempdir(func):
|
|||||||
return new_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):
|
def sprint(*args):
|
||||||
sys.stderr.write(' '.join(map(str, args)) + '\n')
|
sys.stderr.write(' '.join(map(str, args)) + '\n')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user