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-01-07 20:59:50 -06:00
|
|
|
from sphinx.ext.doctest import is_allowed_version
|
|
|
|
from packaging.version import InvalidVersion
|
|
|
|
from packaging.specifiers import InvalidSpecifier
|
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
|