Skip to content

Commit

Permalink
Merge pull request #31 from NextThought/fix-tests
Browse files Browse the repository at this point in the history
Fix tests with sphinx >= 1.8 and resolve warnings
  • Loading branch information
jamadden committed Dec 22, 2018
2 parents 43d6d62 + 18c3db1 commit cc163d4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
38 changes: 16 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
language: python
sudo: false
git:
depth: 1
python:
- pypy-5.4.1
- 2.7
- 3.5
# Pylint is not supported on 3.6 yet. See
# https://github.com/PyCQA/pylint/issues/1113 et al.
env:
matrix:
- ENV=latest
- ENV=oldest
- 3.6
- pypy
- pypy3
matrix:
# Only run the oldest environment once
exclude:
- python: 3.6
env: ENV=oldest
- python: pypy-5.4.1
env: ENV=oldest
include:
- python: "3.7"
dist: xenial


before_install:
- python --version

install:
- pip install -U pip setuptools
- pip install -U coverage coveralls pylint
- pip install -U -e .[test]

script:
- pylint -r no src/sphinxcontrib
- coverage run setup.py test
Expand All @@ -27,14 +29,6 @@ after_success:
notifications:
email: false

before_install:
- python --version

install:
- pip install -U pip setuptools
- pip install -U coverage coveralls pylint
- if [[ $ENV == latest ]]; then pip install -U -e .[test]; fi
- if [[ $ENV == oldest ]]; then pip install Sphinx==1.3.5 && pip install -e .[test]; fi

cache: pip

Expand Down
13 changes: 11 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
0.12 (unreleased)
0.13 (unreleased)
=================

- Nothing changed yet.
- Drop support for Sphinx < 1.7.

- Fix tests on Sphinx >= 1.8.0.

- Restore error message into the document by default from failed
program runs on Sphinx >= 1.8.0b1.

- Fix deprecation warnings on Sphinx >= 1.8. Reported in `issue 29
<https://github.com/NextThought/sphinxcontrib-programoutput/issues/29>`_
by miili.


0.11 (2017-05-18)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read_version_number():
name='sphinxcontrib-programoutput',
version=read_version_number(),
url='https://sphinxcontrib-programoutput.readthedocs.org/',
download_url='https://pypi.python.org/pypi/sphinxcontrib-programoutput',
download_url='https://pypi.org/project/sphinxcontrib-programoutput/',
license='BSD',
author='Sebastian Wiesner',
author_email='lunaryorn@gmail.com',
Expand All @@ -69,6 +69,7 @@ def read_version_number():
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
'Topic :: Documentation',
Expand All @@ -80,7 +81,7 @@ def read_version_number():
namespace_packages=['sphinxcontrib'],
include_package_data=True,
install_requires=[
'Sphinx>=1.3.5',
'Sphinx>=1.7.0',
],
tests_require=tests_require,
extras_require={
Expand Down
16 changes: 13 additions & 3 deletions src/sphinxcontrib/programoutput/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
from docutils.parsers import rst
from docutils.parsers.rst.directives import flag, unchanged, nonnegative_int

from sphinx.util import logging as sphinx_logging

__version__ = '0.12.dev0'
__version__ = '0.13.dev0'

logger = sphinx_logging.getLogger('contrib.programoutput')

class program_output(nodes.Element):
pass
Expand Down Expand Up @@ -217,11 +219,18 @@ def run_programs(app, doctree):
except EnvironmentError as error:
error_message = 'Command {0} failed: {1}'.format(command, error)
error_node = doctree.reporter.error(error_message, base_node=node)
# Sphinx 1.8.0b1 started dropping all system_message nodes with a
# level less than 5 by default (or 2 if `keep_warnings` is set to true).
# This appears to be undocumented. Reporting failures is an important
# part of what this extension does, so we raise the default level.
error_node['level'] = 6
node.replace_self(error_node)
else:
if returncode != node['returncode']:
app.warn('Unexpected return code {0} from command {1}'.format(
returncode, command))
logger.warning(
'Unexpected return code %s from command %s',
returncode, command
)

# replace lines with ..., if ellipsis is specified
if 'strip_lines' in node:
Expand All @@ -240,6 +249,7 @@ def run_programs(app, doctree):
node.replace_self(new_node)



def init_cache(app):
"""
Initialize the cache for program output at
Expand Down
6 changes: 6 additions & 0 deletions src/sphinxcontrib/programoutput/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import tempfile

from docutils.parsers.rst import directives
from docutils.parsers.rst import roles
from sphinx.application import Sphinx

from functools import update_wrapper

# pylint:disable=no-self-use,protected-access,too-few-public-methods
# useless-object-inheritance is version specific
# pylint:disable=bad-option-value,useless-object-inheritance

class Lazy(object):

Expand Down Expand Up @@ -60,9 +63,12 @@ def setUp(self):
# sphinxcontrib.programoutput: directive u'program-output' is
# already registered, it will be overridden".
self.directives = directives._directives.copy()
# Likewise for 'eq'
self.roles = roles._roles.copy()

def tearDown(self):
directives._directives = self.directives
roles._roles = self.roles

@Lazy
def tmpdir(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sphinxcontrib/programoutput/tests/test_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_prompt_with_return_code(self):
def test_non_existing_executable(self):
# check that a proper error message appears in the document
message = self.doctree.next_node(system_message)
assert message
self.assertTrue(message)
srcfile = os.path.join(self.srcdir, 'content', 'doc.rst')
self.assertEqual(message['source'], srcfile)
self.assertEqual(message['line'], 5)
Expand All @@ -314,7 +314,7 @@ def test_non_existing_working_directory(self):
doctree = self.doctree
srcdir = self.srcdir
message = doctree.next_node(system_message)
assert message
self.assertTrue(message)
srcfile = os.path.join(srcdir, 'content', 'doc.rst')
self.assertEqual(message['source'], srcfile)
self.assertEqual(message['line'], 5)
Expand Down
4 changes: 2 additions & 2 deletions src/sphinxcontrib/programoutput/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class TestSetup(AppMixin,

def test_init_cache(self):
app = self.app
assert isinstance(app.env.programoutput_cache, ProgramOutputCache)
assert not app.env.programoutput_cache
self.assertIsInstance(app.env.programoutput_cache, ProgramOutputCache)
self.assertFalse(app.env.programoutput_cache)

def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py27,py27old,py36,pypy,doc
envlist=py27,py27old,py36,py37,pypy,doc

[testenv]
deps =
Expand All @@ -9,7 +9,7 @@ commands=

[testenv:py27old]
deps =
Sphinx == 1.3.5
Sphinx == 1.7.0

[testenv:doc]
deps =
Expand Down

0 comments on commit cc163d4

Please sign in to comment.