From 48128c7b9b8eff5de97c1be61d071fef3a2bb1ea Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Wed, 2 May 2012 12:05:41 +0900 Subject: [PATCH 1/5] * fix test for Windows: test failed by test-code problem depends on os.sep. --- tests/test_build_html.py | 3 ++- tests/test_build_latex.py | 3 ++- tests/test_build_texinfo.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_build_html.py b/tests/test_build_html.py index a38806a865..6812257b6e 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -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 + \ diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4e1e9f70c0..2fa0698b8b 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -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 + \ diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index c626c976b1..59d03e0300 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -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 + \ From 7e56be6f62d48354b8c91f9d0fdb0e2f48d5df97 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Wed, 2 May 2012 12:06:29 +0900 Subject: [PATCH 2/5] * fix for Python2.5: test failed by using os.path.relpath that introduced at Python-2.6. --- sphinx/util/osutil.py | 3 ++- sphinx/util/pycompat.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 5becc37df6..c5fee9d93a 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -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 diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 9e081b02fb..c2c6fe8b1d 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -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 From 733854e121c05281acc3efd3c42020414282b842 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Wed, 2 May 2012 12:07:04 +0900 Subject: [PATCH 3/5] * fix for Python2.5: test failed by using inspect.ArgSpec that introduced at Python-2.6. --- sphinx/util/inspect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index b5c3db598d..ba3fa9681f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -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 From b948dfc7e0835ffaadc8faf69d982641d4c8a55f Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Wed, 2 May 2012 15:55:11 +0900 Subject: [PATCH 4/5] fix for Python3: Python3 open() use 'rt' mode by default, and decoding by locale.getpreferredencoding(). In sphinx test, html output encoded by 'utf-8' but reading with syste-locale-setting-encode that cause UnicodeDecodeError. --- tests/test_build_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 6812257b6e..62bd5a88bc 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -329,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: From 33167797a0fa2e963b21356ebd12877722b6e41d Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Thu, 3 May 2012 10:15:21 +0900 Subject: [PATCH 5/5] fix for Python3.1: Python 3.1 can't proceess '\r' at parser; `parser.suite("print('hello')\r\n")` cause error. --- sphinx/highlighting.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 2f61c1ef11..f4e6f36a1e 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -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