mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6230 from tk0miya/refactor_test_env_indexentries
refactor: test_environment_indexentries
This commit is contained in:
commit
3f8a336d3a
@ -8,135 +8,116 @@
|
|||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import namedtuple
|
import pytest
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from sphinx import locale
|
|
||||||
from sphinx.environment.adapters.indexentries import IndexEntries
|
from sphinx.environment.adapters.indexentries import IndexEntries
|
||||||
|
from sphinx.testing import restructuredtext
|
||||||
Environment = namedtuple('Environment', 'indexentries')
|
|
||||||
|
|
||||||
dummy_builder = mock.Mock()
|
|
||||||
dummy_builder.get_relative_uri.return_value = ''
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_single_index():
|
@pytest.mark.sphinx('dummy')
|
||||||
# type, value, tid, main, index_key
|
def test_create_single_index(app):
|
||||||
env = Environment({
|
app.env.indexentries.clear()
|
||||||
'index': [
|
text = (".. index:: docutils\n"
|
||||||
('single', 'docutils', 'id1', '', None),
|
".. index:: Python\n"
|
||||||
('single', 'Python', 'id2', '', None),
|
".. index:: pip; install\n"
|
||||||
('single', 'pip; install', 'id3', '', None),
|
".. index:: pip; upgrade\n"
|
||||||
('single', 'pip; upgrade', 'id4', '', None),
|
".. index:: Sphinx\n"
|
||||||
('single', 'Sphinx', 'id5', '', None),
|
".. index:: Ель\n"
|
||||||
('single', 'Ель', 'id6', '', None),
|
".. index:: ёлка\n"
|
||||||
('single', 'ёлка', 'id7', '', None),
|
".. index:: תירבע\n"
|
||||||
('single', 'תירבע', 'id8', '', None),
|
".. index:: 9-symbol\n"
|
||||||
('single', '9-symbol', 'id9', '', None),
|
".. index:: &-symbol\n")
|
||||||
('single', '&-symbol', 'id10', '', None),
|
restructuredtext.parse(app, text)
|
||||||
],
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
})
|
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
|
||||||
assert len(index) == 6
|
assert len(index) == 6
|
||||||
assert index[0] == ('Symbols', [('&-symbol', [[('', '#id10')], [], None]),
|
assert index[0] == ('Symbols', [('&-symbol', [[('', '#index-9')], [], None]),
|
||||||
('9-symbol', [[('', '#id9')], [], None])])
|
('9-symbol', [[('', '#index-8')], [], None])])
|
||||||
assert index[1] == ('D', [('docutils', [[('', '#id1')], [], None])])
|
assert index[1] == ('D', [('docutils', [[('', '#index-0')], [], None])])
|
||||||
assert index[2] == ('P', [('pip', [[], [('install', [('', '#id3')]),
|
assert index[2] == ('P', [('pip', [[], [('install', [('', '#index-2')]),
|
||||||
('upgrade', [('', '#id4')])], None]),
|
('upgrade', [('', '#index-3')])], None]),
|
||||||
('Python', [[('', '#id2')], [], None])])
|
('Python', [[('', '#index-1')], [], None])])
|
||||||
assert index[3] == ('S', [('Sphinx', [[('', '#id5')], [], None])])
|
assert index[3] == ('S', [('Sphinx', [[('', '#index-4')], [], None])])
|
||||||
assert index[4] == ('Е', [('ёлка', [[('', '#id7')], [], None]),
|
assert index[4] == ('Е', [('ёлка', [[('', '#index-6')], [], None]),
|
||||||
('Ель', [[('', '#id6')], [], None])])
|
('Ель', [[('', '#index-5')], [], None])])
|
||||||
assert index[5] == ('ת', [('תירבע', [[('', '#id8')], [], None])])
|
assert index[5] == ('ת', [('תירבע', [[('', '#index-7')], [], None])])
|
||||||
|
|
||||||
|
|
||||||
def test_create_pair_index():
|
@pytest.mark.sphinx('dummy')
|
||||||
# type, value, tid, main, index_key
|
def test_create_pair_index(app):
|
||||||
env = Environment({
|
app.env.indexentries.clear()
|
||||||
'index': [
|
text = (".. index:: pair: docutils; reStructuredText\n"
|
||||||
('pair', 'docutils; reStructuredText', 'id1', '', None),
|
".. index:: pair: Python; interpreter\n"
|
||||||
('pair', 'Python; interpreter', 'id2', '', None),
|
".. index:: pair: Sphinx; documentation tool\n")
|
||||||
('pair', 'Sphinx; documentation tool', 'id3', '', None),
|
restructuredtext.parse(app, text)
|
||||||
],
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
})
|
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
|
||||||
assert len(index) == 5
|
assert len(index) == 5
|
||||||
assert index[0] == ('D',
|
assert index[0] == ('D',
|
||||||
[('documentation tool', [[], [('Sphinx', [('', '#id3')])], None]),
|
[('documentation tool', [[], [('Sphinx', [('', '#index-2')])], None]),
|
||||||
('docutils', [[], [('reStructuredText', [('', '#id1')])], None])])
|
('docutils', [[], [('reStructuredText', [('', '#index-0')])], None])])
|
||||||
assert index[1] == ('I', [('interpreter', [[], [('Python', [('', '#id2')])], None])])
|
assert index[1] == ('I', [('interpreter', [[], [('Python', [('', '#index-1')])], None])])
|
||||||
assert index[2] == ('P', [('Python', [[], [('interpreter', [('', '#id2')])], None])])
|
assert index[2] == ('P', [('Python', [[], [('interpreter', [('', '#index-1')])], None])])
|
||||||
assert index[3] == ('R',
|
assert index[3] == ('R',
|
||||||
[('reStructuredText', [[], [('docutils', [('', '#id1')])], None])])
|
[('reStructuredText', [[], [('docutils', [('', '#index-0')])], None])])
|
||||||
assert index[4] == ('S',
|
assert index[4] == ('S',
|
||||||
[('Sphinx', [[], [('documentation tool', [('', '#id3')])], None])])
|
[('Sphinx', [[], [('documentation tool', [('', '#index-2')])], None])])
|
||||||
|
|
||||||
|
|
||||||
def test_create_triple_index():
|
@pytest.mark.sphinx('dummy')
|
||||||
# type, value, tid, main, index_key
|
def test_create_triple_index(app):
|
||||||
env = Environment({
|
app.env.indexentries.clear()
|
||||||
'index': [
|
text = (".. index:: triple: foo; bar; baz\n"
|
||||||
('triple', 'foo; bar; baz', 'id1', '', None),
|
".. index:: triple: Python; Sphinx; reST\n")
|
||||||
('triple', 'Python; Sphinx; reST', 'id2', '', None),
|
restructuredtext.parse(app, text)
|
||||||
],
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
})
|
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
|
||||||
assert len(index) == 5
|
assert len(index) == 5
|
||||||
assert index[0] == ('B', [('bar', [[], [('baz, foo', [('', '#id1')])], None]),
|
assert index[0] == ('B', [('bar', [[], [('baz, foo', [('', '#index-0')])], None]),
|
||||||
('baz', [[], [('foo bar', [('', '#id1')])], None])])
|
('baz', [[], [('foo bar', [('', '#index-0')])], None])])
|
||||||
assert index[1] == ('F', [('foo', [[], [('bar baz', [('', '#id1')])], None])])
|
assert index[1] == ('F', [('foo', [[], [('bar baz', [('', '#index-0')])], None])])
|
||||||
assert index[2] == ('P', [('Python', [[], [('Sphinx reST', [('', '#id2')])], None])])
|
assert index[2] == ('P', [('Python', [[], [('Sphinx reST', [('', '#index-1')])], None])])
|
||||||
assert index[3] == ('R', [('reST', [[], [('Python Sphinx', [('', '#id2')])], None])])
|
assert index[3] == ('R', [('reST', [[], [('Python Sphinx', [('', '#index-1')])], None])])
|
||||||
assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#id2')])], None])])
|
assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#index-1')])], None])])
|
||||||
|
|
||||||
|
|
||||||
def test_create_see_index():
|
@pytest.mark.sphinx('dummy')
|
||||||
locale.init([], None)
|
def test_create_see_index(app):
|
||||||
|
app.env.indexentries.clear()
|
||||||
# type, value, tid, main, index_key
|
text = (".. index:: see: docutils; reStructuredText\n"
|
||||||
env = Environment({
|
".. index:: see: Python; interpreter\n"
|
||||||
'index': [
|
".. index:: see: Sphinx; documentation tool\n")
|
||||||
('see', 'docutils; reStructuredText', 'id1', '', None),
|
restructuredtext.parse(app, text)
|
||||||
('see', 'Python; interpreter', 'id2', '', None),
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
('see', 'Sphinx; documentation tool', 'id3', '', None),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
|
||||||
assert len(index) == 3
|
assert len(index) == 3
|
||||||
assert index[0] == ('D', [('docutils', [[], [('see reStructuredText', [])], None])])
|
assert index[0] == ('D', [('docutils', [[], [('see reStructuredText', [])], None])])
|
||||||
assert index[1] == ('P', [('Python', [[], [('see interpreter', [])], None])])
|
assert index[1] == ('P', [('Python', [[], [('see interpreter', [])], None])])
|
||||||
assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])])
|
assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])])
|
||||||
|
|
||||||
|
|
||||||
def test_create_seealso_index():
|
@pytest.mark.sphinx('dummy')
|
||||||
locale.init([], None)
|
def test_create_seealso_index(app):
|
||||||
|
app.env.indexentries.clear()
|
||||||
# type, value, tid, main, index_key
|
text = (".. index:: seealso: docutils; reStructuredText\n"
|
||||||
env = Environment({
|
".. index:: seealso: Python; interpreter\n"
|
||||||
'index': [
|
".. index:: seealso: Sphinx; documentation tool\n")
|
||||||
('seealso', 'docutils; reStructuredText', 'id1', '', None),
|
restructuredtext.parse(app, text)
|
||||||
('seealso', 'Python; interpreter', 'id2', '', None),
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
('seealso', 'Sphinx; documentation tool', 'id3', '', None),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
|
||||||
assert len(index) == 3
|
assert len(index) == 3
|
||||||
assert index[0] == ('D', [('docutils', [[], [('see also reStructuredText', [])], None])])
|
assert index[0] == ('D', [('docutils', [[], [('see also reStructuredText', [])], None])])
|
||||||
assert index[1] == ('P', [('Python', [[], [('see also interpreter', [])], None])])
|
assert index[1] == ('P', [('Python', [[], [('see also interpreter', [])], None])])
|
||||||
assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
|
assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
|
||||||
|
|
||||||
|
|
||||||
def test_create_index_by_key():
|
@pytest.mark.sphinx('dummy')
|
||||||
# type, value, tid, main, index_key
|
def test_create_index_by_key(app):
|
||||||
env = Environment({
|
app.env.indexentries.clear()
|
||||||
'index': [
|
# At present, only glossary directive is able to create index key
|
||||||
('single', 'docutils', 'id1', '', None),
|
text = (".. glossary::\n"
|
||||||
('single', 'Python', 'id2', '', None),
|
"\n"
|
||||||
('single', 'スフィンクス', 'id3', '', 'ス'),
|
" docutils\n"
|
||||||
],
|
" Python\n"
|
||||||
})
|
" スフィンクス : ス\n")
|
||||||
index = IndexEntries(env).create_index(dummy_builder)
|
restructuredtext.parse(app, text)
|
||||||
|
index = IndexEntries(app.env).create_index(app.builder)
|
||||||
assert len(index) == 3
|
assert len(index) == 3
|
||||||
assert index[0] == ('D', [('docutils', [[('', '#id1')], [], None])])
|
assert index[0] == ('D', [('docutils', [[('main', '#term-docutils')], [], None])])
|
||||||
assert index[1] == ('P', [('Python', [[('', '#id2')], [], None])])
|
assert index[1] == ('P', [('Python', [[('main', '#term-python')], [], None])])
|
||||||
assert index[2] == ('ス', [('スフィンクス', [[('', '#id3')], [], 'ス'])])
|
assert index[2] == ('ス', [('スフィンクス', [[('main', '#term')], [], 'ス'])])
|
||||||
|
Loading…
Reference in New Issue
Block a user