From c1249b9d9f69ff900882b3573699491bc98ebe5a Mon Sep 17 00:00:00 2001 From: DasIch Date: Thu, 29 Apr 2010 20:34:08 +0200 Subject: Don't use execfile() anymore --- tests/test_quickstart.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index cb40d27c..34c54f95 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -85,7 +85,11 @@ def test_quickstart_defaults(tempdir): conffile = tempdir / 'conf.py' assert conffile.isfile() ns = {} - execfile(conffile, ns) + try: + f = open(conffile, 'U') + exec f in ns + finally: + f.close() assert ns['extensions'] == [] assert ns['templates_path'] == ['_templates'] assert ns['source_suffix'] == '.rst' @@ -138,7 +142,11 @@ def test_quickstart_all_answers(tempdir): conffile = tempdir / 'source' / 'conf.py' assert conffile.isfile() ns = {} - execfile(conffile, ns) + try: + f = open(conffile, 'U') + exec f in ns + finally: + f.close() assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] assert ns['templates_path'] == ['.templates'] assert ns['source_suffix'] == '.txt' -- cgit v1.2.1 From 4ce956559b3786c58754f0bcf5c2498d9750d10a Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 1 May 2010 19:19:24 +0200 Subject: Removed pre-2.3 workaround for booleans --- tests/path.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index ceb895f5..20deb048 100644 --- a/tests/path.py +++ b/tests/path.py @@ -56,12 +56,6 @@ try: except AttributeError: pass -# Pre-2.3 workaround for booleans -try: - True, False -except NameError: - True, False = 1, 0 - # Pre-2.3 workaround for basestring. try: basestring -- cgit v1.2.1 From 2a269673211ea132664998037d3c94f8e0b48367 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 1 May 2010 20:26:05 +0200 Subject: Move open() calls out of the try block --- tests/test_quickstart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 34c54f95..71ca95a4 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -85,8 +85,8 @@ def test_quickstart_defaults(tempdir): conffile = tempdir / 'conf.py' assert conffile.isfile() ns = {} + f = open(conffile, 'U') try: - f = open(conffile, 'U') exec f in ns finally: f.close() @@ -142,8 +142,8 @@ def test_quickstart_all_answers(tempdir): conffile = tempdir / 'source' / 'conf.py' assert conffile.isfile() ns = {} + f = open(conffile, 'U') try: - f = open(conffile, 'U') exec f in ns finally: f.close() -- cgit v1.2.1 From b2b313c98290c93e2d38d0abb9b04f373775baa1 Mon Sep 17 00:00:00 2001 From: Daniel Neuh?user Date: Sat, 8 May 2010 22:00:15 +0200 Subject: Use code objects for exec statements instead of files --- tests/test_quickstart.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 71ca95a4..8acff588 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -87,9 +87,10 @@ def test_quickstart_defaults(tempdir): ns = {} f = open(conffile, 'U') try: - exec f in ns + code = compile(f.read(), conffile, 'exec') finally: f.close() + exec code in ns assert ns['extensions'] == [] assert ns['templates_path'] == ['_templates'] assert ns['source_suffix'] == '.rst' @@ -144,9 +145,10 @@ def test_quickstart_all_answers(tempdir): ns = {} f = open(conffile, 'U') try: - exec f in ns + code = compile(f.read(), conffile, 'exec') finally: f.close() + exec code in ns assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] assert ns['templates_path'] == ['.templates'] assert ns['source_suffix'] == '.txt' -- cgit v1.2.1 From 3ab89e534d271f8e5ee030fd260da7f16bfcc007 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 8 May 2010 23:23:56 +0200 Subject: Use 'U' if file is not present (we run under 3.x) --- tests/path.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index 20deb048..7b89c0cd 100644 --- a/tests/path.py +++ b/tests/path.py @@ -64,8 +64,13 @@ except NameError: # Universal newline support _textmode = 'r' -if hasattr(file, 'newlines'): +try: + file +except NameError: _textmode = 'U' +else: + if hasattr(file, 'newlines'): + _textmode = 'U' class TreeWalkWarning(Warning): -- cgit v1.2.1 From 1c968e303f920e0f6e39153c7a1f0e2048b2a64d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 18:19:17 +0200 Subject: Make it easier for the test suite to override raw_input for test_quickstart. --- tests/test_quickstart.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 8acff588..d0403d3b 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -37,7 +37,7 @@ def mock_raw_input(answers, needanswer=False): return raw_input def teardown_module(): - qs.raw_input = __builtin__.raw_input + qs.term_input = raw_input qs.TERM_ENCODING = getattr(sys.stdin, 'encoding', None) coloron() @@ -51,7 +51,7 @@ def test_do_prompt(): 'Q5': 'no', 'Q6': 'foo', } - qs.raw_input = mock_raw_input(answers) + qs.term_input = mock_raw_input(answers) try: qs.do_prompt(d, 'k1', 'Q1') except AssertionError: @@ -79,7 +79,7 @@ def test_quickstart_defaults(tempdir): 'Author name': 'Georg Brandl', 'Project version': '0.1', } - qs.raw_input = mock_raw_input(answers) + qs.term_input = mock_raw_input(answers) qs.inner_main([]) conffile = tempdir / 'conf.py' @@ -136,7 +136,7 @@ def test_quickstart_all_answers(tempdir): 'Create Windows command file': 'no', 'Do you want to use the epub builder': 'yes', } - qs.raw_input = mock_raw_input(answers, needanswer=True) + qs.term_input = mock_raw_input(answers, needanswer=True) qs.TERM_ENCODING = 'utf-8' qs.inner_main([]) -- cgit v1.2.1 From dd8aac39ece4a01f64ad2f146751ddba2b07035e Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 9 May 2010 00:38:16 +0200 Subject: Changed tests/run.py so that it's possible to run the testsuite on python3 more easiely --- tests/run.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 0cb41442..5fd30d62 100755 --- a/tests/run.py +++ b/tests/run.py @@ -11,7 +11,16 @@ """ import sys -from os import path +from os import path, chdir + +if sys.version_info >= (3,): + print('Copying and converting sources to build/lib/test...') + from distutils.util import copydir_run_2to3 + testroot = path.dirname(__file__) or '.' + newroot = path.join(testroot, path.pardir, 'build', 'lib', 'test') + copydir_run_2to3(testroot, newroot) + # switch to the converted dir so nose tests the right tests + chdir(newroot) # always test the sphinx package from this directory sys.path.insert(0, path.join(path.dirname(__file__), path.pardir)) @@ -19,8 +28,8 @@ sys.path.insert(0, path.join(path.dirname(__file__), path.pardir)) try: import nose except ImportError: - print "The nose package is needed to run the Sphinx test suite." + print("The nose package is needed to run the Sphinx test suite.") sys.exit(1) -print "Running Sphinx test suite..." +print("Running Sphinx test suite...") nose.main() -- cgit v1.2.1 From 2928e66c78713363f0bc24c2399226337a95d9d7 Mon Sep 17 00:00:00 2001 From: DasIch Date: Mon, 24 May 2010 17:35:43 +0200 Subject: use open instead of file --- tests/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index 7b89c0cd..f27e58a9 100644 --- a/tests/path.py +++ b/tests/path.py @@ -516,7 +516,7 @@ class path(_base): def open(self, mode='r'): """ Open this file. Return a file object. """ - return file(self, mode) + return open(self, mode) def bytes(self): """ Open this file, read all bytes, return them as a string. """ -- cgit v1.2.1 From 6a24d9f7f17e469fd9f222613ef0353cb54f04b6 Mon Sep 17 00:00:00 2001 From: DasIch Date: Mon, 24 May 2010 19:41:02 +0200 Subject: fixed test_markup test --- tests/test_markup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_markup.py b/tests/test_markup.py index 31817df6..6d6badbb 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -10,6 +10,7 @@ """ import re +import sys from util import * @@ -20,6 +21,12 @@ from sphinx.util import texescape from sphinx.writers.html import HTMLWriter, SmartyPantsHTMLTranslator from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator +if sys.version_info > (3, 0): + def b(s): + return s.encode('utf-8') +else: + b = str + def setup_module(): global app, settings, parser texescape.init() # otherwise done by the latex builder @@ -50,7 +57,7 @@ class ForgivingLaTeXTranslator(LaTeXTranslator, ForgivingTranslator): def verify_re(rst, html_expected, latex_expected): - document = utils.new_document('test data', settings) + document = utils.new_document(b('test data'), settings) document['file'] = 'dummy' parser.parse(rst, document) for msg in document.traverse(nodes.system_message): -- cgit v1.2.1 From 695f93d286f8ea23fff15c92b8d675b36aa592db Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 18:43:40 +0200 Subject: Move the "b" function to pycompat. --- tests/test_markup.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_markup.py b/tests/test_markup.py index 6d6badbb..092113bb 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -10,7 +10,6 @@ """ import re -import sys from util import * @@ -18,15 +17,10 @@ from docutils import frontend, utils, nodes from docutils.parsers import rst from sphinx.util import texescape +from sphinx.util.pycompat import b from sphinx.writers.html import HTMLWriter, SmartyPantsHTMLTranslator from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator -if sys.version_info > (3, 0): - def b(s): - return s.encode('utf-8') -else: - b = str - def setup_module(): global app, settings, parser texescape.init() # otherwise done by the latex builder -- cgit v1.2.1 From efd37f2b4583bd415702ad43d51b76ca6298a03e Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 30 May 2010 17:51:14 +0200 Subject: Fix encoding in config test and open configs in binary mode to warn for possible encoding errors --- tests/test_config.py | 5 +++-- tests/util.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_config.py b/tests/test_config.py index cb4e1105..23d92e39 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -84,11 +84,12 @@ 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', 'project = \n') + write_file(dir / 'conf.py', u'project = \n', 'ascii') raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None) # test the warning for bytestrings with non-ascii content - write_file(dir / 'conf.py', '# -*- coding: latin-1\nproject = "foo\xe4"\n') + write_file(dir / 'conf.py', + u'# -*- coding: latin-1\nproject = "fooä"\n', 'latin-1') cfg = Config(dir, 'conf.py', {}, None) warned = [False] def warn(msg): diff --git a/tests/util.py b/tests/util.py index 1b24af0e..2cf4a775 100644 --- a/tests/util.py +++ b/tests/util.py @@ -11,6 +11,7 @@ import sys import StringIO import tempfile import shutil +from codecs import open try: from functools import wraps @@ -191,8 +192,14 @@ def with_tempdir(func): return new_func -def write_file(name, contents): - f = open(str(name), 'wb') +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), 'wb', encoding=encoding) f.write(contents) f.close() -- cgit v1.2.1 From 861dd3c479f8a8515bc5182a694d3c8f234dce43 Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 1 Jun 2010 18:10:06 +0200 Subject: Replaced the path module with my own version --- tests/path.py | 972 +++------------------------------------------------------- 1 file changed, 49 insertions(+), 923 deletions(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index f27e58a9..36ab3a9a 100644 --- a/tests/path.py +++ b/tests/path.py @@ -1,952 +1,78 @@ -""" path.py - An object representing a path to a file or directory. - -Example: - -from path import path -d = path('/home/guido/bin') -for f in d.files('*.py'): - f.chmod(0755) - -This module requires Python 2.2 or later. - - -URL: http://www.jorendorff.com/articles/python/path -Author: Jason Orendorff (and others - see the url!) -Date: 9 Mar 2007 +#!/usr/bin/env python +# coding: utf-8 """ + path + ~~~~ + :copyright: Copyright 2010 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import os +import sys +import shutil +from codecs import open -# TODO -# - Tree-walking functions don't avoid symlink loops. Matt Harrison -# sent me a patch for this. -# - Bug in write_text(). It doesn't support Universal newline mode. -# - Better error message in listdir() when self isn't a -# directory. (On Windows, the error message really sucks.) -# - Make sure everything has a good docstring. -# - Add methods for regex find and replace. -# - guess_content_type() method? -# - Perhaps support arguments to touch(). - -from __future__ import generators - -import sys, warnings, os, fnmatch, glob, shutil, codecs - -__version__ = '2.2' -__all__ = ['path'] - -# Platform-specific support for path.owner -if os.name == 'nt': - try: - import win32security - except ImportError: - win32security = None -else: - try: - import pwd - except ImportError: - pwd = None - -# Pre-2.3 support. Are unicode filenames supported? -_base = str -_getcwd = os.getcwd -try: - if os.path.supports_unicode_filenames: - _base = unicode - _getcwd = os.getcwdu -except AttributeError: - pass - -# Pre-2.3 workaround for basestring. -try: - basestring -except NameError: - basestring = (str, unicode) - -# Universal newline support -_textmode = 'r' -try: - file -except NameError: - _textmode = 'U' -else: - if hasattr(file, 'newlines'): - _textmode = 'U' - - -class TreeWalkWarning(Warning): - pass - -class path(_base): - """ Represents a filesystem path. - - For documentation on individual methods, consult their - counterparts in os.path. - """ - - # --- Special Python methods. - - def __repr__(self): - return 'path(%s)' % _base.__repr__(self) - - # Adding a path and a string yields a path. - def __add__(self, more): - try: - resultStr = _base.__add__(self, more) - except TypeError: #Python bug - resultStr = NotImplemented - if resultStr is NotImplemented: - return resultStr - return self.__class__(resultStr) - - def __radd__(self, other): - if isinstance(other, basestring): - return self.__class__(other.__add__(self)) - else: - return NotImplemented - - # The / operator joins paths. - def __div__(self, rel): - """ fp.__div__(rel) == fp / rel == fp.joinpath(rel) - - Join two path components, adding a separator character if - needed. - """ - return self.__class__(os.path.join(self, rel)) - - # Make the / operator work even when true division is enabled. - __truediv__ = __div__ - - def getcwd(cls): - """ Return the current working directory as a path object. """ - return cls(_getcwd()) - getcwd = classmethod(getcwd) - - - # --- Operations on path strings. - - isabs = os.path.isabs - def abspath(self): return self.__class__(os.path.abspath(self)) - def normcase(self): return self.__class__(os.path.normcase(self)) - def normpath(self): return self.__class__(os.path.normpath(self)) - def realpath(self): return self.__class__(os.path.realpath(self)) - def expanduser(self): return self.__class__(os.path.expanduser(self)) - def expandvars(self): return self.__class__(os.path.expandvars(self)) - def dirname(self): return self.__class__(os.path.dirname(self)) - basename = os.path.basename - - def expand(self): - """ Clean up a filename by calling expandvars(), - expanduser(), and normpath() on it. - - This is commonly everything needed to clean up a filename - read from a configuration file, for example. - """ - return self.expandvars().expanduser().normpath() - - def _get_namebase(self): - base, ext = os.path.splitext(self.name) - return base - - def _get_ext(self): - f, ext = os.path.splitext(_base(self)) - return ext - - def _get_drive(self): - drive, r = os.path.splitdrive(self) - return self.__class__(drive) - - parent = property( - dirname, None, None, - """ This path's parent directory, as a new path object. - - For example, path('/usr/local/lib/libpython.so').parent == path('/usr/local/lib') - """) - - name = property( - basename, None, None, - """ The name of this file or directory without the full path. - - For example, path('/usr/local/lib/libpython.so').name == 'libpython.so' - """) - - namebase = property( - _get_namebase, None, None, - """ The same as path.name, but with one file extension stripped off. - - For example, path('/home/guido/python.tar.gz').name == 'python.tar.gz', - but path('/home/guido/python.tar.gz').namebase == 'python.tar' - """) - - ext = property( - _get_ext, None, None, - """ The file extension, for example '.py'. """) - - drive = property( - _get_drive, None, None, - """ The drive specifier, for example 'C:'. - This is always empty on systems that don't use drive specifiers. - """) - - def splitpath(self): - """ p.splitpath() -> Return (p.parent, p.name). """ - parent, child = os.path.split(self) - return self.__class__(parent), child - - def splitdrive(self): - """ p.splitdrive() -> Return (p.drive, ). - - Split the drive specifier from this path. If there is - no drive specifier, p.drive is empty, so the return value - is simply (path(''), p). This is always the case on Unix. - """ - drive, rel = os.path.splitdrive(self) - return self.__class__(drive), rel - - def splitext(self): - """ p.splitext() -> Return (p.stripext(), p.ext). - - Split the filename extension from this path and return - the two parts. Either part may be empty. - - The extension is everything from '.' to the end of the - last path segment. This has the property that if - (a, b) == p.splitext(), then a + b == p. - """ - filename, ext = os.path.splitext(self) - return self.__class__(filename), ext - - def stripext(self): - """ p.stripext() -> Remove one file extension from the path. - - For example, path('/home/guido/python.tar.gz').stripext() - returns path('/home/guido/python.tar'). - """ - return self.splitext()[0] - - if hasattr(os.path, 'splitunc'): - def splitunc(self): - unc, rest = os.path.splitunc(self) - return self.__class__(unc), rest - - def _get_uncshare(self): - unc, r = os.path.splitunc(self) - return self.__class__(unc) - - uncshare = property( - _get_uncshare, None, None, - """ The UNC mount point for this path. - This is empty for paths on local drives. """) - - def joinpath(self, *args): - """ Join two or more path components, adding a separator - character (os.sep) if needed. Returns a new path - object. - """ - return self.__class__(os.path.join(self, *args)) - - def splitall(self): - r""" Return a list of the path components in this path. - - The first item in the list will be a path. Its value will be - either os.curdir, os.pardir, empty, or the root directory of - this path (for example, '/' or 'C:\\'). The other items in - the list will be strings. - - path.path.joinpath(*result) will yield the original path. - """ - parts = [] - loc = self - while loc != os.curdir and loc != os.pardir: - prev = loc - loc, child = prev.splitpath() - if loc == prev: - break - parts.append(child) - parts.append(loc) - parts.reverse() - return parts - - def relpath(self): - """ Return this path as a relative path, - based from the current working directory. - """ - cwd = self.__class__(os.getcwd()) - return cwd.relpathto(self) - - def relpathto(self, dest): - """ Return a relative path from self to dest. - - If there is no relative path from self to dest, for example if - they reside on different drives in Windows, then this returns - dest.abspath(). - """ - origin = self.abspath() - dest = self.__class__(dest).abspath() - - orig_list = origin.normcase().splitall() - # Don't normcase dest! We want to preserve the case. - dest_list = dest.splitall() - - if orig_list[0] != os.path.normcase(dest_list[0]): - # Can't get here from there. - return dest - - # Find the location where the two paths start to differ. - i = 0 - for start_seg, dest_seg in zip(orig_list, dest_list): - if start_seg != os.path.normcase(dest_seg): - break - i += 1 - - # Now i is the point where the two paths diverge. - # Need a certain number of "os.pardir"s to work up - # from the origin to the point of divergence. - segments = [os.pardir] * (len(orig_list) - i) - # Need to add the diverging part of dest_list. - segments += dest_list[i:] - if len(segments) == 0: - # If they happen to be identical, use os.curdir. - relpath = os.curdir - else: - relpath = os.path.join(*segments) - return self.__class__(relpath) - - # --- Listing, searching, walking, and matching - - def listdir(self, pattern=None): - """ D.listdir() -> List of items in this directory. - - Use D.files() or D.dirs() instead if you want a listing - of just files or just subdirectories. - - The elements of the list are path objects. - - With the optional 'pattern' argument, this only lists - items whose names match the given pattern. - """ - names = os.listdir(self) - if pattern is not None: - names = fnmatch.filter(names, pattern) - return [self / child for child in names] - - def dirs(self, pattern=None): - """ D.dirs() -> List of this directory's subdirectories. - - The elements of the list are path objects. - This does not walk recursively into subdirectories - (but see path.walkdirs). - - With the optional 'pattern' argument, this only lists - directories whose names match the given pattern. For - example, d.dirs('build-*'). - """ - return [p for p in self.listdir(pattern) if p.isdir()] - - def files(self, pattern=None): - """ D.files() -> List of the files in this directory. - - The elements of the list are path objects. - This does not walk into subdirectories (see path.walkfiles). - - With the optional 'pattern' argument, this only lists files - whose names match the given pattern. For example, - d.files('*.pyc'). - """ - - return [p for p in self.listdir(pattern) if p.isfile()] - - def walk(self, pattern=None, errors='strict'): - """ D.walk() -> iterator over files and subdirs, recursively. - - The iterator yields path objects naming each child item of - this directory and its descendants. This requires that - D.isdir(). - - This performs a depth-first traversal of the directory tree. - Each directory is returned just before all its children. - - The errors= keyword argument controls behavior when an - error occurs. The default is 'strict', which causes an - exception. The other allowed values are 'warn', which - reports the error via warnings.warn(), and 'ignore'. - """ - if errors not in ('strict', 'warn', 'ignore'): - raise ValueError("invalid errors parameter") - - try: - childList = self.listdir() - except Exception: - if errors == 'ignore': - return - elif errors == 'warn': - warnings.warn( - "Unable to list directory '%s': %s" - % (self, sys.exc_info()[1]), - TreeWalkWarning) - return - else: - raise - - for child in childList: - if pattern is None or child.fnmatch(pattern): - yield child - try: - isdir = child.isdir() - except Exception: - if errors == 'ignore': - isdir = False - elif errors == 'warn': - warnings.warn( - "Unable to access '%s': %s" - % (child, sys.exc_info()[1]), - TreeWalkWarning) - isdir = False - else: - raise - - if isdir: - for item in child.walk(pattern, errors): - yield item - - def walkdirs(self, pattern=None, errors='strict'): - """ D.walkdirs() -> iterator over subdirs, recursively. - - With the optional 'pattern' argument, this yields only - directories whose names match the given pattern. For - example, mydir.walkdirs('*test') yields only directories - with names ending in 'test'. - - The errors= keyword argument controls behavior when an - error occurs. The default is 'strict', which causes an - exception. The other allowed values are 'warn', which - reports the error via warnings.warn(), and 'ignore'. - """ - if errors not in ('strict', 'warn', 'ignore'): - raise ValueError("invalid errors parameter") - - try: - dirs = self.dirs() - except Exception: - if errors == 'ignore': - return - elif errors == 'warn': - warnings.warn( - "Unable to list directory '%s': %s" - % (self, sys.exc_info()[1]), - TreeWalkWarning) - return - else: - raise - - for child in dirs: - if pattern is None or child.fnmatch(pattern): - yield child - for subsubdir in child.walkdirs(pattern, errors): - yield subsubdir - - def walkfiles(self, pattern=None, errors='strict'): - """ D.walkfiles() -> iterator over files in D, recursively. - The optional argument, pattern, limits the results to files - with names that match the pattern. For example, - mydir.walkfiles('*.tmp') yields only files with the .tmp - extension. - """ - if errors not in ('strict', 'warn', 'ignore'): - raise ValueError("invalid errors parameter") +FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() - try: - childList = self.listdir() - except Exception: - if errors == 'ignore': - return - elif errors == 'warn': - warnings.warn( - "Unable to list directory '%s': %s" - % (self, sys.exc_info()[1]), - TreeWalkWarning) - return - else: - raise - for child in childList: - try: - isfile = child.isfile() - isdir = not isfile and child.isdir() - except: - if errors == 'ignore': - continue - elif errors == 'warn': - warnings.warn( - "Unable to access '%s': %s" - % (self, sys.exc_info()[1]), - TreeWalkWarning) - continue +class path(str): + if sys.version_info < (3, 0): + def __new__(cls, s, encoding=FILESYSTEMENCODING, errors=None): + if isinstance(s, unicode): + if errors is None: + s = s.encode(encoding) else: - raise - - if isfile: - if pattern is None or child.fnmatch(pattern): - yield child - elif isdir: - for f in child.walkfiles(pattern, errors): - yield f + s = s.encode(encoding, errors=errors) + return str.__new__(cls, s) + return str.__new__(cls, s) - def fnmatch(self, pattern): - """ Return True if self.name matches the given pattern. + @property + def parent(self): + return self.__class__(os.path.dirname(self)) - pattern - A filename pattern with wildcards, - for example '*.py'. - """ - return fnmatch.fnmatch(self.name, pattern) + def abspath(self): + return self.__class__(os.path.abspath(self)) - def glob(self, pattern): - """ Return a list of path objects that match the pattern. + def isdir(self): + return os.path.isdir(self) - pattern - a path relative to this directory, with wildcards. + def isfile(self): + return os.path.isfile(self) - For example, path('/users').glob('*/bin/*') returns a list - of all the files users have in their bin directories. - """ - cls = self.__class__ - return [cls(s) for s in glob.glob(_base(self / pattern))] + def rmtree(self, ignore_errors=False, onerror=None): + shutil.rmtree(self, ignore_errors=ignore_errors, onerror=onerror) + def copytree(self, destination, symlinks=False, ignore=None): + shutil.copytree(self, destination, symlinks=symlinks, ignore=ignore) - # --- Reading or writing an entire file at once. - - def open(self, mode='r'): - """ Open this file. Return a file object. """ - return open(self, mode) - - def bytes(self): - """ Open this file, read all bytes, return them as a string. """ - f = self.open('rb') - try: - return f.read() - finally: - f.close() - - def write_bytes(self, bytes, append=False): - """ Open this file and write the given bytes to it. + def unlink(self): + os.unlink(self) - Default behavior is to overwrite any existing file. - Call p.write_bytes(bytes, append=True) to append instead. - """ - if append: - mode = 'ab' - else: - mode = 'wb' - f = self.open(mode) + def write_text(self, text, **kwargs): + f = open(self, 'w', **kwargs) try: - f.write(bytes) + f.write(text) finally: f.close() - def text(self, encoding=None, errors='strict'): - r""" Open this file, read it in, return the content as a string. - - This uses 'U' mode in Python 2.3 and later, so '\r\n' and '\r' - are automatically translated to '\n'. - - Optional arguments: - - encoding - The Unicode encoding (or character set) of - the file. If present, the content of the file is - decoded and returned as a unicode object; otherwise - it is returned as an 8-bit str. - errors - How to handle Unicode errors; see help(str.decode) - for the options. Default is 'strict'. - """ - if encoding is None: - # 8-bit - f = self.open(_textmode) - try: - return f.read() - finally: - f.close() - else: - # Unicode - f = codecs.open(self, 'r', encoding, errors) - # (Note - Can't use 'U' mode here, since codecs.open - # doesn't support 'U' mode, even in Python 2.3.) - try: - t = f.read() - finally: - f.close() - return (t.replace(u'\r\n', u'\n') - .replace(u'\r\x85', u'\n') - .replace(u'\r', u'\n') - .replace(u'\x85', u'\n') - .replace(u'\u2028', u'\n')) - - def write_text(self, text, encoding=None, errors='strict', linesep=os.linesep, append=False): - r""" Write the given text to this file. - - The default behavior is to overwrite any existing file; - to append instead, use the 'append=True' keyword argument. - - There are two differences between path.write_text() and - path.write_bytes(): newline handling and Unicode handling. - See below. - - Parameters: - - - text - str/unicode - The text to be written. - - - encoding - str - The Unicode encoding that will be used. - This is ignored if 'text' isn't a Unicode string. - - - errors - str - How to handle Unicode encoding errors. - Default is 'strict'. See help(unicode.encode) for the - options. This is ignored if 'text' isn't a Unicode - string. - - - linesep - keyword argument - str/unicode - The sequence of - characters to be used to mark end-of-line. The default is - os.linesep. You can also specify None; this means to - leave all newlines as they are in 'text'. - - - append - keyword argument - bool - Specifies what to do if - the file already exists (True: append to the end of it; - False: overwrite it.) The default is False. - - - --- Newline handling. - - write_text() converts all standard end-of-line sequences - ('\n', '\r', and '\r\n') to your platform's default end-of-line - sequence (see os.linesep; on Windows, for example, the - end-of-line marker is '\r\n'). - - If you don't like your platform's default, you can override it - using the 'linesep=' keyword argument. If you specifically want - write_text() to preserve the newlines as-is, use 'linesep=None'. - - This applies to Unicode text the same as to 8-bit text, except - there are three additional standard Unicode end-of-line sequences: - u'\x85', u'\r\x85', and u'\u2028'. - - (This is slightly different from when you open a file for - writing with fopen(filename, "w") in C or file(filename, 'w') - in Python.) - - - --- Unicode - - If 'text' isn't Unicode, then apart from newline handling, the - bytes are written verbatim to the file. The 'encoding' and - 'errors' arguments are not used and must be omitted. - - If 'text' is Unicode, it is first converted to bytes using the - specified 'encoding' (or the default encoding if 'encoding' - isn't specified). The 'errors' argument applies only to this - conversion. - - """ - if isinstance(text, unicode): - if linesep is not None: - # Convert all standard end-of-line sequences to - # ordinary newline characters. - text = (text.replace(u'\r\n', u'\n') - .replace(u'\r\x85', u'\n') - .replace(u'\r', u'\n') - .replace(u'\x85', u'\n') - .replace(u'\u2028', u'\n')) - text = text.replace(u'\n', linesep) - if encoding is None: - encoding = sys.getdefaultencoding() - bytes = text.encode(encoding, errors) - else: - # It is an error to specify an encoding if 'text' is - # an 8-bit string. - assert encoding is None - - if linesep is not None: - text = (text.replace('\r\n', '\n') - .replace('\r', '\n')) - bytes = text.replace('\n', linesep) - - self.write_bytes(bytes, append) - - def lines(self, encoding=None, errors='strict', retain=True): - r""" Open this file, read all lines, return them in a list. - - Optional arguments: - encoding - The Unicode encoding (or character set) of - the file. The default is None, meaning the content - of the file is read as 8-bit characters and returned - as a list of (non-Unicode) str objects. - errors - How to handle Unicode errors; see help(str.decode) - for the options. Default is 'strict' - retain - If true, retain newline characters; but all newline - character combinations ('\r', '\n', '\r\n') are - translated to '\n'. If false, newline characters are - stripped off. Default is True. - - This uses 'U' mode in Python 2.3 and later. - """ - if encoding is None and retain: - f = self.open(_textmode) - try: - return f.readlines() - finally: - f.close() - else: - return self.text(encoding, errors).splitlines(retain) - - def write_lines(self, lines, encoding=None, errors='strict', - linesep=os.linesep, append=False): - r""" Write the given lines of text to this file. - - By default this overwrites any existing file at this path. - - This puts a platform-specific newline sequence on every line. - See 'linesep' below. - - lines - A list of strings. - - encoding - A Unicode encoding to use. This applies only if - 'lines' contains any Unicode strings. - - errors - How to handle errors in Unicode encoding. This - also applies only to Unicode strings. - - linesep - The desired line-ending. This line-ending is - applied to every line. If a line already has any - standard line ending ('\r', '\n', '\r\n', u'\x85', - u'\r\x85', u'\u2028'), that will be stripped off and - this will be used instead. The default is os.linesep, - which is platform-dependent ('\r\n' on Windows, '\n' on - Unix, etc.) Specify None to write the lines as-is, - like file.writelines(). - - Use the keyword argument append=True to append lines to the - file. The default is to overwrite the file. Warning: - When you use this with Unicode data, if the encoding of the - existing data in the file is different from the encoding - you specify with the encoding= parameter, the result is - mixed-encoding data, which can really confuse someone trying - to read the file later. - """ - if append: - mode = 'ab' - else: - mode = 'wb' - f = self.open(mode) + def text(self, **kwargs): + f = open(self, mode='U', **kwargs) try: - for line in lines: - isUnicode = isinstance(line, unicode) - if linesep is not None: - # Strip off any existing line-end and add the - # specified linesep string. - if isUnicode: - if line[-2:] in (u'\r\n', u'\x0d\x85'): - line = line[:-2] - elif line[-1:] in (u'\r', u'\n', - u'\x85', u'\u2028'): - line = line[:-1] - else: - if line[-2:] == '\r\n': - line = line[:-2] - elif line[-1:] in ('\r', '\n'): - line = line[:-1] - line += linesep - if isUnicode: - if encoding is None: - encoding = sys.getdefaultencoding() - line = line.encode(encoding, errors) - f.write(line) + return f.read() finally: f.close() - # --- Methods for querying the filesystem. - - exists = os.path.exists - isdir = os.path.isdir - isfile = os.path.isfile - islink = os.path.islink - ismount = os.path.ismount - - if hasattr(os.path, 'samefile'): - samefile = os.path.samefile - - getatime = os.path.getatime - atime = property( - getatime, None, None, - """ Last access time of the file. """) - - getmtime = os.path.getmtime - mtime = property( - getmtime, None, None, - """ Last-modified time of the file. """) - - if hasattr(os.path, 'getctime'): - getctime = os.path.getctime - ctime = property( - getctime, None, None, - """ Creation time of the file. """) - - getsize = os.path.getsize - size = property( - getsize, None, None, - """ Size of the file, in bytes. """) - - if hasattr(os, 'access'): - def access(self, mode): - """ Return true if current user has access to this path. - - mode - One of the constants os.F_OK, os.R_OK, os.W_OK, os.X_OK - """ - return os.access(self, mode) - - def stat(self): - """ Perform a stat() system call on this path. """ - return os.stat(self) - - def lstat(self): - """ Like path.stat(), but do not follow symbolic links. """ - return os.lstat(self) - - def get_owner(self): - r""" Return the name of the owner of this file or directory. - - This follows symbolic links. - - On Windows, this returns a name of the form ur'DOMAIN\User Name'. - On Windows, a group can own a file or directory. - """ - if os.name == 'nt': - if win32security is None: - raise Exception("path.owner requires win32all to be installed") - desc = win32security.GetFileSecurity( - self, win32security.OWNER_SECURITY_INFORMATION) - sid = desc.GetSecurityDescriptorOwner() - account, domain, typecode = win32security.LookupAccountSid(None, sid) - return domain + u'\\' + account - else: - if pwd is None: - raise NotImplementedError("path.owner is not implemented on this platform.") - st = self.stat() - return pwd.getpwuid(st.st_uid).pw_name - - owner = property( - get_owner, None, None, - """ Name of the owner of this file or directory. """) - - if hasattr(os, 'statvfs'): - def statvfs(self): - """ Perform a statvfs() system call on this path. """ - return os.statvfs(self) - - if hasattr(os, 'pathconf'): - def pathconf(self, name): - return os.pathconf(self, name) - - - # --- Modifying operations on files and directories - - def utime(self, times): - """ Set the access and modified times of this file. """ - os.utime(self, times) - - def chmod(self, mode): - os.chmod(self, mode) - - if hasattr(os, 'chown'): - def chown(self, uid, gid): - os.chown(self, uid, gid) - - def rename(self, new): - os.rename(self, new) - - def renames(self, new): - os.renames(self, new) - - - # --- Create/delete operations on directories - - def mkdir(self, mode=0777): - os.mkdir(self, mode) + def exists(self): + return os.path.exists(self) def makedirs(self, mode=0777): os.makedirs(self, mode) - def rmdir(self): - os.rmdir(self) - - def removedirs(self): - os.removedirs(self) - - - # --- Modifying operations on files - - def touch(self): - """ Set the access/modified times of this file to the current time. - Create the file if it does not exist. - """ - fd = os.open(self, os.O_WRONLY | os.O_CREAT, 0666) - os.close(fd) - os.utime(self, None) - - def remove(self): - os.remove(self) - - def unlink(self): - os.unlink(self) - - - # --- Links - - if hasattr(os, 'link'): - def link(self, newpath): - """ Create a hard link at 'newpath', pointing to this file. """ - os.link(self, newpath) - - if hasattr(os, 'symlink'): - def symlink(self, newlink): - """ Create a symbolic link at 'newlink', pointing here. """ - os.symlink(self, newlink) - - if hasattr(os, 'readlink'): - def readlink(self): - """ Return the path to which this symbolic link points. - - The result may be an absolute or a relative path. - """ - return self.__class__(os.readlink(self)) - - def readlinkabs(self): - """ Return the path to which this symbolic link points. - - The result is always an absolute path. - """ - p = self.readlink() - if p.isabs(): - return p - else: - return (self.parent / p).abspath() - - - # --- High-level functions from shutil - - copyfile = shutil.copyfile - copymode = shutil.copymode - copystat = shutil.copystat - copy = shutil.copy - copy2 = shutil.copy2 - copytree = shutil.copytree - if hasattr(shutil, 'move'): - move = shutil.move - rmtree = shutil.rmtree - - - # --- Special stuff from os - - if hasattr(os, 'chroot'): - def chroot(self): - os.chroot(self) + def joinpath(self, *args): + return self.__class__(os.path.join(self, *map(self.__class__, args))) - if hasattr(os, 'startfile'): - def startfile(self): - os.startfile(self) + __div__ = __truediv__ = joinpath + def __repr__(self): + return '%s(%s)' % (self.__class__.__name__, str.__repr__(self)) -- cgit v1.2.1 From 122a47304bb1d3960da7decc64a9f28291047ed9 Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 1 Jun 2010 19:59:38 +0200 Subject: Added a movetree method to the path object to make it more consistent along with documentation for every method of it. --- tests/path.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index 36ab3a9a..dccdac3a 100644 --- a/tests/path.py +++ b/tests/path.py @@ -17,6 +17,9 @@ FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() class path(str): + """ + Represents a path which behaves like a string. + """ if sys.version_info < (3, 0): def __new__(cls, s, encoding=FILESYSTEMENCODING, errors=None): if isinstance(s, unicode): @@ -29,27 +32,103 @@ class path(str): @property def parent(self): + """ + The name of the directory the file or directory is in. + """ return self.__class__(os.path.dirname(self)) def abspath(self): + """ + Returns the absolute path. + """ return self.__class__(os.path.abspath(self)) + def isabs(self): + """ + Returns ``True`` if the path is absolute. + """ + return os.path.isabs(self) + def isdir(self): + """ + Returns ``True`` if the path is a directory. + """ return os.path.isdir(self) def isfile(self): + """ + Returns ``True`` if the path is a file. + """ return os.path.isfile(self) + def islink(self): + """ + Returns ``True`` if the path is a symbolic link. + """ + return os.path.islink(self) + + def ismount(self): + """ + Returns ``True`` if the path is a mount point. + """ + return os.path.ismount(self) + def rmtree(self, ignore_errors=False, onerror=None): + """ + Removes the file or directory and any files or directories it may + contain. + + :param ignore_errors: + If ``True`` errors are silently ignored, otherwise an exception + is raised in case an error occurs. + + :param onerror: + A callback which gets called with the arguments `func`, `path` and + `exc_info`. `func` is one of :func:`os.listdir`, :func:`os.remove` + or :func:`os.rmdir`. `path` is the argument to the function which + caused it to fail and `exc_info` is a tuple as returned by + :func:`sys.exc_info`. + """ shutil.rmtree(self, ignore_errors=ignore_errors, onerror=onerror) def copytree(self, destination, symlinks=False, ignore=None): + """ + Recursively copy a directory to the given `destination`. If the given + `destination` does not exist it will be created. + + :param symlinks: + If ``True`` symbolic links in the source tree result in symbolic + links in the destination tree otherwise the contents of the files + pointed to by the symbolic links are copied. + + :param ignore: + A callback which gets called with the path of the directory being + copied and a list of paths as returned by :func:`os.listdir`. + """ shutil.copytree(self, destination, symlinks=symlinks, ignore=ignore) + def movetree(self, destination): + """ + Recursively move the file or directory to the given `destination` + similar to the Unix "mv" command. + + If the `destination` is a file it may be overwritten depending on the + :func:`os.rename` semantics. + """ + shutil.move(self, destination) + + move = movetree + def unlink(self): + """ + Removes a file. + """ os.unlink(self) def write_text(self, text, **kwargs): + """ + Writes the given `text` to the file. + """ f = open(self, 'w', **kwargs) try: f.write(text) @@ -57,6 +136,9 @@ class path(str): f.close() def text(self, **kwargs): + """ + Returns the text in the file. + """ f = open(self, mode='U', **kwargs) try: return f.read() @@ -64,12 +146,28 @@ class path(str): f.close() def exists(self): + """ + Returns ``True`` if the path exist. + """ return os.path.exists(self) + def lexists(self): + """ + Returns ``True`` if the path exists unless it is a broken symbolic + link. + """ + return os.path.lexists(self) + def makedirs(self, mode=0777): + """ + Recursively create directories. + """ os.makedirs(self, mode) def joinpath(self, *args): + """ + Joins the path with the argument given and returns the result. + """ return self.__class__(os.path.join(self, *map(self.__class__, args))) __div__ = __truediv__ = joinpath -- cgit v1.2.1 From c15e9ef0ff35686578d8570ece99611a9b23e137 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 6 Jun 2010 23:13:06 +0200 Subject: don't use string.strip anymore --- tests/test_autosummary.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_autosummary.py b/tests/test_autosummary.py index 7e309367..20fb06e0 100644 --- a/tests/test_autosummary.py +++ b/tests/test_autosummary.py @@ -9,8 +9,6 @@ :license: BSD, see LICENSE for details. """ -import string - from util import * from sphinx.ext.autosummary import mangle_signature @@ -27,7 +25,7 @@ def test_mangle_signature(): (a, b, c='foobar()', d=123) :: (a, b[, c, d]) """ - TEST = [map(string.strip, x.split("::")) for x in TEST.split("\n") + TEST = [map(lambda x: x.strip(), x.split("::")) for x in TEST.split("\n") if '::' in x] for inp, outp in TEST: res = mangle_signature(inp).strip().replace(u"\u00a0", " ") -- cgit v1.2.1 From 05a6f46d3e182991431e3cd277b7b51ea813dadc Mon Sep 17 00:00:00 2001 From: DasIch Date: Mon, 7 Jun 2010 01:34:01 +0200 Subject: fixed file handling and parsing in intersphinx so it properly handles encodings --- tests/test_intersphinx.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_intersphinx.py b/tests/test_intersphinx.py index 8b6547e5..4f70bd20 100644 --- a/tests/test_intersphinx.py +++ b/tests/test_intersphinx.py @@ -11,7 +11,10 @@ import zlib import posixpath -from cStringIO import StringIO +try: + from io import BytesIO +except ImportError: + from cStringIO import StringIO as BytesIO from docutils import nodes @@ -28,23 +31,23 @@ inventory_v1 = '''\ # Version: 1.0 module mod foo.html module.cls class foo.html -''' +'''.encode('utf-8') inventory_v2 = '''\ # Sphinx inventory version 2 # Project: foo # Version: 2.0 # The remainder of this file is compressed with zlib. -''' + zlib.compress('''\ +'''.encode('utf-8') + zlib.compress('''\ module1 py:module 0 foo.html#module-module1 Long Module desc module2 py:module 0 foo.html#module-$ - module1.func py:function 1 sub/foo.html#$ - CFunc c:function 2 cfunc.html#CFunc - -''') +'''.encode('utf-8')) def test_read_inventory_v1(): - f = StringIO(inventory_v1) + f = BytesIO(inventory_v1) f.readline() invdata = read_inventory_v1(f, '/util', posixpath.join) assert invdata['py:module']['module'] == \ @@ -54,12 +57,12 @@ def test_read_inventory_v1(): def test_read_inventory_v2(): - f = StringIO(inventory_v2) + f = BytesIO(inventory_v2) f.readline() invdata1 = read_inventory_v2(f, '/util', posixpath.join) # try again with a small buffer size to test the chunking algorithm - f = StringIO(inventory_v2) + f = BytesIO(inventory_v2) f.readline() invdata2 = read_inventory_v2(f, '/util', posixpath.join, bufsize=5) -- cgit v1.2.1 From c529f967eca0e62cffa3fc929a04e7fe258d6a6d Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 12 Jun 2010 15:16:57 +0200 Subject: Copy converted tests to build/lib/tests not build/lib/test --- tests/run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 5fd30d62..f384fe26 100755 --- a/tests/run.py +++ b/tests/run.py @@ -14,10 +14,10 @@ import sys from os import path, chdir if sys.version_info >= (3,): - print('Copying and converting sources to build/lib/test...') + print('Copying and converting sources to build/lib/tests...') from distutils.util import copydir_run_2to3 testroot = path.dirname(__file__) or '.' - newroot = path.join(testroot, path.pardir, 'build', 'lib', 'test') + newroot = path.join(testroot, path.pardir, 'build', 'lib', 'tests') copydir_run_2to3(testroot, newroot) # switch to the converted dir so nose tests the right tests chdir(newroot) -- cgit v1.2.1 From 8232e3a896fb23e71c11c0d41901a50a36c4690c Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 12 Jun 2010 20:21:14 +0200 Subject: Remove unnecessary code --- tests/path.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index dccdac3a..28a8c22a 100644 --- a/tests/path.py +++ b/tests/path.py @@ -21,12 +21,9 @@ class path(str): Represents a path which behaves like a string. """ if sys.version_info < (3, 0): - def __new__(cls, s, encoding=FILESYSTEMENCODING, errors=None): + def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): if isinstance(s, unicode): - if errors is None: - s = s.encode(encoding) - else: - s = s.encode(encoding, errors=errors) + s = s.encode(encoding, errors=errors) return str.__new__(cls, s) return str.__new__(cls, s) -- cgit v1.2.1 From 0d055b80a97daaa29c49a2b0e507d60fa7a0e9a3 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 19 Jun 2010 16:38:52 +0200 Subject: Fix test to respect the new .truncate() behavior --- tests/test_application.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/test_application.py b/tests/test_application.py index 3d287a57..d1154863 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -45,9 +45,11 @@ def test_output(): app = TestApp(status=status, warning=warnings) try: status.truncate(0) # __init__ writes to status + status.seek(0) app.info("Nothing here...") assert status.getvalue() == "Nothing here...\n" status.truncate(0) + status.seek(0) app.info("Nothing here...", True) assert status.getvalue() == "Nothing here..." -- cgit v1.2.1 From 64b37e03e42f94ddd9486d0afd1ffd5e47cc1f4e Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 19 Jun 2010 21:50:00 +0200 Subject: make doctest work with python2 and python3 --- tests/root/conf.py | 2 +- tests/root/doctest.txt | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/root/conf.py b/tests/root/conf.py index 2b6d6a9a..b4734189 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -22,7 +22,7 @@ copyright = '2010, Georg Brandl & Team' version = '0.6' release = '0.6alpha1' today_fmt = '%B %d, %Y' -#unused_docs = [] +# unused_docs = [] exclude_patterns = ['_build', '**/excluded.*'] keep_warnings = True pygments_style = 'sphinx' diff --git a/tests/root/doctest.txt b/tests/root/doctest.txt index 35cdd589..6ac0b286 100644 --- a/tests/root/doctest.txt +++ b/tests/root/doctest.txt @@ -30,7 +30,7 @@ Special directives .. testcode:: - print 1+1 + print(1+1) .. testoutput:: @@ -50,30 +50,30 @@ Special directives .. testsetup:: * - from math import floor + from math import factorial .. doctest:: - >>> floor(1.2) - 1.0 + >>> factorial(1) + 1 .. testcode:: - print floor(1.2) + print(factorial(1)) .. testoutput:: - 1.0 + 1 - >>> floor(1.2) - 1.0 + >>> factorial(1) + 1 * options for testcode/testoutput blocks .. testcode:: :hide: - print 'Output text.' + print('Output text.') .. testoutput:: :hide: @@ -85,36 +85,36 @@ Special directives .. testsetup:: group1 - from math import ceil + from math import trunc - ``ceil`` is now known in "group1", but not in others. + ``trunc`` is now known in "group1", but not in others. .. doctest:: group1 - >>> ceil(0.8) - 1.0 + >>> trunc(1.1) + 1 .. doctest:: group2 - >>> ceil(0.8) + >>> trunc(1.1) Traceback (most recent call last): ... - NameError: name 'ceil' is not defined + NameError: name 'trunc' is not defined Interleaving testcode/testoutput: .. testcode:: group1 - print ceil(0.8) + print(factorial(3)) .. testcode:: group2 - print floor(0.8) + print(factorial(4)) .. testoutput:: group1 - 1.0 + 6 .. testoutput:: group2 - 0.0 + 24 -- cgit v1.2.1 From 6680b807c17db68681a98a89f92a3dec944d2eda Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 19 Jun 2010 19:58:28 +0200 Subject: Fixed the coverage extension test as well as the coverage extension itself for python3 --- tests/path.py | 27 +++++++++++++++++++++++++++ tests/test_coverage.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/path.py b/tests/path.py index 28a8c22a..df96bce4 100644 --- a/tests/path.py +++ b/tests/path.py @@ -142,6 +142,33 @@ class path(str): finally: f.close() + def bytes(self): + """ + Returns the bytes in the file. + """ + f = open(self, mode='rb') + try: + return f.read() + finally: + f.close() + + def write_bytes(self, bytes, append=False): + """ + Writes the given `bytes` to the file. + + :param append: + If ``True`` given `bytes` are added at the end of the file. + """ + if append: + mode = 'ab' + else: + mode = 'wb' + f = open(self, mode=mode) + try: + f.write(bytes) + finally: + f.close() + def exists(self): """ Returns ``True`` if the path exist. diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 1262ebf5..cb831635 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -33,7 +33,7 @@ def test_build(app): assert 'api.h' in c_undoc assert ' * Py_SphinxTest' in c_undoc - undoc_py, undoc_c = pickle.loads((app.outdir / 'undoc.pickle').text()) + undoc_py, undoc_c = pickle.loads((app.outdir / 'undoc.pickle').bytes()) assert len(undoc_c) == 1 # the key is the full path to the header file, which isn't testable assert undoc_c.values()[0] == [('function', 'Py_SphinxTest')] -- cgit v1.2.1 From 2f961d167d0c8a3c26a62a1771032c232cc5cf65 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 20 Jun 2010 19:34:49 +0200 Subject: Fix warning for bytestrings with non-ascii content for python3 --- tests/test_config.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_config.py b/tests/test_config.py index 23d92e39..ecf90f60 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,6 +9,7 @@ :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import sys from util import * @@ -88,8 +89,12 @@ def test_errors_warnings(dir): raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None) # test the warning for bytestrings with non-ascii content - write_file(dir / 'conf.py', - u'# -*- coding: latin-1\nproject = "fooä"\n', 'latin-1') + # bytestrings with non-ascii content are a syntax error in python3 so we + # 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') cfg = Config(dir, 'conf.py', {}, None) warned = [False] def warn(msg): -- cgit v1.2.1 From db6d04b5fcf265b0ce0e3f3afa7807ed5de91399 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 20 Jun 2010 22:39:38 +0200 Subject: Fixed warnings in python3 --- tests/test_build_html.py | 5 +++++ tests/test_build_latex.py | 3 +++ tests/util.py | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 4dee513a..65c1840e 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -12,6 +12,7 @@ import os import re import htmlentitydefs +import sys from StringIO import StringIO try: @@ -60,6 +61,10 @@ def tail_check(check): return checker +if sys.version_info >= (3, 0): + ENV_WARNINGS = remove_unicode_literals(ENV_WARNINGS) + HTML_WARNINGS = remove_unicode_literals(HTML_WARNINGS) + HTML_XPATH = { 'images.html': [ (".//img[@src='_images/img.png']", ''), diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4405395a..6c1ccad9 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -32,6 +32,9 @@ None:None: WARNING: no matching candidate for image URI u'foo.\\*' WARNING: invalid pair index entry u'' """ +if sys.version_info >= (3, 0): + LATEX_WARNINGS = remove_unicode_literals(LATEX_WARNINGS) + @with_app(buildername='latex', warning=latex_warnfile, cleanenv=True) def test_latex(app): diff --git a/tests/util.py b/tests/util.py index 2cf4a775..950ea23f 100644 --- a/tests/util.py +++ b/tests/util.py @@ -11,6 +11,7 @@ import sys import StringIO import tempfile import shutil +import re from codecs import open try: @@ -32,7 +33,7 @@ __all__ = [ 'raises', 'raises_msg', 'Struct', 'ListOutput', 'TestApp', 'with_app', 'gen_with_app', 'path', 'with_tempdir', 'write_file', - 'sprint', + 'sprint', 'remove_unicode_literals', ] @@ -206,3 +207,7 @@ def write_file(name, contents, encoding=None): def sprint(*args): sys.stderr.write(' '.join(map(str, args)) + '\n') + +_unicode_literals_re = re.compile(r'u(".*")|u(\'.*\')') +def remove_unicode_literals(s): + return _unicode_literals_re.sub(lambda x: x.group(1) or x.group(2), s) -- cgit v1.2.1 From 68e145cf0816da9301217240cbba4be9b43a9589 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 19:15:04 +0200 Subject: Make string contents nongreedy. --- tests/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/util.py b/tests/util.py index 950ea23f..b81e15b6 100644 --- a/tests/util.py +++ b/tests/util.py @@ -208,6 +208,6 @@ def write_file(name, contents, encoding=None): def sprint(*args): sys.stderr.write(' '.join(map(str, args)) + '\n') -_unicode_literals_re = re.compile(r'u(".*")|u(\'.*\')') +_unicode_literals_re = re.compile(r'u(".*?")|u(\'.*?\')') def remove_unicode_literals(s): return _unicode_literals_re.sub(lambda x: x.group(1) or x.group(2), s) -- cgit v1.2.1 From b658c351d3479df5d54f88eff3f10166c7253a81 Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 22 Jun 2010 22:49:58 +0200 Subject: the test suite now runs on ubuntu, hopefully also debian and other system --- tests/run.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index f384fe26..59a3ffa5 100755 --- a/tests/run.py +++ b/tests/run.py @@ -11,13 +11,14 @@ """ import sys -from os import path, chdir +from os import path, chdir, listdir if sys.version_info >= (3,): print('Copying and converting sources to build/lib/tests...') from distutils.util import copydir_run_2to3 testroot = path.dirname(__file__) or '.' - newroot = path.join(testroot, path.pardir, 'build', 'lib', 'tests') + newroot = path.join(testroot, path.pardir, 'build') + newroot = path.join(newroot, listdir(newroot)[0], 'tests') copydir_run_2to3(testroot, newroot) # switch to the converted dir so nose tests the right tests chdir(newroot) -- cgit v1.2.1 From 5cc8cecdec5eb4181cffa1ca3b5c4081472970dd Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 10 Jul 2010 19:47:32 +0200 Subject: Removed XMLParser._fixtext which fixes several errors in the test suite --- tests/etree13/ElementTree.py | 17 ++++------------- tests/test_build_html.py | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/etree13/ElementTree.py b/tests/etree13/ElementTree.py index d3732504..e50ad640 100644 --- a/tests/etree13/ElementTree.py +++ b/tests/etree13/ElementTree.py @@ -1425,13 +1425,6 @@ class XMLParser(object): err.position = value.lineno, value.offset raise err - def _fixtext(self, text): - # convert text string to ascii, if possible - try: - return text.encode("ascii") - except UnicodeError: - return text - def _fixname(self, key): # expand qname, and convert name string to ascii, if possible try: @@ -1440,30 +1433,28 @@ class XMLParser(object): name = key if "}" in name: name = "{" + name - self._names[key] = name = self._fixtext(name) + self._names[key] return name def _start(self, tag, attrib_in): fixname = self._fixname - fixtext = self._fixtext tag = fixname(tag) attrib = {} for key, value in attrib_in.items(): - attrib[fixname(key)] = fixtext(value) + attrib[fixname(key)] = value return self.target.start(tag, attrib) def _start_list(self, tag, attrib_in): fixname = self._fixname - fixtext = self._fixtext tag = fixname(tag) attrib = {} if attrib_in: for i in range(0, len(attrib_in), 2): - attrib[fixname(attrib_in[i])] = fixtext(attrib_in[i+1]) + attrib[fixname(attrib_in[i])] = attrib_in[i+1] return self.target.start(tag, attrib) def _data(self, text): - return self.target.data(self._fixtext(text)) + return self.target.data(text) def _end(self, tag): return self.target.end(self._fixname(tag)) diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 65c1840e..5e3a2018 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -258,7 +258,7 @@ class NslessParser(ET.XMLParser): br = name.find('}') if br > 0: name = name[br+1:] - self._names[key] = name = self._fixtext(name) + self._names[key] = name return name -- cgit v1.2.1 From 69de288fb75fc12d161a8441be4fe1fd4477f775 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 11 Jul 2010 00:57:08 +0200 Subject: Revert changes from the last commit which caused problems with 2.x --- tests/etree13/ElementTree.py | 17 +++++++++++++---- tests/test_build_html.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/etree13/ElementTree.py b/tests/etree13/ElementTree.py index e50ad640..d3732504 100644 --- a/tests/etree13/ElementTree.py +++ b/tests/etree13/ElementTree.py @@ -1425,6 +1425,13 @@ class XMLParser(object): err.position = value.lineno, value.offset raise err + def _fixtext(self, text): + # convert text string to ascii, if possible + try: + return text.encode("ascii") + except UnicodeError: + return text + def _fixname(self, key): # expand qname, and convert name string to ascii, if possible try: @@ -1433,28 +1440,30 @@ class XMLParser(object): name = key if "}" in name: name = "{" + name - self._names[key] + self._names[key] = name = self._fixtext(name) return name def _start(self, tag, attrib_in): fixname = self._fixname + fixtext = self._fixtext tag = fixname(tag) attrib = {} for key, value in attrib_in.items(): - attrib[fixname(key)] = value + attrib[fixname(key)] = fixtext(value) return self.target.start(tag, attrib) def _start_list(self, tag, attrib_in): fixname = self._fixname + fixtext = self._fixtext tag = fixname(tag) attrib = {} if attrib_in: for i in range(0, len(attrib_in), 2): - attrib[fixname(attrib_in[i])] = attrib_in[i+1] + attrib[fixname(attrib_in[i])] = fixtext(attrib_in[i+1]) return self.target.start(tag, attrib) def _data(self, text): - return self.target.data(text) + return self.target.data(self._fixtext(text)) def _end(self, tag): return self.target.end(self._fixname(tag)) diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 5e3a2018..65c1840e 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -258,7 +258,7 @@ class NslessParser(ET.XMLParser): br = name.find('}') if br > 0: name = name[br+1:] - self._names[key] = name + self._names[key] = name = self._fixtext(name) return name -- cgit v1.2.1 From 8355164b22844c6f234513631a298cde046211af Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 11 Jul 2010 01:05:27 +0200 Subject: Provided a working fix for the remaining errors in the test suite --- tests/etree13/ElementTree.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/etree13/ElementTree.py b/tests/etree13/ElementTree.py index d3732504..f459c7f8 100644 --- a/tests/etree13/ElementTree.py +++ b/tests/etree13/ElementTree.py @@ -1425,12 +1425,16 @@ class XMLParser(object): err.position = value.lineno, value.offset raise err - def _fixtext(self, text): - # convert text string to ascii, if possible - try: - return text.encode("ascii") - except UnicodeError: + if sys.version_info >= (3, 0): + def _fixtext(self, text): return text + else: + def _fixtext(self, text): + # convert text string to ascii, if possible + try: + return text.encode("ascii") + except UnicodeError: + return text def _fixname(self, key): # expand qname, and convert name string to ascii, if possible -- cgit v1.2.1 From c3de719cc5f7ed256ad3bfe39925c313b9cc99d1 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 11 Jul 2010 11:32:16 +0200 Subject: Fixed test_env.test_images test for python3 --- tests/test_env.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_env.py b/tests/test_env.py index 4ecbaac4..124ed08c 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -8,6 +8,7 @@ :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import sys from util import * @@ -54,8 +55,10 @@ def test_images(): app._warning.reset() htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.post_process_images(tree) - assert "no matching candidate for image URI u'foo.*'" in \ - app._warning.content[-1] + image_uri_message = "no matching candidate for image URI u'foo.*'" + if sys.version_info >= (3, 0): + image_uri_message = remove_unicode_literals(image_uri_message) + assert image_uri_message in app._warning.content[-1] assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg']) assert set(htmlbuilder.images.values()) == \ @@ -64,8 +67,7 @@ def test_images(): app._warning.reset() latexbuilder = LaTeXBuilder(app) latexbuilder.post_process_images(tree) - assert "no matching candidate for image URI u'foo.*'" in \ - app._warning.content[-1] + assert image_uri_message in app._warning.content[-1] assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf']) -- cgit v1.2.1 From ff445040232d83f025c8d8842804234d348f5ee3 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sun, 11 Jul 2010 12:24:50 +0200 Subject: Don't use (in this case) unnecessary python2 unicode literals --- tests/root/literal.inc | 2 +- tests/test_build_html.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/root/literal.inc b/tests/root/literal.inc index d5b9890c..694f15ed 100644 --- a/tests/root/literal.inc +++ b/tests/root/literal.inc @@ -1,7 +1,7 @@ # Literally included file using Python highlighting # -*- coding: utf-8 -*- -foo = u"Including Unicode characters: üöä" +foo = "Including Unicode characters: üöä" class Foo: pass diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 65c1840e..3ca2c757 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -232,7 +232,7 @@ if pygments: (".//div[@class='inc-lines highlight-text']//pre", r'^class Foo:\n pass\nclass Bar:\n$'), (".//div[@class='inc-startend highlight-text']//pre", - ur'^foo = u"Including Unicode characters: üöä"\n$'), + ur'^foo = "Including Unicode characters: üöä"\n$'), (".//div[@class='inc-preappend highlight-text']//pre", r'(?m)^START CODE$'), (".//div[@class='inc-pyobj-dedent highlight-python']//span", -- cgit v1.2.1 From f714133ad1807ae95c33a8ba294b288d4ca3af0a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 19:27:45 +0200 Subject: Give a binary document name. --- tests/test_search.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_search.py b/tests/test_search.py index 0b5b158b..c0750366 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -13,6 +13,7 @@ from docutils import frontend, utils from docutils.parsers import rst from sphinx.search import IndexBuilder +from sphinx.util.pycompat import b settings = parser = None @@ -31,7 +32,7 @@ test that non-comments are indexed: fermion ''' def test_wordcollector(): - doc = utils.new_document('test data', settings) + doc = utils.new_document(b('test data'), settings) doc['file'] = 'dummy' parser.parse(FILE_CONTENTS, doc) -- cgit v1.2.1 From 41e44bc87e76642cf4e2bc32f63431dbcf24bfb4 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 19:36:57 +0200 Subject: Unify version_info checks. --- tests/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 59a3ffa5..50567fbc 100755 --- a/tests/run.py +++ b/tests/run.py @@ -13,7 +13,7 @@ import sys from os import path, chdir, listdir -if sys.version_info >= (3,): +if sys.version_info >= (3, 0): print('Copying and converting sources to build/lib/tests...') from distutils.util import copydir_run_2to3 testroot = path.dirname(__file__) or '.' -- cgit v1.2.1 From e9b4aec500672dc8d7018c6f20610f8a7a6607a0 Mon Sep 17 00:00:00 2001 From: DasIch Date: Fri, 28 May 2010 04:08:15 +0200 Subject: Fix SyntaxError in config generated by quickstart and the quickstart test --- tests/test_quickstart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index d0403d3b..72ae764d 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -117,8 +117,8 @@ def test_quickstart_all_answers(tempdir): 'Root path': tempdir, 'Separate source and build': 'y', 'Name prefix for templates': '.', - 'Project name': 'STASI\xe2\x84\xa2', - 'Author name': 'Wolfgang Sch\xc3\xa4uble & G\'Beckstein', + 'Project name': u'STASI™'.encode('utf-8'), + 'Author name': u'Wolfgang Schäuble & G\'Beckstein'.encode('utf-8'), 'Project version': '2.0', 'Project release': '2.0.1', 'Source file suffix': '.txt', -- cgit v1.2.1 From 29591bef24e7398a23058fa80255266405f61625 Mon Sep 17 00:00:00 2001 From: DasIch Date: Fri, 2 Jul 2010 16:44:05 +0200 Subject: Add test for oldcmarkup warning --- tests/test_build_html.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index fe249f44..a1d99357 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -39,6 +39,9 @@ http://www.python.org/logo.png reading included file u'wrongenc.inc' seems to be wrong, try giving an \ :encoding: option %(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png +%(root)s/objects.txt:79: WARNING: using old C markup; please migrate to \ +new-style markup \(e.g. c:function instead of cfunction\), see \ +http://sphinx.pocoo.org/domains.html """ HTML_WARNINGS = ENV_WARNINGS + """\ -- cgit v1.2.1 From ae573607969eb6ecb45f4c35729ac09564ff7434 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 21 Jul 2010 11:33:24 +0100 Subject: Fix :guilabel: unescaping, and make some tests actually run. --- tests/root/markup.txt | 30 ++--- tests/test_build_html.py | 306 +++++++++++++++++++++++------------------------ 2 files changed, 169 insertions(+), 167 deletions(-) (limited to 'tests') diff --git a/tests/root/markup.txt b/tests/root/markup.txt index e286d26c..a72285ed 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -97,21 +97,23 @@ Inline markup *Generic inline markup* -* :command:`command` -* :dfn:`dfn` -* :guilabel:`guilabel with &accelerator` -* :kbd:`kbd` -* :mailheader:`mailheader` -* :makevar:`makevar` -* :manpage:`manpage` -* :mimetype:`mimetype` -* :newsgroup:`newsgroup` -* :program:`program` -* :regexp:`regexp` -* :menuselection:`File --> Close` +Adding \n to test unescaping. + +* :command:`command\\n` +* :dfn:`dfn\\n` +* :guilabel:`guilabel with &accelerator and \\n` +* :kbd:`kbd\\n` +* :mailheader:`mailheader\\n` +* :makevar:`makevar\\n` +* :manpage:`manpage\\n` +* :mimetype:`mimetype\\n` +* :newsgroup:`newsgroup\\n` +* :program:`program\\n` +* :regexp:`regexp\\n` +* :menuselection:`File --> Close\\n` * :menuselection:`&File --> &Print` -* :file:`a/{varpart}/b` -* :samp:`print {i}` +* :file:`a/{varpart}/b\\n` +* :samp:`print {i}\\n` *Linking inline markup* diff --git a/tests/test_build_html.py b/tests/test_build_html.py index a1d99357..bafee243 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -52,182 +52,182 @@ HTML_WARNINGS = ENV_WARNINGS + """\ """ HTML_XPATH = { - 'images.html': { - ".//img[@src='_images/img.png']": '', - ".//img[@src='_images/img1.png']": '', - ".//img[@src='_images/simg.png']": '', - ".//object[@data='_images/svgimg.svg']": '', - ".//embed[@src='_images/svgimg.svg']": '', - }, - 'subdir/images.html': { - ".//img[@src='../_images/img1.png']": '', - ".//img[@src='../_images/rimg.png']": '', - }, - 'subdir/includes.html': { - ".//a[@href='../_downloads/img.png']": '', - ".//img[@src='../_images/img.png']": '', - ".//p": 'This is an include file.', - }, - 'includes.html': { - ".//pre": u'Max Strauß', - ".//a[@href='_downloads/img.png']": '', - ".//a[@href='_downloads/img1.png']": '', - ".//pre": u'"quotes"', - ".//pre": u"'included'", - }, - 'autodoc.html': { - ".//dt[@id='test_autodoc.Class']": '', - ".//dt[@id='test_autodoc.function']/em": r'\*\*kwds', - ".//dd/p": r'Return spam\.', - }, - 'extapi.html': { - ".//strong": 'from function: Foo', - ".//strong": 'from class: Bar', - }, - 'markup.html': { - ".//title": 'set by title directive', - ".//p/em": 'Section author: Georg Brandl', - ".//p/em": 'Module author: Georg Brandl', + 'images.html': [ + (".//img[@src='_images/img.png']", ''), + (".//img[@src='_images/img1.png']", ''), + (".//img[@src='_images/simg.png']", ''), + (".//object[@data='_images/svgimg.svg']", ''), + (".//embed[@src='_images/svgimg.svg']", ''), + ], + 'subdir/images.html': [ + (".//img[@src='../_images/img1.png']", ''), + (".//img[@src='../_images/rimg.png']", ''), + ], + 'subdir/includes.html': [ + (".//a[@href='../_downloads/img.png']", ''), + (".//img[@src='../_images/img.png']", ''), + (".//p", 'This is an include file.'), + ], + 'includes.html': [ + (".//pre", u'Max Strauß'), + (".//a[@href='_downloads/img.png']", ''), + (".//a[@href='_downloads/img1.png']", ''), + (".//pre", u'"quotes"'), + (".//pre", u"'included'"), + ], + 'autodoc.html': [ + (".//dt[@id='test_autodoc.Class']", ''), + (".//dt[@id='test_autodoc.function']/em", r'\*\*kwds'), + (".//dd/p", r'Return spam\.'), + ], + 'extapi.html': [ + (".//strong", 'from function: Foo'), + (".//strong", 'from class: Bar'), + ], + 'markup.html': [ + (".//title", 'set by title directive'), + (".//p/em", 'Section author: Georg Brandl'), + (".//p/em", 'Module author: Georg Brandl'), # created by the meta directive - ".//meta[@name='author'][@content='Me']": '', - ".//meta[@name='keywords'][@content='docs, sphinx']": '', + (".//meta[@name='author'][@content='Me']", ''), + (".//meta[@name='keywords'][@content='docs, sphinx']", ''), # a label created by ``.. _label:`` - ".//div[@id='label']": '', + (".//div[@id='label']", ''), # code with standard code blocks - ".//pre": '^some code$', + (".//pre", '^some code$'), # an option list - ".//span[@class='option']": '--help', + (".//span[@class='option']", '--help'), # admonitions - ".//p[@class='first admonition-title']": 'My Admonition', - ".//p[@class='last']": 'Note text.', - ".//p[@class='last']": 'Warning text.', + (".//p[@class='first admonition-title']", 'My Admonition'), + (".//p[@class='last']", 'Note text.'), + (".//p[@class='last']", 'Warning text.'), # inline markup - ".//li/strong": '^command$', - ".//li/strong": '^program$', - ".//li/em": '^dfn$', - ".//li/tt/span[@class='pre']": '^kbd$', - ".//li/em": u'File \N{TRIANGULAR BULLET} Close', - ".//li/tt/span[@class='pre']": '^a/$', - ".//li/tt/em/span[@class='pre']": '^varpart$', - ".//li/tt/em/span[@class='pre']": '^i$', - ".//a[@href='http://www.python.org/dev/peps/pep-0008']" - "[@class='pep reference external']/strong": 'PEP 8', - ".//a[@href='http://tools.ietf.org/html/rfc1.html']" - "[@class='rfc reference external']/strong": 'RFC 1', - ".//a[@href='objects.html#envvar-HOME']" - "[@class='reference internal']/tt/span[@class='pre']": 'HOME', - ".//a[@href='#with']" - "[@class='reference internal']/tt/span[@class='pre']": '^with$', - ".//a[@href='#grammar-token-try_stmt']" - "[@class='reference internal']/tt/span": '^statement$', - ".//a[@href='subdir/includes.html']" - "[@class='reference internal']/em": 'Including in subdir', - ".//a[@href='objects.html#cmdoption-python-c']" - "[@class='reference internal']/em": 'Python -c option', + (".//li/strong", r'^command\\n$'), + (".//li/strong", r'^program\\n$'), + (".//li/em", r'^dfn\\n$'), + (".//li/tt/span[@class='pre']", r'^kbd\\n$'), + (".//li/em", u'File \N{TRIANGULAR BULLET} Close'), + (".//li/tt/span[@class='pre']", '^a/$'), + (".//li/tt/em/span[@class='pre']", '^varpart$'), + (".//li/tt/em/span[@class='pre']", '^i$'), + (".//a[@href='http://www.python.org/dev/peps/pep-0008']" + "[@class='pep reference external']/strong", 'PEP 8'), + (".//a[@href='http://tools.ietf.org/html/rfc1.html']" + "[@class='rfc reference external']/strong", 'RFC 1'), + (".//a[@href='objects.html#envvar-HOME']" + "[@class='reference internal']/tt/span[@class='pre']", 'HOME'), + (".//a[@href='#with']" + "[@class='reference internal']/tt/span[@class='pre']", '^with$'), + (".//a[@href='#grammar-token-try_stmt']" + "[@class='reference internal']/tt/span", '^statement$'), + (".//a[@href='subdir/includes.html']" + "[@class='reference internal']/em", 'Including in subdir'), + (".//a[@href='objects.html#cmdoption-python-c']" + "[@class='reference internal']/em", 'Python -c option'), # abbreviations - ".//abbr[@title='abbreviation']": '^abbr$', + (".//abbr[@title='abbreviation']", '^abbr$'), # version stuff - ".//span[@class='versionmodified']": 'New in version 0.6', + (".//span[@class='versionmodified']", 'New in version 0.6'), # footnote reference - ".//a[@class='footnote-reference']": r'\[1\]', + (".//a[@class='footnote-reference']", r'\[1\]'), # created by reference lookup - ".//a[@href='contents.html#ref1']": '', + (".//a[@href='contents.html#ref1']", ''), # ``seealso`` directive - ".//div/p[@class='first admonition-title']": 'See also', + (".//div/p[@class='first admonition-title']", 'See also'), # a ``hlist`` directive - ".//table[@class='hlist']/tr/td/ul/li": '^This$', + (".//table[@class='hlist']/tr/td/ul/li", '^This$'), # a ``centered`` directive - ".//p[@class='centered']/strong": 'LICENSE', + (".//p[@class='centered']/strong", 'LICENSE'), # a glossary - ".//dl/dt[@id='term-boson']": 'boson', + (".//dl/dt[@id='term-boson']", 'boson'), # a production list - ".//pre/strong": 'try_stmt', - ".//pre/a[@href='#grammar-token-try1_stmt']/tt/span": 'try1_stmt', + (".//pre/strong", 'try_stmt'), + (".//pre/a[@href='#grammar-token-try1_stmt']/tt/span", 'try1_stmt'), # tests for ``only`` directive - ".//p": 'A global substitution.', - ".//p": 'In HTML.', - ".//p": 'In both.', - ".//p": 'Always present', - }, - 'objects.html': { - ".//dt[@id='mod.Cls.meth1']": '', - ".//dt[@id='errmod.Error']": '', - ".//a[@href='#mod.Cls'][@class='reference internal']": '', - ".//dl[@class='userdesc']": '', - ".//dt[@id='userdesc-myobj']": '', - ".//a[@href='#userdesc-myobj']": '', + (".//p", 'A global substitution.'), + (".//p", 'In HTML.'), + (".//p", 'In both.'), + (".//p", 'Always present'), + ], + 'objects.html': [ + (".//dt[@id='mod.Cls.meth1']", ''), + (".//dt[@id='errmod.Error']", ''), + (".//a[@href='#mod.Cls'][@class='reference internal']", ''), + (".//dl[@class='userdesc']", ''), + (".//dt[@id='userdesc-myobj']", ''), + (".//a[@href='#userdesc-myobj']", ''), # C references - ".//span[@class='pre']": 'CFunction()', - ".//a[@href='#Sphinx_DoSomething']": '', - ".//a[@href='#SphinxStruct.member']": '', - ".//a[@href='#SPHINX_USE_PYTHON']": '', - ".//a[@href='#SphinxType']": '', - ".//a[@href='#sphinx_global']": '', + (".//span[@class='pre']", 'CFunction()'), + (".//a[@href='#Sphinx_DoSomething']", ''), + (".//a[@href='#SphinxStruct.member']", ''), + (".//a[@href='#SPHINX_USE_PYTHON']", ''), + (".//a[@href='#SphinxType']", ''), + (".//a[@href='#sphinx_global']", ''), # reference from old C markup extension - ".//a[@href='#Sphinx_Func']": '', + (".//a[@href='#Sphinx_Func']", ''), # test global TOC created by toctree() - ".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='']": - 'Testing object descriptions', - ".//li[@class='toctree-l1']/a[@href='markup.html']": - 'Testing various markup', + (".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='']", + 'Testing object descriptions'), + (".//li[@class='toctree-l1']/a[@href='markup.html']", + 'Testing various markup'), # custom sidebar - ".//h4": 'Custom sidebar', - }, - 'contents.html': { - ".//meta[@name='hc'][@content='hcval']": '', - ".//meta[@name='hc_co'][@content='hcval_co']": '', - ".//meta[@name='testopt'][@content='testoverride']": '', - ".//td[@class='label']": r'\[Ref1\]', - ".//td[@class='label']": '', - ".//li[@class='toctree-l1']/a": 'Testing various markup', - ".//li[@class='toctree-l2']/a": 'Inline markup', - ".//title": 'Sphinx ', - ".//div[@class='footer']": 'Georg Brandl & Team', - ".//a[@href='http://python.org/']" - "[@class='reference external']": '', - ".//li/a[@href='genindex.html']/em": 'Index', - ".//li/a[@href='py-modindex.html']/em": 'Module Index', - ".//li/a[@href='search.html']/em": 'Search Page', + (".//h4", 'Custom sidebar'), + ], + 'contents.html': [ + (".//meta[@name='hc'][@content='hcval']", ''), + (".//meta[@name='hc_co'][@content='hcval_co']", ''), + (".//meta[@name='testopt'][@content='testoverride']", ''), + (".//td[@class='label']", r'\[Ref1\]'), + (".//td[@class='label']", ''), + (".//li[@class='toctree-l1']/a", 'Testing various markup'), + (".//li[@class='toctree-l2']/a", 'Inline markup'), + (".//title", 'Sphinx '), + (".//div[@class='footer']", 'Georg Brandl & Team'), + (".//a[@href='http://python.org/']" + "[@class='reference external']", ''), + (".//li/a[@href='genindex.html']/em", 'Index'), + (".//li/a[@href='py-modindex.html']/em", 'Module Index'), + (".//li/a[@href='search.html']/em", 'Search Page'), # custom sidebar only for contents - ".//h4": 'Contents sidebar', - }, - 'bom.html': { - ".//title": " File with UTF-8 BOM", - }, - 'extensions.html': { - ".//a[@href='http://python.org/dev/']": "http://python.org/dev/", - ".//a[@href='http://bugs.python.org/issue1000']": "issue 1000", - ".//a[@href='http://bugs.python.org/issue1042']": "explicit caption", - }, - '_static/statictmpl.html': { - ".//project": 'Sphinx ', - }, + (".//h4", 'Contents sidebar'), + ], + 'bom.html': [ + (".//title", " File with UTF-8 BOM"), + ], + 'extensions.html': [ + (".//a[@href='http://python.org/dev/']", "http://python.org/dev/"), + (".//a[@href='http://bugs.python.org/issue1000']", "issue 1000"), + (".//a[@href='http://bugs.python.org/issue1042']", "explicit caption"), + ], + '_static/statictmpl.html': [ + (".//project", 'Sphinx '), + ], } if pygments: - HTML_XPATH['includes.html'].update({ - ".//pre/span[@class='s']": u'üöä', - ".//div[@class='inc-pyobj1 highlight-text']//pre": - r'^class Foo:\n pass\n\s*$', - ".//div[@class='inc-pyobj2 highlight-text']//pre": - r'^ def baz\(\):\n pass\n\s*$', - ".//div[@class='inc-lines highlight-text']//pre": - r'^class Foo:\n pass\nclass Bar:\n$', - ".//div[@class='inc-startend highlight-text']//pre": - ur'^foo = u"Including Unicode characters: üöä"\n$', - ".//div[@class='inc-preappend highlight-text']//pre": - r'(?m)^START CODE$', - ".//div[@class='inc-pyobj-dedent highlight-python']//span": - r'def', - ".//div[@class='inc-tab3 highlight-text']//pre": - r'-| |-', - ".//div[@class='inc-tab8 highlight-python']//pre": - r'-| |-', - }) - HTML_XPATH['subdir/includes.html'].update({ - ".//pre/span": 'line 1', - ".//pre/span": 'line 2', - }) + HTML_XPATH['includes.html'].extend([ + (".//pre/span[@class='s']", u'üöä'), + (".//div[@class='inc-pyobj1 highlight-text']//pre", + r'^class Foo:\n pass\n\s*$'), + (".//div[@class='inc-pyobj2 highlight-text']//pre", + r'^ def baz\(\):\n pass\n\s*$'), + (".//div[@class='inc-lines highlight-text']//pre", + r'^class Foo:\n pass\nclass Bar:\n$'), + (".//div[@class='inc-startend highlight-text']//pre", + ur'^foo = u"Including Unicode characters: üöä"\n$'), + (".//div[@class='inc-preappend highlight-text']//pre", + r'(?m)^START CODE$'), + (".//div[@class='inc-pyobj-dedent highlight-python']//span", + r'def'), + (".//div[@class='inc-tab3 highlight-text']//pre", + r'-| |-'), + (".//div[@class='inc-tab8 highlight-python']//pre", + r'-| |-'), + ]) + HTML_XPATH['subdir/includes.html'].extend([ + (".//pre/span", 'line 1'), + (".//pre/span", 'line 2'), + ]) class NslessParser(ET.XMLParser): """XMLParser that throws away namespaces in tag names.""" @@ -292,7 +292,7 @@ def test_html(app): parser = NslessParser() parser.entity.update(htmlentitydefs.entitydefs) etree = ET.parse(os.path.join(app.outdir, fname), parser) - for path, check in paths.iteritems(): + for path, check in paths: yield check_xpath, etree, fname, path, check check_static_entries(app.builder.outdir) -- cgit v1.2.1 From 5cef519052bb7339e7dfbe791d6736963ede1a7f Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 25 Jul 2010 14:50:47 +0200 Subject: Actually test the JSON builder. --- tests/test_build.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/test_build.py b/tests/test_build.py index f18ff175..d571febd 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -21,6 +21,10 @@ def teardown_module(): def test_pickle(app): app.builder.build_all() +@with_app(buildername='json') +def test_json(app): + app.builder.build_all() + @with_app(buildername='linkcheck') def test_linkcheck(app): app.builder.build_all() -- cgit v1.2.1 From 11affd4ae31e34b34d72e451cc375b47cf2c898b Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 27 Jul 2010 13:20:58 +0200 Subject: Further fix for intersphinx labels, add test cases for that. --- tests/test_intersphinx.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_intersphinx.py b/tests/test_intersphinx.py index 622243e6..8b6547e5 100644 --- a/tests/test_intersphinx.py +++ b/tests/test_intersphinx.py @@ -80,7 +80,10 @@ def test_read_inventory_v2(): def test_missing_reference(tempdir, app): inv_file = tempdir / 'inventory' write_file(inv_file, inventory_v2) - app.config.intersphinx_mapping = {'http://docs.python.org/': inv_file} + app.config.intersphinx_mapping = { + 'http://docs.python.org/': inv_file, + 'py3k': ('http://docs.python.org/py3k/', inv_file), + } app.config.intersphinx_cache_limit = 0 # load the inventory and check if it's done correctly @@ -91,7 +94,7 @@ def test_missing_reference(tempdir, app): ('foo', '2.0', 'http://docs.python.org/foo.html#module-module2', '-') # create fake nodes and check referencing - contnode = nodes.emphasis('foo') + contnode = nodes.emphasis('foo', 'foo') refnode = addnodes.pending_xref('') refnode['reftarget'] = 'module1.func' refnode['reftype'] = 'func' @@ -101,7 +104,7 @@ def test_missing_reference(tempdir, app): assert isinstance(rn, nodes.reference) assert rn['refuri'] == 'http://docs.python.org/sub/foo.html#module1.func' assert rn['reftitle'] == '(in foo v2.0)' - assert rn[0] is contnode + assert rn[0].astext() == 'module1.func' # create unresolvable nodes and check None return value refnode['reftype'] = 'foo' @@ -110,3 +113,27 @@ def test_missing_reference(tempdir, app): refnode['reftype'] = 'function' refnode['reftarget'] = 'foo.func' assert missing_reference(app, app.env, refnode, contnode) is None + + # check handling of prefixes + + # prefix given, target found: prefix is stripped + refnode['reftype'] = 'mod' + refnode['reftarget'] = 'py3k:module2' + rn = missing_reference(app, app.env, refnode, contnode) + assert rn[0].astext() == 'module2' + + # prefix given, target not found and nonexplicit title: prefix is stripped + refnode['reftarget'] = 'py3k:unknown' + refnode['refexplicit'] = False + contnode[0] = nodes.Text('py3k:unknown') + rn = missing_reference(app, app.env, refnode, contnode) + assert rn is None + assert contnode[0].astext() == 'unknown' + + # prefix given, target not found and explicit title: nothing is changed + refnode['reftarget'] = 'py3k:unknown' + refnode['refexplicit'] = True + contnode[0] = nodes.Text('py3k:unknown') + rn = missing_reference(app, app.env, refnode, contnode) + assert rn is None + assert contnode[0].astext() == 'py3k:unknown' -- cgit v1.2.1 From 946c657fdcb57c1f6f7117931957d480f6c95c9b Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 27 Jul 2010 17:52:57 +0200 Subject: This apparently fixes a failing test in Gentoo. --- tests/test_build_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index bafee243..41ebf055 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -37,7 +37,7 @@ ENV_WARNINGS = """\ http://www.python.org/logo.png %(root)s/includes.txt:\\d*: \\(WARNING/2\\) Encoding 'utf-8-sig' used for \ reading included file u'wrongenc.inc' seems to be wrong, try giving an \ -:encoding: option +:encoding: option\n? %(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png %(root)s/objects.txt:79: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ -- cgit v1.2.1 From b815c4d7b67107c1ddd5f14b6365fa01cc83b940 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 27 Jul 2010 19:07:51 +0200 Subject: Now that the expected warnings are regexes, diffing them with the actual output makes no sense anymore. --- tests/test_build_html.py | 5 ++--- tests/test_build_latex.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 41ebf055..5f4dea0f 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -11,7 +11,6 @@ import os import re -import difflib import htmlentitydefs from StringIO import StringIO @@ -285,8 +284,8 @@ def test_html(app): html_warnings_exp = HTML_WARNINGS % {'root': re.escape(app.srcdir)} assert re.match(html_warnings_exp + '$', html_warnings), \ 'Warnings don\'t match:\n' + \ - '\n'.join(difflib.ndiff(html_warnings_exp.splitlines(), - html_warnings.splitlines())) + '--- Expected (regex):\n' + html_warnings_exp + \ + '--- Got:\n' + html_warnings for fname, paths in HTML_XPATH.iteritems(): parser = NslessParser() diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 6a20746b..4405395a 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -12,7 +12,6 @@ import os import re import sys -import difflib from StringIO import StringIO from subprocess import Popen, PIPE @@ -42,8 +41,9 @@ def test_latex(app): latex_warnings_exp = LATEX_WARNINGS % {'root': app.srcdir} assert re.match(latex_warnings_exp + '$', latex_warnings), \ 'Warnings don\'t match:\n' + \ - '\n'.join(difflib.ndiff(latex_warnings_exp.splitlines(), - latex_warnings.splitlines())) + '--- Expected (regex):\n' + latex_warnings_exp + \ + '--- Got:\n' + latex_warnings + # file from latex_additional_files assert (app.outdir / 'svgimg.svg').isfile() -- cgit v1.2.1 From ffc0c1242226dffbf4db192a5f8aac0723e228fb Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 27 Jul 2010 19:19:29 +0200 Subject: Add some tests for docfields. --- tests/root/objects.txt | 5 +++++ tests/test_build_html.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/root/objects.txt b/tests/root/objects.txt index ca3d0eb7..334827de 100644 --- a/tests/root/objects.txt +++ b/tests/root/objects.txt @@ -43,6 +43,11 @@ Testing object descriptions .. class:: TimeInt + :param moo: |test| + :type moo: |test| + +.. |test| replace:: Moo + .. class:: Time(hour, minute, isdst) :param hour: The year. diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 5f4dea0f..4dee513a 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -36,9 +36,9 @@ ENV_WARNINGS = """\ http://www.python.org/logo.png %(root)s/includes.txt:\\d*: \\(WARNING/2\\) Encoding 'utf-8-sig' used for \ reading included file u'wrongenc.inc' seems to be wrong, try giving an \ -:encoding: option\n? +:encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png -%(root)s/objects.txt:79: WARNING: using old C markup; please migrate to \ +%(root)s/objects.txt:84: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ http://sphinx.pocoo.org/domains.html """ @@ -50,6 +50,16 @@ HTML_WARNINGS = ENV_WARNINGS + """\ %(root)s/markup.txt:: WARNING: invalid pair index entry u'keyword; ' """ +def tail_check(check): + rex = re.compile(check) + def checker(nodes): + for node in nodes: + if node.tail and rex.search(node.tail): + return True + assert False, '%r not found in tail of any nodes %s' % (check, nodes) + return checker + + HTML_XPATH = { 'images.html': [ (".//img[@src='_images/img.png']", ''), @@ -171,6 +181,10 @@ HTML_XPATH = { 'Testing various markup'), # custom sidebar (".//h4", 'Custom sidebar'), + # docfields + (".//td[@class='field-body']/ul/li/strong", '^moo$'), + (".//td[@class='field-body']/ul/li/strong", + tail_check(r'\(Moo\) .* Moo')), ], 'contents.html': [ (".//meta[@name='hc'][@content='hcval']", ''), -- cgit v1.2.1 From 5cd8ce60a545f81c3899e1c79072d050db55b644 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 19:49:06 +0200 Subject: Add some changes not picked up in the transplantation process. --- tests/test_build_html.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3ca2c757..0c59d9cc 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -51,6 +51,11 @@ HTML_WARNINGS = ENV_WARNINGS + """\ %(root)s/markup.txt:: WARNING: invalid pair index entry u'keyword; ' """ +if sys.version_info >= (3, 0): + ENV_WARNINGS = remove_unicode_literals(ENV_WARNINGS) + HTML_WARNINGS = remove_unicode_literals(HTML_WARNINGS) + + def tail_check(check): rex = re.compile(check) def checker(nodes): @@ -61,10 +66,6 @@ def tail_check(check): return checker -if sys.version_info >= (3, 0): - ENV_WARNINGS = remove_unicode_literals(ENV_WARNINGS) - HTML_WARNINGS = remove_unicode_literals(HTML_WARNINGS) - HTML_XPATH = { 'images.html': [ (".//img[@src='_images/img.png']", ''), -- cgit v1.2.1 From c7ece3cb418f04e1a5aae46b33989969e737be2f Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 20:24:35 +0200 Subject: Fix raw_input which is not converted by 2to3 if not called. --- tests/test_quickstart.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 72ae764d..541959bd 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -36,8 +36,13 @@ def mock_raw_input(answers, needanswer=False): return '' return raw_input +try: + real_raw_input = raw_input +except NameError: + real_raw_input = input + def teardown_module(): - qs.term_input = raw_input + qs.term_input = real_raw_input qs.TERM_ENCODING = getattr(sys.stdin, 'encoding', None) coloron() -- cgit v1.2.1 From a1706a0d3d654e605dda77b2649327bf7066dc02 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 31 Jul 2010 19:47:15 +0200 Subject: Improve support for automatic 2to3 conversion of config files. It now kicks in whenever the original file raises SyntaxErrors on compiling. --- tests/test_config.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test_config.py b/tests/test_config.py index ecf90f60..7fce4495 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -88,6 +88,12 @@ def test_errors_warnings(dir): write_file(dir / 'conf.py', u'project = \n', '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'\n\nproject = u"Jägermeister"\n', 'utf-8') + cfg = Config(dir, 'conf.py', {}, None) + cfg.init_values() + assert cfg.project == u'Jägermeister' + # test the warning for bytestrings with non-ascii content # bytestrings with non-ascii content are a syntax error in python3 so we # skip the test there -- cgit v1.2.1 From 24f8b6a705b2f93e03094a2d03e5386ae7ede85b Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 Aug 2010 11:58:43 +0200 Subject: #480: Fix handling of target naming in intersphinx. --- tests/test_intersphinx.py | 60 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/test_intersphinx.py b/tests/test_intersphinx.py index 8b6547e5..3b50cc78 100644 --- a/tests/test_intersphinx.py +++ b/tests/test_intersphinx.py @@ -94,46 +94,58 @@ def test_missing_reference(tempdir, app): ('foo', '2.0', 'http://docs.python.org/foo.html#module-module2', '-') # create fake nodes and check referencing - contnode = nodes.emphasis('foo', 'foo') - refnode = addnodes.pending_xref('') - refnode['reftarget'] = 'module1.func' - refnode['reftype'] = 'func' - refnode['refdomain'] = 'py' - rn = missing_reference(app, app.env, refnode, contnode) + def fake_node(domain, type, target, content, **attrs): + contnode = nodes.emphasis(content, content) + node = addnodes.pending_xref('') + node['reftarget'] = target + node['reftype'] = type + node['refdomain'] = domain + node.attributes.update(attrs) + node += contnode + return node, contnode + + def reference_check(*args, **kwds): + node, contnode = fake_node(*args, **kwds) + return missing_reference(app, app.env, node, contnode) + + # check resolution when a target is found + rn = reference_check('py', 'func', 'module1.func', 'foo') assert isinstance(rn, nodes.reference) assert rn['refuri'] == 'http://docs.python.org/sub/foo.html#module1.func' assert rn['reftitle'] == '(in foo v2.0)' - assert rn[0].astext() == 'module1.func' + assert rn[0].astext() == 'foo' # create unresolvable nodes and check None return value - refnode['reftype'] = 'foo' - assert missing_reference(app, app.env, refnode, contnode) is None - - refnode['reftype'] = 'function' - refnode['reftarget'] = 'foo.func' - assert missing_reference(app, app.env, refnode, contnode) is None + assert reference_check('py', 'foo', 'module1.func', 'foo') is None + assert reference_check('py', 'func', 'foo', 'foo') is None + assert reference_check('py', 'func', 'foo', 'foo') is None # check handling of prefixes # prefix given, target found: prefix is stripped - refnode['reftype'] = 'mod' - refnode['reftarget'] = 'py3k:module2' - rn = missing_reference(app, app.env, refnode, contnode) + rn = reference_check('py', 'mod', 'py3k:module2', 'py3k:module2') + assert rn[0].astext() == 'module2' + + # prefix given, but not in title: nothing stripped + rn = reference_check('py', 'mod', 'py3k:module2', 'module2') assert rn[0].astext() == 'module2' + # prefix given, but explicit: nothing stripped + rn = reference_check('py', 'mod', 'py3k:module2', 'py3k:module2', + refexplicit=True) + assert rn[0].astext() == 'py3k:module2' + # prefix given, target not found and nonexplicit title: prefix is stripped - refnode['reftarget'] = 'py3k:unknown' - refnode['refexplicit'] = False - contnode[0] = nodes.Text('py3k:unknown') - rn = missing_reference(app, app.env, refnode, contnode) + node, contnode = fake_node('py', 'mod', 'py3k:unknown', 'py3k:unknown', + refexplicit=False) + rn = missing_reference(app, app.env, node, contnode) assert rn is None assert contnode[0].astext() == 'unknown' # prefix given, target not found and explicit title: nothing is changed - refnode['reftarget'] = 'py3k:unknown' - refnode['refexplicit'] = True - contnode[0] = nodes.Text('py3k:unknown') - rn = missing_reference(app, app.env, refnode, contnode) + node, contnode = fake_node('py', 'mod', 'py3k:unknown', 'py3k:unknown', + refexplicit=True) + rn = missing_reference(app, app.env, node, contnode) assert rn is None assert contnode[0].astext() == 'py3k:unknown' -- cgit v1.2.1 From 50e8b6ac9e4bda6a1131fe34648259f0be807c0d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 Aug 2010 12:53:05 +0200 Subject: #484: Fix crash when duplicating a parameter in an info field list. Problem was that the :type: info nodes were inserted twice into the doctree, which led to inconsistencies when reference nodes were resolved. --- tests/root/objects.txt | 2 ++ tests/test_build_html.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/root/objects.txt b/tests/root/objects.txt index 334827de..d6b8bdf6 100644 --- a/tests/root/objects.txt +++ b/tests/root/objects.txt @@ -62,6 +62,8 @@ Testing object descriptions :ivar int hour: like *hour* :ivar minute: like *minute* :vartype minute: int + :param hour: Duplicate param. Should not lead to crashes. + :type hour: Duplicate type. C items diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 4dee513a..813c962f 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -38,7 +38,7 @@ http://www.python.org/logo.png reading included file u'wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png -%(root)s/objects.txt:84: WARNING: using old C markup; please migrate to \ +%(root)s/objects.txt:86: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ http://sphinx.pocoo.org/domains.html """ -- cgit v1.2.1 From ac9d5434eefe66b336f7cee5599f253aaea6b70f Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 Aug 2010 16:03:36 +0200 Subject: Allow breaking long signatures, continuing with backlash-escaped newlines. --- tests/root/objects.txt | 4 ++++ tests/test_build_html.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/root/objects.txt b/tests/root/objects.txt index d6b8bdf6..e62f6d96 100644 --- a/tests/root/objects.txt +++ b/tests/root/objects.txt @@ -41,6 +41,10 @@ Testing object descriptions .. function:: func_without_module2() -> annotation +.. object:: long(parameter, \ + list) + another one + .. class:: TimeInt :param moo: |test| diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 813c962f..6857d330 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -38,7 +38,7 @@ http://www.python.org/logo.png reading included file u'wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png -%(root)s/objects.txt:86: WARNING: using old C markup; please migrate to \ +%(root)s/objects.txt:\\d*: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ http://sphinx.pocoo.org/domains.html """ @@ -161,6 +161,8 @@ HTML_XPATH = { 'objects.html': [ (".//dt[@id='mod.Cls.meth1']", ''), (".//dt[@id='errmod.Error']", ''), + (".//dt/tt", r'long\(parameter,\s* list\)'), + (".//dt/tt", 'another one'), (".//a[@href='#mod.Cls'][@class='reference internal']", ''), (".//dl[@class='userdesc']", ''), (".//dt[@id='userdesc-myobj']", ''), -- cgit v1.2.1 From 5b3789fc4506d4bb05365ef8195cd1bbf2f1cae3 Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 10 Aug 2010 12:25:48 +0200 Subject: Initial version tracking implementation --- tests/root/contents.txt | 1 + tests/root/versioning/added.txt | 20 ++++++++ tests/root/versioning/deleted.txt | 12 +++++ tests/root/versioning/deleted_end.txt | 11 +++++ tests/root/versioning/index.txt | 11 +++++ tests/root/versioning/insert.txt | 18 +++++++ tests/root/versioning/modified.txt | 17 +++++++ tests/root/versioning/original.txt | 15 ++++++ tests/test_versioning.py | 88 +++++++++++++++++++++++++++++++++++ 9 files changed, 193 insertions(+) create mode 100644 tests/root/versioning/added.txt create mode 100644 tests/root/versioning/deleted.txt create mode 100644 tests/root/versioning/deleted_end.txt create mode 100644 tests/root/versioning/index.txt create mode 100644 tests/root/versioning/insert.txt create mode 100644 tests/root/versioning/modified.txt create mode 100644 tests/root/versioning/original.txt create mode 100644 tests/test_versioning.py (limited to 'tests') diff --git a/tests/root/contents.txt b/tests/root/contents.txt index e052e04b..280953b4 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -26,6 +26,7 @@ Contents: extensions doctest extensions + versioning/index Python diff --git a/tests/root/versioning/added.txt b/tests/root/versioning/added.txt new file mode 100644 index 00000000..22a70739 --- /dev/null +++ b/tests/root/versioning/added.txt @@ -0,0 +1,20 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. It's not really interesting, in fact it is *really* +boring. + +Anyway I need more than one paragraph, at least three for the original +document, I think, and another one for two different ones. + +So the previous paragraph was a bit short because I don't want to test this +only on long paragraphs, I hope it was short enough to cover most stuff. +Anyway I see this lacks ``some markup`` so I have to add a **little** bit. + +Woho another paragraph, if this test fails we really have a problem because +this means the algorithm itself fails and not the diffing algorithm which is +pretty much doomed anyway as it probably fails for some kind of language +respecting certain nodes anyway but we can't work around that anyway. diff --git a/tests/root/versioning/deleted.txt b/tests/root/versioning/deleted.txt new file mode 100644 index 00000000..a1a9c4c9 --- /dev/null +++ b/tests/root/versioning/deleted.txt @@ -0,0 +1,12 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. It's not really interesting, in fact it is *really* +boring. + +So the previous paragraph was a bit short because I don't want to test this +only on long paragraphs, I hope it was short enough to cover most stuff. +Anyway I see this lacks ``some markup`` so I have to add a **little** bit. diff --git a/tests/root/versioning/deleted_end.txt b/tests/root/versioning/deleted_end.txt new file mode 100644 index 00000000..f30e6300 --- /dev/null +++ b/tests/root/versioning/deleted_end.txt @@ -0,0 +1,11 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. It's not really interesting, in fact it is *really* +boring. + +Anyway I need more than one paragraph, at least three for the original +document, I think, and another one for two different ones. diff --git a/tests/root/versioning/index.txt b/tests/root/versioning/index.txt new file mode 100644 index 00000000..234e223f --- /dev/null +++ b/tests/root/versioning/index.txt @@ -0,0 +1,11 @@ +Versioning Stuff +================ + +.. toctree:: + + original + added + insert + deleted + deleted_end + modified diff --git a/tests/root/versioning/insert.txt b/tests/root/versioning/insert.txt new file mode 100644 index 00000000..1c157cc9 --- /dev/null +++ b/tests/root/versioning/insert.txt @@ -0,0 +1,18 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. It's not really interesting, in fact it is *really* +boring. + +So this paragraph is just something I inserted in this document to test if our +algorithm notices that this paragraph is not just a changed version. + +Anyway I need more than one paragraph, at least three for the original +document, I think, and another one for two different ones. + +So the previous paragraph was a bit short because I don't want to test this +only on long paragraphs, I hope it was short enough to cover most stuff. +Anyway I see this lacks ``some markup`` so I have to add a **little** bit. diff --git a/tests/root/versioning/modified.txt b/tests/root/versioning/modified.txt new file mode 100644 index 00000000..49cdad93 --- /dev/null +++ b/tests/root/versioning/modified.txt @@ -0,0 +1,17 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. Inserting something silly as a modification, btw. have +you seen the typo below?. It's not really interesting, in fact it is *really* +boring. + +Anyway I need more than one paragraph, at least three for the original +document, I think, and another one for two different ones. So this is a small +modification by adding something to this paragraph. + +So the previous paragraph was a bit short because I don't want to test this +only on long paragraphs, I hoep it was short enough to cover most stuff. +Anyway I see this lacks ``some markup`` so I have to add a **little** bit. diff --git a/tests/root/versioning/original.txt b/tests/root/versioning/original.txt new file mode 100644 index 00000000..b3fe0609 --- /dev/null +++ b/tests/root/versioning/original.txt @@ -0,0 +1,15 @@ +Versioning test text +==================== + +So the thing is I need some kind of text - not the lorem ipsum stuff, that +doesn't work out that well - to test :mod:`sphinx.versioning`. I couldn't find +a good text for that under public domain so I thought the easiest solution is +to write one by myself. It's not really interesting, in fact it is *really* +boring. + +Anyway I need more than one paragraph, at least three for the original +document, I think, and another one for two different ones. + +So the previous paragraph was a bit short because I don't want to test this +only on long paragraphs, I hope it was short enough to cover most stuff. +Anyway I see this lacks ``some markup`` so I have to add a **little** bit. diff --git a/tests/test_versioning.py b/tests/test_versioning.py new file mode 100644 index 00000000..19ef8904 --- /dev/null +++ b/tests/test_versioning.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +""" + test_versioning + ~~~~~~~~~~~~~~~ + + Test the versioning implementation. + + :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from util import * + +from docutils.statemachine import ViewList + +from sphinx.versioning import make_diff, add_uids, merge_doctrees + +def setup_module(): + global app, original, original_uids + app = TestApp() + app.builder.env.app = app + app.connect('doctree-resolved', on_doctree_resolved) + app.build() + original = doctrees['versioning/original'] + original_uids = [n.uid for n in add_uids(original, is_paragraph)] + +def teardown_module(): + app.cleanup() + +doctrees = {} + +def on_doctree_resolved(app, doctree, docname): + doctrees[docname] = doctree + +def test_make_diff(): + tests = [ + (('aaa', 'aaa'), (True, False, False)), + (('aaa', 'aab'), (False, True, False)), + (('aaa', 'abb'), (False, True, False)), + (('aaa', 'aba'), (False, True, False)), + (('aaa', 'baa'), (False, True, False)), + (('aaa', 'bbb'), (False, False, True)) + ] + for args, result in tests: + assert make_diff(*args) == result + +def is_paragraph(node): + return node.__class__.__name__ == 'paragraph' + +def test_add_uids(): + assert len(original_uids) == 3 + +def test_modified(): + modified = doctrees['versioning/modified'] + new_nodes = list(merge_doctrees(original, modified, is_paragraph)) + uids = [n.uid for n in modified.traverse(is_paragraph)] + assert not new_nodes + assert original_uids == uids + +def test_added(): + added = doctrees['versioning/added'] + new_nodes = list(merge_doctrees(original, added, is_paragraph)) + uids = [n.uid for n in added.traverse(is_paragraph)] + assert len(new_nodes) == 1 + assert original_uids == uids[:-1] + +def test_deleted(): + deleted = doctrees['versioning/deleted'] + new_nodes = list(merge_doctrees(original, deleted, is_paragraph)) + uids = [n.uid for n in deleted.traverse(is_paragraph)] + assert not new_nodes + assert original_uids[::2] == uids + +def test_deleted_end(): + deleted_end = doctrees['versioning/deleted_end'] + new_nodes = list(merge_doctrees(original, deleted_end, is_paragraph)) + uids = [n.uid for n in deleted_end.traverse(is_paragraph)] + assert not new_nodes + assert original_uids[:-1] == uids + +def test_insert(): + from nose import SkipTest + raise SkipTest('The algorithm does not work at the moment') + insert = doctrees['versioning/insert'] + new_nodes = list(merge_doctrees(original, insert, is_paragraph)) + uids = [n.uid for n in insert.traverse(is_paragraph)] + assert len(new_nodes) == 1 + assert original_uids[0] == uids[0] + assert original_uids[1:] == uids[2:] -- cgit v1.2.1 From 9ae387d9fdcb4bdaf1dd44217d0d8fdd9f965ede Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 10 Aug 2010 15:22:11 +0200 Subject: Fixed algorithm test_insert passes now and everything seems to be working fine --- tests/test_versioning.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 19ef8904..47c322bb 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -78,8 +78,6 @@ def test_deleted_end(): assert original_uids[:-1] == uids def test_insert(): - from nose import SkipTest - raise SkipTest('The algorithm does not work at the moment') insert = doctrees['versioning/insert'] new_nodes = list(merge_doctrees(original, insert, is_paragraph)) uids = [n.uid for n in insert.traverse(is_paragraph)] -- cgit v1.2.1 From 7dbd85c6aca4e84d3123b94733d8526ac58d61a4 Mon Sep 17 00:00:00 2001 From: DasIch Date: Tue, 10 Aug 2010 15:22:42 +0200 Subject: Delete remaining files in the _build directory --- tests/test_versioning.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 47c322bb..77306580 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -25,6 +25,7 @@ def setup_module(): def teardown_module(): app.cleanup() + (test_root / '_build').rmtree(True) doctrees = {} -- cgit v1.2.1 From 15360eb1bdd2102231027fef95627a36247bd507 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 10 Aug 2010 17:16:49 +0200 Subject: Fix test_config under 2.x. --- tests/test_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_config.py b/tests/test_config.py index 7fce4495..b5f88a6f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -89,7 +89,8 @@ def test_errors_warnings(dir): 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'\n\nproject = u"Jägermeister"\n', 'utf-8') + write_file(dir / 'conf.py', u'# -*- coding: utf-8\n\n' + u'project = u"Jägermeister"\n', 'utf-8') cfg = Config(dir, 'conf.py', {}, None) cfg.init_values() assert cfg.project == u'Jägermeister' -- cgit v1.2.1 From c0e116c026aebb10854d8e083e702f6290403116 Mon Sep 17 00:00:00 2001 From: DasIch Date: Sat, 14 Aug 2010 11:11:50 +0200 Subject: Added a test to make sure pickled doctrees still have their uids --- tests/test_versioning.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 77306580..54a48f4a 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -8,10 +8,14 @@ :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import pickle + from util import * from docutils.statemachine import ViewList +from docutils.parsers.rst.directives.html import MetaBody +from sphinx import addnodes from sphinx.versioning import make_diff, add_uids, merge_doctrees def setup_module(): @@ -50,6 +54,19 @@ def is_paragraph(node): def test_add_uids(): assert len(original_uids) == 3 +def test_picklablility(): + # we have to modify the doctree so we can pickle it + copy = original.copy() + copy.reporter = None + copy.transformer = None + copy.settings.warning_stream = None + copy.settings.env = None + copy.settings.record_dependencies = None + for metanode in copy.traverse(MetaBody.meta): + metanode.__class__ = addnodes.meta + loaded = pickle.loads(pickle.dumps(copy, pickle.HIGHEST_PROTOCOL)) + assert all(getattr(n, 'uid', False) for n in loaded.traverse(is_paragraph)) + def test_modified(): modified = doctrees['versioning/modified'] new_nodes = list(merge_doctrees(original, modified, is_paragraph)) -- cgit v1.2.1