sphinx-testing-0.8.1/0000755000076600000240000000000013376016734015317 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/.drone.io.sh0000644000076600000240000000044113376016041017434 0ustar tkomiyastaff00000000000000#!/bin/sh sudo add-apt-repository ppa:fkrull/deadsnakes sudo apt-get update sudo apt-get install python2.6 python2.6-dev python3.4 python3.4-dev pip install --use-mirrors --upgrade detox misspellings check-manifest docutils find src/ -name "*.py" | misspellings -f - detox check-manifest sphinx-testing-0.8.1/AUTHORS0000644000076600000240000000045413376016424016366 0ustar tkomiyastaff00000000000000sphinx-testing is written and maintained by Takeshi KOMIYA . There are also a few modules or functions incorporated from other authors and projects: * sphinx.testing.path and sphinx.testing.util was written by Sphinx-team, released under the BSD License (See Sphinx-AUTHORS) sphinx-testing-0.8.1/CHANGES.rst0000644000076600000240000000271613376016661017126 0ustar tkomiyastaff00000000000000Changelog ========== 0.8.1 (2018-11-24) ------------------- - Fix a bug: - #9: warningiserror=True is broken with Sphinx 1.8.2 0.8.0 (2018-11-13) ------------------- - Drop py33 support - Fix bug: - #8: Tests are failing with Sphinx 1.8.2 0.7.2 (2017-05-03) ------------------- - Fix bug: - #2: Fix cleanups for Sphinx 1.6 0.7.1 (2015-05-24) ------------------- - Fix bug: - Fix write_docstring should refer master_doc and source_suffix 0.7.0 (2015-03-21) ------------------- - PR#1 Enable verbosity and parallel arguments. 0.6.0 (2014-10-17) ------------------- - Add python 3.2 support (with Sphinx < 1.3) - Replace ListOutput with StringIO 0.5.2 (2014-10-16) ------------------- - Fix bug: - Fix srcdir and confdir are not abspath 0.5.1 (2014-10-15) ------------------- - Reimplement with_app decorator as class - Set copy_srcdir_to_tmpdir=True if write_docstring is specified 0.5.0 (2014-10-15) ------------------- - Add write_docstring option to with_app() 0.4.0 (2014-09-30) ------------------- - Add pathlib like accessors to path class: parent, name, suffix and stem - Fix bug: - #1 Fix exc assignment in with_app decorator. 0.3.0 (2014-09-27) ------------------- - Rename sphinx.testing package to sphinx_testing 0.2.0 (2014-09-24) ------------------- - Add path#utime() and path#listdir() - Change interface of @with_app: Give `status` and `warning` to decorated function as a argument 0.1.0 (2014-09-20) ------------------- - Initial release sphinx-testing-0.8.1/LICENSE0000644000076600000240000000262013376016424016320 0ustar tkomiyastaff00000000000000License for sphinx-testing ========================== Copyright (c) 2014 by Takeshi KOMIYA. Copyright (c) 2007-2014 by the Sphinx team (see Sphinx-AUTHORS file). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sphinx-testing-0.8.1/MANIFEST.in0000644000076600000240000000024713376016424017054 0ustar tkomiyastaff00000000000000include AUTHORS include CHANGES.rst include LICENSE include MANIFEST.in include Sphinx-AUTHORS include tox.ini include .drone.io.sh recursive-include tests *.py *.rst sphinx-testing-0.8.1/PKG-INFO0000644000076600000240000000247513376016734016424 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinx-testing Version: 0.8.1 Summary: testing utility classes and functions for Sphinx extensions Home-page: https://github.com/sphinx-doc/sphinx-testing Author: Takeshi Komiya Author-email: i.tkomiya@gmail.com License: UNKNOWN Description: testing utility classes and functions for Sphinx extensions Keywords: sphinx,testing Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Framework :: Sphinx :: Extension Classifier: Intended Audience :: Developers Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Topic :: Documentation Classifier: Topic :: Documentation :: Sphinx Classifier: Topic :: Software Development Classifier: Topic :: Software Development :: Documentation Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Text Processing :: Markup Classifier: Topic :: Utilities sphinx-testing-0.8.1/README.rst0000644000076600000240000000234613376016424017007 0ustar tkomiyastaff00000000000000============== sphinx-testing ============== `sphinx-testing` provides testing utility classes and functions for Sphinx extensions. .. image:: https://travis-ci.org/sphinx-doc/sphinx-testing.svg?branch=master :target: https://travis-ci.org/sphinx-doc/sphinx-testing .. image:: https://coveralls.io/repos/sphinx-doc/sphinx-testing/badge.png?branch=master :target: https://coveralls.io/r/sphinx-doc/sphinx-testing?branch=master .. image:: https://img.shields.io/pypi/dm/sphinx-testing.svg :target: https://pypi.python.org/pypi/sphinx-testing/ :alt: Number of PyPI downloads .. image:: https://img.shields.io/pypi/wheel/sphinx-testing.svg :target: https://pypi.python.org/pypi/sphinx-testing/ :alt: Wheel Status Setup ===== Use easy_install or pip:: $ sudo pip install sphinx-testing Usage ====== Example:: from sphinx_testing import with_app @with_app(buildername='html', srcdir='/path/to/examples', copy_srcdir_to_tmpdir=True) def test_sphinx_build(app, status, warning): app.build() html = (app.outdir / 'index.html').read_text() assert '

Hello world

' in html Requirements ============ * Python 2.6, 2.7, 3.4 or later * Sphinx 0.6 or later * six License ======= BSD License sphinx-testing-0.8.1/Sphinx-AUTHORS0000644000076600000240000000455213376016424017640 0ustar tkomiyastaff00000000000000Sphinx is written and maintained by Georg Brandl . Substantial parts of the templates were written by Armin Ronacher . Other co-maintainers: * Takayuki Shimizukawa * Daniel Neuhäuser <@DasIch> * Jon Waltman <@jonwaltman> * Rob Ruana <@RelentlessIdiot> * Robert Lehmann <@lehmannro> * Roland Meister <@rolmei> Other contributors, listed alphabetically, are: * Andi Albrecht -- agogo theme * Henrique Bastos -- SVG support for graphviz extension * Daniel Bültmann -- todo extension * Etienne Desautels -- apidoc module * Michael Droettboom -- inheritance_diagram extension * Charles Duffy -- original graphviz extension * Kevin Dunn -- MathJax extension * Josip Dzolonga -- coverage builder * Hernan Grecco -- search improvements * Horst Gutmann -- internationalization support * Martin Hans -- autodoc improvements * Doug Hellmann -- graphviz improvements * Dave Kuhlman -- original LaTeX writer * Blaise Laflamme -- pyramid theme * Thomas Lamb -- linkcheck builder * Łukasz Langa -- partial support for autodoc * Robert Lehmann -- gettext builder (GSOC project) * Dan MacKinlay -- metadata fixes * Martin Mahner -- nature theme * Will Maier -- directory HTML builder * Jacob Mason -- websupport library (GSOC project) * Roland Meister -- epub builder * Ezio Melotti -- collapsible sidebar JavaScript * Daniel Neuhäuser -- JavaScript domain, Python 3 support (GSOC) * Christopher Perkins -- autosummary integration * Benjamin Peterson -- unittests * T. Powers -- HTML output improvements * Rob Ruana -- napoleon extension * Stefan Seefeld -- toctree improvements * Shibukawa Yoshiki -- pluggable search API and Japanese search * Antonio Valentino -- qthelp builder * Pauli Virtanen -- autodoc improvements, autosummary extension * Stefan van der Walt -- autosummary extension * Thomas Waldmann -- apidoc module fixes * John Waltman -- Texinfo builder * Barry Warsaw -- setup command improvements * Sebastian Wiesner -- image handling, distutils support * Joel Wurtz -- cellspanning support in LaTeX Many thanks for all contributions! There are also a few modules or functions incorporated from other authors and projects: * sphinx.util.jsdump uses the basestring encoding from simplejson, written by Bob Ippolito, released under the MIT license * sphinx.util.stemmer was written by Vivake Gupta, placed in the Public Domain sphinx-testing-0.8.1/setup.cfg0000644000076600000240000000036413376016734017143 0ustar tkomiyastaff00000000000000[egg_info] tag_build = tag_date = 0 [build] build-base = _build [sdist] formats = gztar [wheel] universal = 1 [aliases] release = check -r -s register sdist bdist_wheel upload [check] strict = 1 restructuredtext = 1 [flake8] ignore = _ sphinx-testing-0.8.1/setup.py0000644000076600000240000000322713376016713017032 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- import sys from setuptools import setup, find_packages classifiers = [ "Development Status :: 4 - Beta", "Environment :: Console", "Environment :: Web Environment", "Framework :: Sphinx :: Extension", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Documentation", "Topic :: Documentation :: Sphinx", "Topic :: Software Development", "Topic :: Software Development :: Documentation", "Topic :: Software Development :: Testing", "Topic :: Text Processing :: Markup", "Topic :: Utilities", ] description = 'testing utility classes and functions for Sphinx extensions' test_require = [] if sys.version_info < (2, 7): test_require.append('unittest2') if sys.version_info < (3, 3): test_require.append('mock') setup( name='sphinx-testing', version='0.8.1', description=description, long_description=description, classifiers=classifiers, keywords=['sphinx', 'testing'], author='Takeshi Komiya', author_email='i.tkomiya@gmail.com', url='https://github.com/sphinx-doc/sphinx-testing', packages=find_packages('src'), package_dir={'': 'src'}, include_package_data=True, install_requires=[ 'Sphinx', 'six', ], tests_require=test_require, ) sphinx-testing-0.8.1/src/0000755000076600000240000000000013376016734016106 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/src/sphinx_testing/0000755000076600000240000000000013376016734021154 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/src/sphinx_testing/__init__.py0000644000076600000240000000055113376016424023262 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ Sphinx test suite utilities ~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2014 by Takeshi KOMIYA :license: BSD, see LICENSE for details. """ from sphinx_testing.tmpdir import mkdtemp, with_tmpdir # NOQA: import for exporting from sphinx_testing.util import TestApp, with_app # NOQA: import for exporting sphinx-testing-0.8.1/src/sphinx_testing/path.py0000644000076600000240000001306613376016424022464 0ustar tkomiyastaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """ path ~~~~ :copyright: Copyright 2007-2014 by the Sphinx team, see Sphinx-AUTHORS. :license: BSD, see LICENSE for details. """ import os import sys import shutil from codecs import open from six import PY2, text_type FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() class path(text_type): """ Represents a path which behaves like a string. """ if PY2: def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): if isinstance(s, str): s = s.decode(encoding, errors) return text_type.__new__(cls, s) return text_type.__new__(cls, s) @property def parent(self): return self.dirname() @property def name(self): return self.basename() @property def suffix(self): return os.path.splitext(self)[1] @property def stem(self): return os.path.splitext(self)[0] def basename(self): return os.path.basename(self) def dirname(self): 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): """ 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. """ shutil.copytree(self, destination, symlinks=symlinks) def move(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) def unlink(self): """ Removes a file. """ os.unlink(self) def utime(self, times): """ Set the access and modified times. """ os.utime(self, times) def listdir(self): return os.listdir(self) def write_text(self, text, **kwargs): """ Writes the given `text` to the file. """ f = open(self, 'w', **kwargs) try: f.write(text) finally: f.close() def read_text(self, **kwargs): """ Returns the text in the file. """ f = open(self, mode='U', **kwargs) try: return f.read() finally: f.close() def read_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. """ 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=0o777): """ 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 def __repr__(self): return '%s(%s)' % (self.__class__.__name__, text_type.__repr__(self)) sphinx-testing-0.8.1/src/sphinx_testing/tmpdir.py0000644000076600000240000000143213376016424023021 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ tmpdir utilities ~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2014 by Takeshi KOMIYA :license: BSD, see LICENSE for details. """ from functools import wraps from sphinx_testing.path import path def mkdtemp(suffix='', prefix='tmp', dir=None): import tempfile if isinstance(dir, path): tmpdir = tempfile.mkdtemp(suffix, prefix, str(dir)) else: tmpdir = tempfile.mkdtemp(suffix, prefix, dir) return path(tmpdir) def with_tmpdir(func): @wraps(func) def decorator(*args, **kwargs): try: tmpdir = mkdtemp() args = args + (tmpdir,) # extends argument; add tmpdir at tail return func(*args, **kwargs) finally: tmpdir.rmtree() return decorator sphinx-testing-0.8.1/src/sphinx_testing/util.py0000644000076600000240000001374313376016461022510 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ Sphinx test suite utilities ~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2014 by the Sphinx team, see Sphinx-AUTHORS. :license: BSD, see LICENSE for details. """ import os.path import shutil from six import StringIO from functools import wraps from textwrap import dedent import sphinx.application from sphinx import __version__ as sphinx_version from sphinx.application import Sphinx from sphinx_testing.path import path from sphinx_testing.tmpdir import mkdtemp try: from sphinx.util.docutils import docutils_namespace except ImportError: # workaround for Sphinx-1.4 and older versions from contextlib import contextmanager @contextmanager def docutils_namespace(): yield class TestApp(Sphinx): """ A subclass of :class:`Sphinx` that runs on the test root, with some better default values for the initialization parameters. """ def __init__(self, srcdir=None, confdir=None, outdir=None, doctreedir=None, buildername='html', confoverrides=None, status=None, warning=None, freshenv=False, warningiserror=False, tags=None, copy_srcdir_to_tmpdir=False, create_new_srcdir=False, cleanup_on_errors=True, verbosity=0, parallel=0): self.cleanup_trees = [] self.cleanup_on_errors = cleanup_on_errors if create_new_srcdir: assert srcdir is None, 'conflicted: create_new_srcdir, srcdir' tmpdir = mkdtemp() self.cleanup_trees.append(tmpdir) tmproot = tmpdir / 'root' tmproot.makedirs() (tmproot / 'conf.py').write_text('') srcdir = tmproot assert srcdir is not None, 'srcdir not found' srcdir = path(srcdir).abspath() if copy_srcdir_to_tmpdir: tmpdir = mkdtemp() self.cleanup_trees.append(tmpdir) tmproot = tmpdir / srcdir.basename() srcdir.copytree(tmproot) srcdir = tmproot self.builddir = srcdir.joinpath('_build') else: self.builddir = mkdtemp() self.cleanup_trees.append(self.builddir) if confdir is None: confdir = srcdir if outdir is None: outdir = self.builddir.joinpath(buildername) if not outdir.isdir(): outdir.makedirs() if doctreedir is None: doctreedir = self.builddir.joinpath('doctrees') if not doctreedir.isdir(): doctreedir.makedirs() if confoverrides is None: confoverrides = {} if status is None: status = StringIO() if warning is None: warning = StringIO() try: sphinx.application.abspath = lambda x: x if sphinx_version < '1.3': Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides, status, warning, freshenv, warningiserror, tags) else: Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides, status, warning, freshenv, warningiserror, tags, verbosity, parallel) finally: sphinx.application.abspath = os.path.abspath def __repr__(self): classname = self.__class__.__name__ return '<%s buildername=%r>' % (classname, self.builder.name) def cleanup(self, error=None): if error and self.cleanup_on_errors is False: return if sphinx_version < '1.6': from sphinx.theming import Theme Theme.themes.clear() from sphinx.ext.autodoc import AutoDirective AutoDirective._registry.clear() for tree in self.cleanup_trees: shutil.rmtree(tree, True) class with_app(object): """ Make a TestApp with args and kwargs, pass it to the test and clean up properly. """ def __init__(self, *sphinxargs, **sphinxkwargs): self.sphinxargs = sphinxargs self.sphinxkwargs = sphinxkwargs self._write_docstring = sphinxkwargs.pop('write_docstring', False) if self._write_docstring: self.sphinxkwargs['copy_srcdir_to_tmpdir'] = True def write_docstring(self, app, docstring): if self._write_docstring: if self._write_docstring is True: if isinstance(app.config.source_suffix, (list, tuple)): source_suffix = app.config.source_suffix[0] elif isinstance(app.config.source_suffix, dict): source_suffix = list(app.config.source_suffix)[0] else: source_suffix = app.config.source_suffix basename = '%s%s' % (app.config.master_doc, source_suffix) filename = app.srcdir / basename else: filename = app.srcdir / self._write_docstring filename.write_text(dedent(docstring), encoding='utf-8') def __call__(self, func): @wraps(func) def decorator(*args, **kwargs): app = None exc = None sphinxkwargs = dict(self.sphinxkwargs) # create copy with docutils_namespace(): try: status = sphinxkwargs.setdefault('status', StringIO()) warning = sphinxkwargs.setdefault('warning', StringIO()) app = TestApp(*self.sphinxargs, **sphinxkwargs) self.write_docstring(app, func.__doc__) func(*(args + (app, status, warning)), **kwargs) except Exception as _exc: exc = _exc raise finally: if app: if exc: app.cleanup(error=exc) else: app.cleanup() return decorator sphinx-testing-0.8.1/src/sphinx_testing.egg-info/0000755000076600000240000000000013376016734022646 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/src/sphinx_testing.egg-info/PKG-INFO0000644000076600000240000000247513376016733023752 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinx-testing Version: 0.8.1 Summary: testing utility classes and functions for Sphinx extensions Home-page: https://github.com/sphinx-doc/sphinx-testing Author: Takeshi Komiya Author-email: i.tkomiya@gmail.com License: UNKNOWN Description: testing utility classes and functions for Sphinx extensions Keywords: sphinx,testing Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Framework :: Sphinx :: Extension Classifier: Intended Audience :: Developers Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Topic :: Documentation Classifier: Topic :: Documentation :: Sphinx Classifier: Topic :: Software Development Classifier: Topic :: Software Development :: Documentation Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Text Processing :: Markup Classifier: Topic :: Utilities sphinx-testing-0.8.1/src/sphinx_testing.egg-info/SOURCES.txt0000644000076600000240000000102713376016733024531 0ustar tkomiyastaff00000000000000.drone.io.sh AUTHORS CHANGES.rst LICENSE MANIFEST.in README.rst Sphinx-AUTHORS setup.cfg setup.py tox.ini src/sphinx_testing/__init__.py src/sphinx_testing/path.py src/sphinx_testing/tmpdir.py src/sphinx_testing/util.py src/sphinx_testing.egg-info/PKG-INFO src/sphinx_testing.egg-info/SOURCES.txt src/sphinx_testing.egg-info/dependency_links.txt src/sphinx_testing.egg-info/requires.txt src/sphinx_testing.egg-info/top_level.txt tests/test_path.py tests/test_tmpdir.py tests/test_util.py tests/examples/conf.py tests/examples/index.rstsphinx-testing-0.8.1/src/sphinx_testing.egg-info/dependency_links.txt0000644000076600000240000000000113376016733026713 0ustar tkomiyastaff00000000000000 sphinx-testing-0.8.1/src/sphinx_testing.egg-info/requires.txt0000644000076600000240000000001313376016733025237 0ustar tkomiyastaff00000000000000Sphinx six sphinx-testing-0.8.1/src/sphinx_testing.egg-info/top_level.txt0000644000076600000240000000001713376016733025375 0ustar tkomiyastaff00000000000000sphinx_testing sphinx-testing-0.8.1/tests/0000755000076600000240000000000013376016734016461 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/tests/examples/0000755000076600000240000000000013376016734020277 5ustar tkomiyastaff00000000000000sphinx-testing-0.8.1/tests/examples/conf.py0000644000076600000240000000005613376016424021573 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- master_doc = 'index' sphinx-testing-0.8.1/tests/examples/index.rst0000644000076600000240000000007313376016424022134 0ustar tkomiyastaff00000000000000Example documentation ====================== Hello world! sphinx-testing-0.8.1/tests/test_path.py0000644000076600000240000002266713376016424021037 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- import os import sys import shutil from tempfile import mkdtemp from sphinx_testing import with_tmpdir from sphinx_testing.path import path if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest if sys.version_info < (3,): unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual class TestPath(unittest.TestCase): def test_instantiate(self): p = path('/path/to/file') self.assertIsInstance(p, path) self.assertEqual('/path/to/file', p) def test_suffix(self): p = path('/path/to/file.ext') self.assertEqual(".ext", p.suffix) self.assertEqual("/path/to/file", p.stem) def test_basename(self): p = path('/path/to/file') self.assertEqual("file", p.basename()) self.assertEqual("file", p.name) def test_dirname(self): p = path('/path/to/file') self.assertIsInstance(p.dirname(), path) self.assertEqual("/path/to", p.dirname()) self.assertEqual("/path/to", p.parent) self.assertEqual("/path", p.dirname().dirname()) self.assertEqual("/", p.dirname().dirname().dirname()) def test_abspath(self): p = path('.') self.assertIsInstance(p.abspath(), path) self.assertEqual(os.getcwd(), p.abspath()) def test_isabs(self): p = path('path/to/file') self.assertFalse(p.isabs()) p = path('/path/to/file') self.assertTrue(p.isabs()) def test_isdir(self): p = path(__file__) self.assertFalse(p.isdir()) # file self.assertTrue(p.dirname().isdir()) # directory p = path('/path/to/file') # not exists self.assertFalse(p.isdir()) def test_isfile(self): p = path(__file__) self.assertTrue(p.isfile()) # file self.assertFalse(p.dirname().isfile()) # directory p = path('/path/to/file') # not exists self.assertFalse(p.isfile()) def test_islink(self): try: tmpdir = mkdtemp() symlink = "%s/test.symlink" % tmpdir os.symlink(__file__, symlink) p = path(symlink) self.assertTrue(p.islink()) # symlink p = path(__file__) self.assertFalse(p.islink()) # file self.assertFalse(p.dirname().islink()) # directory p = path('/path/to/file') # not exists self.assertFalse(p.islink()) finally: shutil.rmtree(tmpdir) def test_ismount(self): pass # FIXME: to be test @with_tmpdir def test_rmtree(self, tmpdir): subdir = mkdtemp(dir=tmpdir) filename = "%s/entry.txt" % subdir open(filename, 'w').close() # create empty file path(subdir).rmtree() self.assertFalse(os.path.exists(filename)) self.assertFalse(os.path.exists(subdir)) with self.assertRaises(OSError): path('/path/to/file').rmtree() path('/path/to/file').rmtree(ignore_errors=True) # no exceptions # error handler result = [] def onerror(func, path, exc_info): result.append((func, path, exc_info)) path('/path/to/file').rmtree(onerror=onerror) self.assertNotEqual([], result) # errors are stacked @with_tmpdir def test_copytree(self, tmpdir): subdir = mkdtemp(dir=tmpdir) subsubdir = "%s/subdir" % subdir filename = "%s/test.file" % subdir symlink = "%s/test.symlink" % subdir os.makedirs(subsubdir) open(filename, 'w').close() # create empty file os.symlink(__file__, symlink) dstdir = os.path.join(tmpdir, "path/to/dstdir") path(subdir).copytree(dstdir) self.assertTrue(os.path.exists(subdir)) self.assertTrue(os.path.exists(dstdir)) self.assertTrue(os.path.isdir("%s/subdir" % dstdir)) self.assertTrue(os.path.isfile("%s/test.file" % dstdir)) self.assertTrue(os.path.isfile("%s/test.symlink" % dstdir)) self.assertFalse(os.path.islink("%s/test.symlink" % dstdir)) dstdir = os.path.join(tmpdir, "path/to/dstdir2") path(subdir).copytree(dstdir, symlinks=True) self.assertTrue(os.path.exists(subdir)) self.assertTrue(os.path.exists(dstdir)) self.assertTrue(os.path.isdir("%s/subdir" % dstdir)) self.assertTrue(os.path.isfile("%s/test.file" % dstdir)) self.assertTrue(os.path.isfile("%s/test.symlink" % dstdir)) self.assertTrue(os.path.islink("%s/test.symlink" % dstdir)) @with_tmpdir def test_move(self, tmpdir): subdir = mkdtemp(dir=tmpdir) subsubdir = "%s/subdir" % subdir filename = "%s/test.file" % subdir symlink = "%s/test.symlink" % subdir os.makedirs(subsubdir) open(filename, 'w').close() # create empty file os.symlink(__file__, symlink) # rename dstdir = os.path.join(tmpdir, "dstdir") path(subdir).move(dstdir) self.assertFalse(os.path.exists(subdir)) self.assertTrue(os.path.exists(dstdir)) self.assertTrue(os.path.isdir("%s/subdir" % dstdir)) self.assertTrue(os.path.isfile("%s/test.file" % dstdir)) self.assertTrue(os.path.islink("%s/test.symlink" % dstdir)) # move into the directory dstdir2 = mkdtemp(dir=tmpdir) dstsubdir = "%s/%s" % (dstdir2, os.path.basename(dstdir)) path(dstdir).move(dstdir2) self.assertFalse(os.path.exists(dstdir)) self.assertTrue(os.path.exists(dstdir2)) self.assertTrue(os.path.exists(dstsubdir)) @with_tmpdir def test_unlink(self, tmpdir): filename = "%s/test.file" % tmpdir symlink = "%s/test.symlink" % tmpdir open(filename, 'w').close() # create empty file os.symlink(__file__, symlink) path(filename).unlink() self.assertFalse(os.path.exists(filename)) path(symlink).unlink() self.assertFalse(os.path.exists(symlink)) @with_tmpdir def test_utime(self, tmpdir): filename = "%s/test.file" % tmpdir open(filename, 'w').close() # create empty file path(filename).utime((123, 456)) self.assertEqual(123, os.stat(filename).st_atime) self.assertEqual(456, os.stat(filename).st_mtime) @with_tmpdir def test_listdir(self, tmpdir): subdir = "%s/subdir" % tmpdir filename = "%s/test.file" % tmpdir symlink = "%s/test.symlink" % tmpdir os.makedirs(subdir) open(filename, 'w').close() # create empty file os.symlink(__file__, symlink) files = path(tmpdir).listdir() self.assertCountEqual(['subdir', 'test.file', 'test.symlink'], files) @with_tmpdir def test_write_text(self, tmpdir): filename = "%s/test.file" % tmpdir path(filename).write_text('hello world') text = open(filename).read() self.assertEqual('hello world', text) @with_tmpdir def test_read_text(self, tmpdir): filename = "%s/test.file" % tmpdir with open(filename, 'w') as fd: fd.write('hello world') self.assertEqual('hello world', path(filename).read_text()) @with_tmpdir def test_write_bytes(self, tmpdir): filename = "%s/test.file" % tmpdir path(filename).write_bytes(b'hello world') text = open(filename, 'rb').read() self.assertEqual(b'hello world', text) @with_tmpdir def test_read_bytes(self, tmpdir): filename = "%s/test.file" % tmpdir with open(filename, 'wb') as fd: fd.write(b'hello world') self.assertEqual(b'hello world', path(filename).read_bytes()) @with_tmpdir def test_exists(self, tmpdir): subdir = "%s/subdir" % tmpdir filename = "%s/test.file" % tmpdir symlink1 = "%s/test.symlink" % tmpdir symlink2 = "%s/test.symlink2" % tmpdir os.makedirs(subdir) open(filename, 'w').close() # create empty file os.symlink(__file__, symlink1) os.symlink('/path/to/file', symlink2) # path#exists() self.assertTrue(path(subdir).exists()) self.assertTrue(path(filename).exists()) self.assertTrue(path(symlink1).exists()) self.assertFalse(path(symlink2).exists()) self.assertFalse(path('/path/to/file').exists()) # path#lexists() self.assertTrue(path(subdir).lexists()) self.assertTrue(path(filename).lexists()) self.assertTrue(path(symlink1).lexists()) self.assertTrue(path(symlink2).lexists()) self.assertFalse(path('/path/to/file').lexists()) @with_tmpdir def test_makedirs(self, tmpdir): try: umask = os.umask(0o000) # reset umask at first subdir = "%s/path/to/subdir" % tmpdir path(subdir).makedirs() self.assertTrue(os.path.isdir(subdir)) self.assertEqual(0o777, os.stat(subdir).st_mode & 0o777) subdir = "%s/another/path/to/subdir" % tmpdir path(subdir).makedirs(0o700) self.assertTrue(os.path.isdir(subdir)) self.assertEqual(0o700, os.stat(subdir).st_mode & 0o777) finally: os.umask(umask) @with_tmpdir def test_jonpath(self, tmpdir): p = path('.') self.assertEqual('./path/to/file', p.joinpath('path/to/file')) self.assertEqual('/path/to/file', p.joinpath('/path/to/file')) self.assertEqual('./path/to/file', p / 'path/to/file') self.assertEqual('/path/to/file', p / '/path/to/file') sphinx-testing-0.8.1/tests/test_tmpdir.py0000644000076600000240000000301413376016424021363 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- import sys import shutil from sphinx_testing.path import path from sphinx_testing.tmpdir import mkdtemp, with_tmpdir if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest class TestTmpdir(unittest.TestCase): def test_mkdtemp(self): try: tmpdir = mkdtemp() self.assertIsInstance(tmpdir, path) finally: shutil.rmtree(tmpdir) # prefix option try: tmpdir = mkdtemp(prefix='sphinx') self.assertTrue(tmpdir.basename().startswith('sphinx')) finally: tmpdir.rmtree() # suffix option try: tmpdir = mkdtemp(suffix='sphinx') self.assertTrue(tmpdir.basename().endswith('sphinx')) finally: tmpdir.rmtree() # dir option try: parent = mkdtemp() tmpdir = mkdtemp(dir=parent) self.assertTrue(parent, tmpdir.dirname()) finally: parent.rmtree() def test_with_tmpdir(self): @with_tmpdir def testcase1(tmpdir): self.assertTrue(tmpdir.isdir()) return tmpdir tmpdir = testcase1() self.assertFalse(tmpdir.isdir()) @with_tmpdir def testcase2(tmpdir): self.assertTrue(tmpdir.isdir()) raise Exception(tmpdir) try: testcase2() except Exception as exc: tmpdir = exc.args[0] self.assertFalse(tmpdir.isdir()) sphinx-testing-0.8.1/tests/test_util.py0000644000076600000240000001611013376016424021042 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- import os import sys import sphinx from six import StringIO from sphinx_testing.path import path from sphinx_testing.tmpdir import mkdtemp from sphinx_testing.util import TestApp, with_app if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest if sys.version_info < (3,): unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual if sys.version_info < (3, 3): from mock import patch else: from unittest.mock import patch class TestSphinxTesting(unittest.TestCase): def test_TestApp(self): try: srcdir = path(__file__).dirname() / 'examples' app = TestApp(srcdir=srcdir) self.assertIsInstance(app._status, StringIO) self.assertIsInstance(app._warning, StringIO) if sphinx.__version__ < '1.0.0': app.build(True, None) else: app.build() self.assertIn('index.html', os.listdir(app.outdir)) finally: app.cleanup() def test_TestApp_when_srcdir_specified(self): try: srcdir = path(__file__).dirname() / 'examples' app = TestApp(srcdir=srcdir) self.assertEqual(srcdir, app.srcdir) self.assertNotEqual(app.srcdir, app.builddir.dirname()) self.assertTrue(app.builddir.isdir()) self.assertCountEqual(['conf.py', 'index.rst'], os.listdir(app.srcdir)) self.assertEqual((srcdir / 'conf.py').read_text(), (app.srcdir / 'conf.py').read_text()) self.assertEqual((srcdir / 'index.rst').read_text(), (app.srcdir / 'index.rst').read_text()) finally: app.cleanup() self.assertFalse(app.builddir.exists()) def test_TestApp_when_srcdir_is_None(self): with self.assertRaises(AssertionError): TestApp(srcdir=None) def test_TestApp_when_create_new_srcdir(self): try: app = TestApp(create_new_srcdir=True) self.assertIsNotNone(app.srcdir) self.assertEqual(['conf.py'], os.listdir(app.srcdir)) self.assertEqual('', (app.srcdir / 'conf.py').read_text()) finally: app.cleanup() def test_TestApp_when_srcdir_and_create_new_srcdir_conflict(self): with self.assertRaises(AssertionError): TestApp(srcdir='examples', create_new_srcdir=True) def test_TestApp_when_copy_srcdir_to_tmpdir(self): try: srcdir = path(__file__).dirname() / 'examples' app = TestApp(srcdir=srcdir, copy_srcdir_to_tmpdir=True) self.assertNotEqual(srcdir, app.srcdir) self.assertEqual(app.srcdir, app.builddir.dirname()) self.assertTrue(app.builddir.isdir()) self.assertCountEqual(['_build', 'conf.py', 'index.rst'], os.listdir(app.srcdir)) self.assertEqual((srcdir / 'conf.py').read_text(), (app.srcdir / 'conf.py').read_text()) self.assertEqual((srcdir / 'index.rst').read_text(), (app.srcdir / 'index.rst').read_text()) finally: app.cleanup() self.assertFalse(app.srcdir.exists()) self.assertFalse(app.builddir.exists()) def test_TestApp_cleanup(self): app = TestApp(create_new_srcdir=True) self.assertTrue(app.builddir.exists()) with patch("sphinx.ext.autodoc.AutoDirective") as AutoDirective: app.cleanup() self.assertEqual(1, AutoDirective._registry.clear.call_count) self.assertFalse(app.builddir.exists()) def test_TestApp_cleanup_when_cleanup_on_errors(self): app = TestApp(create_new_srcdir=True, cleanup_on_errors=False) self.assertTrue(app.builddir.exists()) with patch("sphinx.ext.autodoc.AutoDirective") as AutoDirective: app.cleanup(error=True) self.assertEqual(0, AutoDirective._registry.clear.call_count) self.assertTrue(app.builddir.exists()) with patch("sphinx.ext.autodoc.AutoDirective") as AutoDirective: app.cleanup(error=None) self.assertEqual(1, AutoDirective._registry.clear.call_count) self.assertFalse(app.builddir.exists()) def test_with_app(self): srcdir = path(__file__).dirname() / 'examples' builddir = [] @with_app(srcdir=srcdir, copy_srcdir_to_tmpdir=True) def execute(app, status, warning): (app.srcdir / 'unknown.rst').write_text('') builddir.append(app.builddir) # store to check outside of func if sphinx.__version__ < '1.0.0': app.build(True, None) else: app.build() self.assertIsInstance(status, StringIO) self.assertIsInstance(warning, StringIO) self.assertIn('index.html', os.listdir(app.outdir)) self.assertIn('Running Sphinx', status.getvalue()) self.assertIn("WARNING: document isn't included in any toctree", warning.getvalue()) execute() self.assertFalse(builddir[0].exists()) @patch("sphinx_testing.util.mkdtemp") def test_with_app_bad_args(self, _mkdtemp): tmpdir = _mkdtemp.return_value = mkdtemp() srcdir = path(__file__).dirname() / 'examples' @with_app(srcdir=srcdir, copy_srcdir_to_tmpdir=True) def execute(oops): pass with self.assertRaises(TypeError): # TypeError: execute() takes 1 positional argument but 3 were given execute() self.assertFalse(tmpdir.exists()) def test_with_app_write_docstring(self): @with_app(create_new_srcdir=True, write_docstring=True) def execute(app, status, warning): """ Hello world """ content = (app.srcdir / 'contents.rst').read_text() self.assertEqual('Hello world ', content) execute() def test_with_app_write_docstring_with_master_doc(self): @with_app(create_new_srcdir=True, write_docstring=True, confoverrides={'master_doc': 'index'}) def execute(app, status, warning): """ Hello world """ content = (app.srcdir / 'index.rst').read_text() self.assertEqual('Hello world ', content) execute() def test_with_app_write_docstring_with_source_suffix(self): @with_app(create_new_srcdir=True, write_docstring=True, confoverrides={'source_suffix': '.txt'}) def execute(app, status, warning): """ Hello world """ content = (app.srcdir / 'contents.txt').read_text() self.assertEqual('Hello world ', content) execute() def test_with_app_write_docstring_by_name(self): @with_app(create_new_srcdir=True, write_docstring='hello.rst') def execute(app, status, warning): """ Hello world """ content = (app.srcdir / 'hello.rst').read_text() self.assertEqual('Hello world ', content) execute() sphinx-testing-0.8.1/tox.ini0000644000076600000240000000201313376016424016622 0ustar tkomiyastaff00000000000000[tox] envlist=py26,py27,py34,sphinx06,sphinx10,sphinx11,sphinx12,sphinx13,sphinx14,sphinx15,sphinx16,sphinx17,sphinx18 [testenv] deps= nose mock flake8 passenv= TRAVIS* commands= nosetests flake8 setup.py src/ tests/ [testenv:py26] deps= {[testenv]deps} unittest2 Sphinx <= 1.4.9999 commands= nosetests [testenv:sphinx06] deps= {[testenv]deps} Sphinx <= 0.6.9999 [testenv:sphinx10] deps= {[testenv]deps} Sphinx <= 1.0.9999 [testenv:sphinx11] deps= {[testenv]deps} Sphinx <= 1.1.9999 [testenv:sphinx12] deps= {[testenv]deps} Sphinx <= 1.2.9999 [testenv:sphinx13] deps= {[testenv]deps} Sphinx <= 1.3.9999 [testenv:sphinx14] deps= {[testenv]deps} Sphinx <= 1.4.9999 [testenv:sphinx15] deps= {[testenv]deps} Sphinx <= 1.5.9999 [testenv:sphinx16] deps= {[testenv]deps} Sphinx <= 1.6.9999 [testenv:sphinx17] deps= {[testenv]deps} Sphinx <= 1.7.9999 [testenv:sphinx18] deps= {[testenv]deps} Sphinx <= 1.8.9999