2010-01-02 07:59:27 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_doctest
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the doctest extension.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2010-01-02 07:59:27 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
2017-01-14 11:57:19 -06:00
|
|
|
import platform
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2017-01-14 11:57:19 -06:00
|
|
|
from sphinx.ext.doctest import TestDirective as _TestDirective
|
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-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('doctest', testroot='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
|
|
|
|
2017-01-14 11:57:19 -06:00
|
|
|
def test_pyversion(monkeypatch):
|
2017-01-15 03:27:34 -06:00
|
|
|
monkeypatch.setattr(platform, 'python_version', lambda: '3.3')
|
2017-01-14 11:57:19 -06:00
|
|
|
td = _TestDirective(*([None] * 9))
|
|
|
|
assert td.proper_pyversion('<', '3.4') is True
|
|
|
|
assert td.proper_pyversion('<', '3.2') is False
|
|
|
|
assert td.proper_pyversion('<=', '3.4') is True
|
|
|
|
assert td.proper_pyversion('<=', '3.3') is True
|
|
|
|
assert td.proper_pyversion('==', '3.3') is True
|
|
|
|
assert td.proper_pyversion('>=', '3.4') is False
|
|
|
|
assert td.proper_pyversion('>=', '3.2') is True
|
|
|
|
assert td.proper_pyversion('>', '3.4') is False
|
|
|
|
assert td.proper_pyversion('>', '3.2') is True
|
|
|
|
assert td.proper_pyversion('>', '3.3a0') is True
|
|
|
|
|
|
|
|
|
2011-01-03 14:20:29 -06:00
|
|
|
def cleanup_call():
|
|
|
|
global cleanup_called
|
|
|
|
cleanup_called += 1
|