From cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 19:25:40 +0200 Subject: Adding upstream version 7.2.6. Signed-off-by: Daniel Baumann --- tests/test_build_text.py | 278 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 tests/test_build_text.py (limited to 'tests/test_build_text.py') diff --git a/tests/test_build_text.py b/tests/test_build_text.py new file mode 100644 index 0000000..4a53be3 --- /dev/null +++ b/tests/test_build_text.py @@ -0,0 +1,278 @@ +"""Test the build process with Text builder with the test root.""" + +import pytest +from docutils.utils import column_width + +from sphinx.writers.text import MAXWIDTH, Cell, Table + + +def with_text_app(*args, **kw): + default_kw = { + 'buildername': 'text', + 'testroot': 'build-text', + } + default_kw.update(kw) + return pytest.mark.sphinx(*args, **default_kw) + + +@with_text_app() +def test_maxwitdh_with_prefix(app, status, warning): + app.builder.build_update() + result = (app.outdir / 'maxwidth.txt').read_text(encoding='utf8') + + lines = result.splitlines() + line_widths = [column_width(line) for line in lines] + assert max(line_widths) < MAXWIDTH + assert lines[0].startswith('See also:') + assert lines[1].startswith('') + assert lines[2].startswith(' ham') + assert lines[3].startswith(' ham') + assert lines[4] == '' + assert lines[5].startswith('* ham') + assert lines[6].startswith(' ham') + assert lines[7] == '' + assert lines[8].startswith('* ham') + assert lines[9].startswith(' ham') + assert lines[10] == '' + assert lines[11].startswith('spam egg') + + +@with_text_app() +def test_lineblock(app, status, warning): + # regression test for #1109: need empty line after line block + app.builder.build_update() + result = (app.outdir / 'lineblock.txt').read_text(encoding='utf8') + expect = ( + "* one\n" + "\n" + " line-block 1\n" + " line-block 2\n" + "\n" + "followed paragraph.\n" + ) + assert result == expect + + +@with_text_app() +def test_nonascii_title_line(app, status, warning): + app.builder.build_update() + result = (app.outdir / 'nonascii_title.txt').read_text(encoding='utf8') + expect_underline = '*********' + result_underline = result.splitlines()[1].strip() + assert expect_underline == result_underline + + +@with_text_app() +def test_nonascii_table(app, status, warning): + app.builder.build_update() + result = (app.outdir / 'nonascii_table.txt').read_text(encoding='utf8') + lines = [line.strip() for line in result.splitlines() if line.strip()] + line_widths = [column_width(line) for line in lines] + assert len(set(line_widths)) == 1 # same widths + + +@with_text_app() +def test_nonascii_maxwidth(app, status, warning): + app.builder.build_update() + result = (app.outdir / 'nonascii_maxwidth.txt').read_text(encoding='utf8') + lines = [line.strip() for line in result.splitlines() if line.strip()] + line_widths = [column_width(line) for line in lines] + assert max(line_widths) < MAXWIDTH + + +def test_table_builder(): + table = Table([6, 6]) + table.add_cell(Cell("foo")) + table.add_cell(Cell("bar")) + table_str = str(table).split("\n") + assert table_str[0] == "+--------+--------+" + assert table_str[1] == "| foo | bar |" + assert table_str[2] == "+--------+--------+" + assert repr(table).count("