mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Merged in shimizukawa/sphinx-fix-testing-fork (pull request #62)
This commit is contained in:
@@ -143,6 +143,12 @@ class PygmentsBridge(object):
|
||||
# just replace all non-ASCII characters.
|
||||
src = src.encode('ascii', 'replace')
|
||||
|
||||
if sys.version_info < (3, 2):
|
||||
# Python 3.1 can't proceess '\r' as linesep.
|
||||
# `parser.suite("print('hello')\r\n")` cause error.
|
||||
if '\r\n' in src:
|
||||
src = src.replace('\r\n', '\n')
|
||||
|
||||
if parser is None:
|
||||
return True
|
||||
|
||||
|
||||
@@ -45,7 +45,10 @@ if sys.version_info >= (2, 5):
|
||||
del func_defaults[i]
|
||||
except IndexError:
|
||||
pass
|
||||
return inspect.ArgSpec(args, varargs, varkw, func_defaults)
|
||||
if sys.version_info >= (2, 6):
|
||||
return inspect.ArgSpec(args, varargs, varkw, func_defaults)
|
||||
else:
|
||||
return (args, varargs, varkw, func_defaults)
|
||||
else:
|
||||
getargspec = inspect.getargspec
|
||||
|
||||
|
||||
@@ -136,8 +136,9 @@ else:
|
||||
|
||||
|
||||
def safe_relpath(path, start=None):
|
||||
from sphinx.util.pycompat import relpath
|
||||
try:
|
||||
return os.path.relpath(path, start)
|
||||
return relpath(path, start)
|
||||
except ValueError:
|
||||
return path
|
||||
|
||||
|
||||
@@ -82,6 +82,10 @@ if sys.version_info >= (2, 6):
|
||||
except ImportError:
|
||||
from itertools import izip_longest as zip_longest
|
||||
|
||||
import os
|
||||
relpath = os.path.relpath
|
||||
del os
|
||||
|
||||
else:
|
||||
# Python < 2.6
|
||||
from itertools import izip, repeat, chain
|
||||
@@ -114,6 +118,26 @@ else:
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
from os.path import curdir
|
||||
def relpath(path, start=curdir):
|
||||
"""Return a relative version of a path"""
|
||||
from os.path import sep, abspath, commonprefix, join, pardir
|
||||
|
||||
if not path:
|
||||
raise ValueError("no path specified")
|
||||
|
||||
start_list = abspath(start).split(sep)
|
||||
path_list = abspath(path).split(sep)
|
||||
|
||||
# Work out how much of the filepath is shared by start and path.
|
||||
i = len(commonprefix([start_list, path_list]))
|
||||
|
||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||
if not rel_list:
|
||||
return curdir
|
||||
return join(*rel_list)
|
||||
del curdir
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Missing builtins and codecs in Python < 2.5
|
||||
|
||||
@@ -319,7 +319,8 @@ def check_static_entries(outdir):
|
||||
def test_html(app):
|
||||
app.builder.build_all()
|
||||
html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
|
||||
html_warnings_exp = HTML_WARNINGS % {'root': re.escape(app.srcdir)}
|
||||
html_warnings_exp = HTML_WARNINGS % {
|
||||
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
||||
assert re.match(html_warnings_exp + '$', html_warnings), \
|
||||
'Warnings don\'t match:\n' + \
|
||||
'--- Expected (regex):\n' + html_warnings_exp + \
|
||||
@@ -328,7 +329,7 @@ def test_html(app):
|
||||
for fname, paths in HTML_XPATH.iteritems():
|
||||
parser = NslessParser()
|
||||
parser.entity.update(htmlentitydefs.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname))
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
|
||||
@@ -42,7 +42,8 @@ def test_latex(app):
|
||||
LaTeXTranslator.ignore_missing_images = True
|
||||
app.builder.build_all()
|
||||
latex_warnings = latex_warnfile.getvalue().replace(os.sep, '/')
|
||||
latex_warnings_exp = LATEX_WARNINGS % {'root': re.escape(app.srcdir)}
|
||||
latex_warnings_exp = LATEX_WARNINGS % {
|
||||
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
||||
assert re.match(latex_warnings_exp + '$', latex_warnings), \
|
||||
'Warnings don\'t match:\n' + \
|
||||
'--- Expected (regex):\n' + latex_warnings_exp + \
|
||||
|
||||
@@ -41,7 +41,8 @@ def test_texinfo(app):
|
||||
TexinfoTranslator.ignore_missing_images = True
|
||||
app.builder.build_all()
|
||||
texinfo_warnings = texinfo_warnfile.getvalue().replace(os.sep, '/')
|
||||
texinfo_warnings_exp = TEXINFO_WARNINGS % {'root': re.escape(app.srcdir)}
|
||||
texinfo_warnings_exp = TEXINFO_WARNINGS % {
|
||||
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
||||
assert re.match(texinfo_warnings_exp + '$', texinfo_warnings), \
|
||||
'Warnings don\'t match:\n' + \
|
||||
'--- Expected (regex):\n' + texinfo_warnings_exp + \
|
||||
|
||||
Reference in New Issue
Block a user