summaryrefslogtreecommitdiffstats
path: root/tests/test_builders/test_build.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_builders/test_build.py (renamed from tests/test_build.py)38
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/test_build.py b/tests/test_builders/test_build.py
index ed4bc43..3f6d12c 100644
--- a/tests/test_build.py
+++ b/tests/test_builders/test_build.py
@@ -2,13 +2,17 @@
import os
import shutil
+from contextlib import contextmanager
from unittest import mock
import pytest
from docutils import nodes
+from sphinx.cmd.build import build_main
from sphinx.errors import SphinxError
+from tests.utils import TESTS_ROOT
+
def request_session_head(url, **kwargs):
response = mock.Mock()
@@ -60,12 +64,12 @@ def test_root_doc_not_found(tmp_path, make_app):
app = make_app('dummy', srcdir=tmp_path)
with pytest.raises(SphinxError):
- app.builder.build_all() # no index.rst
+ app.build(force_all=True) # no index.rst
@pytest.mark.sphinx(buildername='text', testroot='circular')
def test_circular_toctree(app, status, warning):
- app.builder.build_all()
+ app.build(force_all=True)
warnings = warning.getvalue()
assert (
'circular toctree references detected, ignoring: '
@@ -77,7 +81,7 @@ def test_circular_toctree(app, status, warning):
@pytest.mark.sphinx(buildername='text', testroot='numbered-circular')
def test_numbered_circular_toctree(app, status, warning):
- app.builder.build_all()
+ app.build(force_all=True)
warnings = warning.getvalue()
assert (
'circular toctree references detected, ignoring: '
@@ -89,7 +93,7 @@ def test_numbered_circular_toctree(app, status, warning):
@pytest.mark.sphinx(buildername='dummy', testroot='images')
def test_image_glob(app, status, warning):
- app.builder.build_all()
+ app.build(force_all=True)
# index.rst
doctree = app.env.get_doctree('index')
@@ -133,3 +137,29 @@ def test_image_glob(app, status, warning):
assert doctree[0][3][0]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'}
assert doctree[0][3][0]['uri'] == 'subdir/svgimg.*'
+
+
+@contextmanager
+def force_colors():
+ forcecolor = os.environ.get('FORCE_COLOR', None)
+
+ try:
+ os.environ['FORCE_COLOR'] = '1'
+ yield
+ finally:
+ if forcecolor is None:
+ os.environ.pop('FORCE_COLOR', None)
+ else:
+ os.environ['FORCE_COLOR'] = forcecolor
+
+
+def test_log_no_ansi_colors(tmp_path):
+ with force_colors():
+ wfile = tmp_path / 'warnings.txt'
+ srcdir = TESTS_ROOT / 'roots' / 'test-nitpicky-warnings'
+ argv = list(map(str, ['-b', 'html', srcdir, tmp_path, '-n', '-w', wfile]))
+ retcode = build_main(argv)
+ assert retcode == 0
+
+ content = wfile.read_text(encoding='utf8')
+ assert '\x1b[91m' not in content