2010-01-02 07:59:27 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_doctest
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the doctest extension.
|
|
|
|
|
2017-12-31 10:06:58 -06:00
|
|
|
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
2010-01-02 07:59:27 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2018-02-19 07:39:14 -06:00
|
|
|
from packaging.specifiers import InvalidSpecifier
|
|
|
|
from packaging.version import InvalidVersion
|
2018-02-07 06:28:01 -06:00
|
|
|
from six import PY2
|
2018-02-19 07:39:14 -06:00
|
|
|
|
2018-01-07 20:59:50 -06:00
|
|
|
from sphinx.ext.doctest import is_allowed_version
|
2013-04-01 04:39:32 -05:00
|
|
|
|
2011-01-03 14:20:29 -06:00
|
|
|
cleanup_called = 0
|
2010-01-02 07:59:27 -06:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-11-01 10:03:29 -05:00
|
|
|
@pytest.mark.sphinx('doctest', testroot='ext-doctest')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_build(app, status, warning):
|
2011-01-03 14:20:29 -06:00
|
|
|
global cleanup_called
|
|
|
|
cleanup_called = 0
|
2010-01-02 07:59:27 -06:00
|
|
|
app.builder.build_all()
|
|
|
|
if app.statuscode != 0:
|
2014-09-21 10:17:02 -05:00
|
|
|
assert False, 'failures in doctests:' + status.getvalue()
|
2011-01-03 14:20:29 -06:00
|
|
|
# in doctest.txt, there are two named groups and the default group,
|
|
|
|
# so the cleanup function must be called three times
|
|
|
|
assert cleanup_called == 3, 'testcleanup did not get executed enough times'
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2018-01-07 20:59:50 -06:00
|
|
|
def test_is_allowed_version():
|
|
|
|
assert is_allowed_version('<3.4', '3.3') is True
|
|
|
|
assert is_allowed_version('<3.4', '3.3') is True
|
|
|
|
assert is_allowed_version('<3.2', '3.3') is False
|
|
|
|
assert is_allowed_version('<=3.4', '3.3') is True
|
|
|
|
assert is_allowed_version('<=3.2', '3.3') is False
|
|
|
|
assert is_allowed_version('==3.3', '3.3') is True
|
|
|
|
assert is_allowed_version('==3.4', '3.3') is False
|
|
|
|
assert is_allowed_version('>=3.2', '3.3') is True
|
|
|
|
assert is_allowed_version('>=3.4', '3.3') is False
|
|
|
|
assert is_allowed_version('>3.2', '3.3') is True
|
|
|
|
assert is_allowed_version('>3.4', '3.3') is False
|
|
|
|
assert is_allowed_version('~=3.4', '3.4.5') is True
|
|
|
|
assert is_allowed_version('~=3.4', '3.5.0') is True
|
|
|
|
|
|
|
|
# invalid spec
|
|
|
|
with pytest.raises(InvalidSpecifier):
|
|
|
|
is_allowed_version('&3.4', '3.5')
|
|
|
|
|
|
|
|
# invalid version
|
|
|
|
with pytest.raises(InvalidVersion):
|
|
|
|
is_allowed_version('>3.4', 'Sphinx')
|
2017-01-14 11:57:19 -06:00
|
|
|
|
|
|
|
|
2011-01-03 14:20:29 -06:00
|
|
|
def cleanup_call():
|
|
|
|
global cleanup_called
|
|
|
|
cleanup_called += 1
|
2017-11-16 01:28:30 -06:00
|
|
|
|
|
|
|
|
2018-02-07 06:28:01 -06:00
|
|
|
@pytest.mark.xfail(
|
|
|
|
PY2, reason='node.source points to document instead of filename',
|
|
|
|
)
|
2017-11-16 01:28:30 -06:00
|
|
|
@pytest.mark.sphinx('doctest', testroot='ext-doctest-with-autodoc')
|
|
|
|
def test_reporting_with_autodoc(app, status, warning, capfd):
|
|
|
|
# Patch builder to get a copy of the output
|
|
|
|
written = []
|
|
|
|
app.builder._warn_out = written.append
|
|
|
|
app.builder.build_all()
|
|
|
|
lines = '\n'.join(written).split('\n')
|
|
|
|
failures = [l for l in lines if l.startswith('File')]
|
|
|
|
expected = [
|
|
|
|
'File "dir/inner.rst", line 1, in default',
|
2018-02-07 07:29:51 -06:00
|
|
|
'File "dir/bar.py", line ?, in default',
|
|
|
|
'File "foo.py", line ?, in default',
|
2017-11-16 01:28:30 -06:00
|
|
|
'File "index.rst", line 4, in default',
|
|
|
|
]
|
|
|
|
for location in expected:
|
|
|
|
assert location in failures
|