2013-02-05 08:57:26 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_build_text
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the build process with Text builder with the test root.
|
|
|
|
|
2017-03-22 06:21:12 -05:00
|
|
|
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
2013-02-05 08:57:26 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
2017-04-27 09:38:42 -05:00
|
|
|
import pytest
|
2013-02-05 08:57:26 -06:00
|
|
|
|
|
|
|
from docutils.utils import column_width
|
2013-02-06 21:34:51 -06:00
|
|
|
from sphinx.writers.text import MAXWIDTH
|
2013-02-05 08:57:26 -06:00
|
|
|
|
|
|
|
|
|
|
|
def with_text_app(*args, **kw):
|
|
|
|
default_kw = {
|
|
|
|
'buildername': 'text',
|
2014-09-21 10:17:02 -05:00
|
|
|
'testroot': 'build-text',
|
2013-02-05 08:57:26 -06:00
|
|
|
}
|
|
|
|
default_kw.update(kw)
|
2017-04-27 09:38:42 -05:00
|
|
|
return pytest.mark.sphinx(*args, **default_kw)
|
2013-02-05 08:57:26 -06:00
|
|
|
|
|
|
|
|
2013-03-09 07:58:47 -06:00
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_maxwitdh_with_prefix(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'maxwidth.txt').text(encoding='utf-8')
|
2013-03-09 07:58:47 -06:00
|
|
|
|
|
|
|
lines = result.splitlines()
|
|
|
|
line_widths = [column_width(line) for line in lines]
|
|
|
|
assert max(line_widths) < MAXWIDTH
|
|
|
|
assert lines[0].startswith('See also: ham')
|
|
|
|
assert lines[1].startswith(' ham')
|
|
|
|
assert lines[2] == ''
|
|
|
|
assert lines[3].startswith('* ham')
|
|
|
|
assert lines[4].startswith(' ham')
|
|
|
|
assert lines[5] == ''
|
|
|
|
assert lines[6].startswith('* ham')
|
|
|
|
assert lines[7].startswith(' ham')
|
|
|
|
assert lines[8] == ''
|
|
|
|
assert lines[9].startswith('spam egg')
|
|
|
|
|
|
|
|
|
2013-03-09 08:14:31 -06:00
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_lineblock(app, status, warning):
|
2013-03-09 08:14:31 -06:00
|
|
|
# regression test for #1109: need empty line after line block
|
2014-09-21 10:17:02 -05:00
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'lineblock.txt').text(encoding='utf-8')
|
2013-03-09 08:14:31 -06:00
|
|
|
expect = (
|
2014-09-21 10:17:02 -05:00
|
|
|
u"* one\n"
|
|
|
|
u"\n"
|
|
|
|
u" line-block 1\n"
|
|
|
|
u" line-block 2\n"
|
|
|
|
u"\n"
|
|
|
|
u"followed paragraph.\n"
|
|
|
|
)
|
2013-03-09 08:14:31 -06:00
|
|
|
assert result == expect
|
|
|
|
|
|
|
|
|
2013-02-05 08:57:26 -06:00
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_nonascii_title_line(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'nonascii_title.txt').text(encoding='utf-8')
|
|
|
|
expect_underline = '******'
|
2016-08-19 09:46:54 -05:00
|
|
|
result_underline = result.splitlines()[1].strip()
|
2013-02-05 08:57:26 -06:00
|
|
|
assert expect_underline == result_underline
|
2013-02-05 09:29:59 -06:00
|
|
|
|
|
|
|
|
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_nonascii_table(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'nonascii_table.txt').text(encoding='utf-8')
|
2013-02-05 09:29:59 -06:00
|
|
|
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
|
2013-02-06 21:34:51 -06:00
|
|
|
|
|
|
|
|
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_nonascii_maxwidth(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'nonascii_maxwidth.txt').text(encoding='utf-8')
|
2013-02-06 21:34:51 -06:00
|
|
|
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
|
2014-08-26 06:52:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
@with_text_app()
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_table_with_empty_cell(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'table.txt').text(encoding='utf-8')
|
2014-08-26 06:52:02 -05:00
|
|
|
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
|
|
|
assert lines[0] == "+-------+-------+"
|
|
|
|
assert lines[1] == "| XXX | XXX |"
|
|
|
|
assert lines[2] == "+-------+-------+"
|
|
|
|
assert lines[3] == "| | XXX |"
|
|
|
|
assert lines[4] == "+-------+-------+"
|
|
|
|
assert lines[5] == "| XXX | |"
|
|
|
|
assert lines[6] == "+-------+-------+"
|
2015-03-30 05:54:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
@with_text_app()
|
|
|
|
def test_list_items_in_admonition(app, status, warning):
|
|
|
|
app.builder.build_update()
|
|
|
|
result = (app.outdir / 'listitems.txt').text(encoding='utf-8')
|
|
|
|
lines = [line.rstrip() for line in result.splitlines()]
|
|
|
|
assert lines[0] == "See also:"
|
|
|
|
assert lines[1] == ""
|
|
|
|
assert lines[2] == " * item 1"
|
|
|
|
assert lines[3] == ""
|
|
|
|
assert lines[4] == " * item 2"
|
2017-11-05 16:47:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
@with_text_app()
|
|
|
|
def test_secnums(app, status, warning):
|
|
|
|
app.builder.build_all()
|
2017-11-07 17:10:11 -06:00
|
|
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
|
|
|
expect = (
|
|
|
|
"* Section A\n"
|
|
|
|
"\n"
|
|
|
|
"* Section B\n"
|
|
|
|
"\n"
|
|
|
|
" * Sub Ba\n"
|
|
|
|
"\n"
|
|
|
|
" * Sub Bb\n"
|
|
|
|
"\n"
|
|
|
|
"* 日本語\n"
|
|
|
|
)
|
|
|
|
assert contents == expect
|
|
|
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
2017-11-05 16:47:57 -06:00
|
|
|
expect = (
|
|
|
|
"Section B\n"
|
|
|
|
"*********\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"Sub Ba\n"
|
|
|
|
"======\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"Sub Bb\n"
|
|
|
|
"======\n"
|
|
|
|
)
|
2017-11-07 17:10:11 -06:00
|
|
|
assert doc2 == expect
|
2017-11-05 16:47:57 -06:00
|
|
|
|
|
|
|
app.config.text_add_secnumbers = True
|
|
|
|
app.builder.build_all()
|
2017-11-07 17:10:11 -06:00
|
|
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
|
|
|
expect = (
|
|
|
|
"* 1. Section A\n"
|
|
|
|
"\n"
|
|
|
|
"* 2. Section B\n"
|
|
|
|
"\n"
|
|
|
|
" * 2.1. Sub Ba\n"
|
|
|
|
"\n"
|
|
|
|
" * 2.2. Sub Bb\n"
|
|
|
|
"\n"
|
|
|
|
"* 3. 日本語\n"
|
|
|
|
)
|
|
|
|
assert contents == expect
|
|
|
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
2017-11-05 16:47:57 -06:00
|
|
|
expect = (
|
|
|
|
"2. Section B\n"
|
|
|
|
"************\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"2.1. Sub Ba\n"
|
|
|
|
"===========\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"2.2. Sub Bb\n"
|
|
|
|
"===========\n"
|
|
|
|
)
|
2017-11-07 17:10:11 -06:00
|
|
|
assert doc2 == expect
|
2017-11-05 16:47:57 -06:00
|
|
|
|
|
|
|
app.config.text_secnumber_suffix = " "
|
|
|
|
app.builder.build_all()
|
2017-11-07 17:10:11 -06:00
|
|
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
|
|
|
expect = (
|
|
|
|
"* 1 Section A\n"
|
|
|
|
"\n"
|
|
|
|
"* 2 Section B\n"
|
|
|
|
"\n"
|
|
|
|
" * 2.1 Sub Ba\n"
|
|
|
|
"\n"
|
|
|
|
" * 2.2 Sub Bb\n"
|
|
|
|
"\n"
|
|
|
|
"* 3 日本語\n"
|
|
|
|
)
|
|
|
|
assert contents == expect
|
|
|
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
2017-11-05 16:47:57 -06:00
|
|
|
expect = (
|
|
|
|
"2 Section B\n"
|
|
|
|
"***********\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"2.1 Sub Ba\n"
|
|
|
|
"==========\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"2.2 Sub Bb\n"
|
|
|
|
"==========\n"
|
|
|
|
)
|
2017-11-07 17:10:11 -06:00
|
|
|
assert doc2 == expect
|
2017-11-05 16:47:57 -06:00
|
|
|
|