"
@@ -878,7 +878,7 @@ def test_template_args():
key='using')
-def test_initializers():
+def test_domain_cpp_ast_initializers():
idsMember = {1: 'v__T', 2: '1v'}
idsFunction = {1: 'f__T', 2: '1f1T'}
idsTemplate = {2: 'I_1TE1fv', 4: 'I_1TE1fvv'}
@@ -912,7 +912,7 @@ def test_initializers():
check('member', 'T v = T{}', idsMember)
-def test_attributes():
+def test_domain_cpp_ast_attributes():
# style: C++
check('member', '[[]] int f', {1: 'f__i', 2: '1f'})
check('member', '[ [ ] ] int f', {1: 'f__i', 2: '1f'},
@@ -960,7 +960,7 @@ def test_attributes():
check('function', 'void f() [[attr1]] [[attr2]]', {1: 'f', 2: '1fv'})
-def test_xref_parsing():
+def test_domain_cpp_ast_xref_parsing():
def check(target):
class Config:
cpp_id_attributes = ["id_attr"]
@@ -993,7 +993,7 @@ def filter_warnings(warning, file):
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
-def test_build_domain_cpp_multi_decl_lookup(app, status, warning):
+def test_domain_cpp_build_multi_decl_lookup(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "lookup-key-overload")
assert len(ws) == 0
@@ -1003,7 +1003,7 @@ def test_build_domain_cpp_multi_decl_lookup(app, status, warning):
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
-def test_build_domain_cpp_warn_template_param_qualified_name(app, status, warning):
+def test_domain_cpp_build_warn_template_param_qualified_name(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "warn-template-param-qualified-name")
assert len(ws) == 2
@@ -1012,14 +1012,14 @@ def test_build_domain_cpp_warn_template_param_qualified_name(app, status, warnin
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
-def test_build_domain_cpp_backslash_ok_true(app, status, warning):
+def test_domain_cpp_build_backslash_ok_true(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "backslash")
assert len(ws) == 0
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
-def test_build_domain_cpp_semicolon(app, status, warning):
+def test_domain_cpp_build_semicolon(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "semicolon")
assert len(ws) == 0
@@ -1027,7 +1027,7 @@ def test_build_domain_cpp_semicolon(app, status, warning):
@pytest.mark.sphinx(testroot='domain-cpp',
confoverrides={'nitpicky': True, 'strip_signature_backslash': True})
-def test_build_domain_cpp_backslash_ok_false(app, status, warning):
+def test_domain_cpp_build_backslash_ok_false(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "backslash")
assert len(ws) == 1
@@ -1035,7 +1035,7 @@ def test_build_domain_cpp_backslash_ok_false(app, status, warning):
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
-def test_build_domain_cpp_anon_dup_decl(app, status, warning):
+def test_domain_cpp_build_anon_dup_decl(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "anon-dup-decl")
assert len(ws) == 2
@@ -1044,7 +1044,7 @@ def test_build_domain_cpp_anon_dup_decl(app, status, warning):
@pytest.mark.sphinx(testroot='domain-cpp')
-def test_build_domain_cpp_misuse_of_roles(app, status, warning):
+def test_domain_cpp_build_misuse_of_roles(app, status, warning):
app.builder.build_all()
ws = filter_warnings(warning, "roles-targets-ok")
assert len(ws) == 0
@@ -1092,7 +1092,7 @@ def test_build_domain_cpp_misuse_of_roles(app, status, warning):
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': True})
-def test_build_domain_cpp_with_add_function_parentheses_is_True(app, status, warning):
+def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, warning):
app.builder.build_all()
def check(spec, text, file):
@@ -1133,7 +1133,7 @@ def test_build_domain_cpp_with_add_function_parentheses_is_True(app, status, war
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': False})
-def test_build_domain_cpp_with_add_function_parentheses_is_False(app, status, warning):
+def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, warning):
app.builder.build_all()
def check(spec, text, file):
@@ -1174,7 +1174,7 @@ def test_build_domain_cpp_with_add_function_parentheses_is_False(app, status, wa
@pytest.mark.sphinx(testroot='domain-cpp')
-def test_xref_consistency(app, status, warning):
+def test_domain_cpp_build_xref_consistency(app, status, warning):
app.builder.build_all()
test = 'xref_consistency.html'
@@ -1237,33 +1237,15 @@ not found in `{test}`
assert any_role.classes == texpr_role.content_classes['a'], expect
-def test_noindexentry(app):
- text = (".. cpp:function:: void f()\n"
- ".. cpp:function:: void g()\n"
- " :noindexentry:\n")
- doctree = restructuredtext.parse(app, text)
- assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
- assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C++ function)', '_CPPv41fv', '', None)])
- assert_node(doctree[2], addnodes.index, entries=[])
-
-
-def test_mix_decl_duplicate(app, warning):
- # Issue 8270
- text = (".. cpp:struct:: A\n"
- ".. cpp:function:: void A()\n"
- ".. cpp:struct:: A\n")
- restructuredtext.parse(app, text)
- ws = warning.getvalue().split("\n")
- assert len(ws) == 5
- assert "index.rst:2: WARNING: Duplicate C++ declaration, also defined at index:1." in ws[0]
- assert "Declaration is '.. cpp:function:: void A()'." in ws[1]
- assert "index.rst:3: WARNING: Duplicate C++ declaration, also defined at index:1." in ws[2]
- assert "Declaration is '.. cpp:struct:: A'." in ws[3]
- assert ws[4] == ""
+@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'nitpicky': True})
+def test_domain_cpp_build_field_role(app, status, warning):
+ app.builder.build_all()
+ ws = filter_warnings(warning, "field-role")
+ assert len(ws) == 0
@pytest.mark.sphinx(testroot='domain-cpp-intersphinx', confoverrides={'nitpicky': True})
-def test_intersphinx(tempdir, app, status, warning):
+def test_domain_cpp_build_intersphinx(tempdir, app, status, warning):
origSource = """\
.. cpp:class:: _class
.. cpp:struct:: _struct
@@ -1323,3 +1305,28 @@ _var cpp:member 1 index.html#_CPPv44$ -
app.builder.build_all()
ws = filter_warnings(warning, "index")
assert len(ws) == 0
+
+
+def test_domain_cpp_parse_noindexentry(app):
+ text = (".. cpp:function:: void f()\n"
+ ".. cpp:function:: void g()\n"
+ " :noindexentry:\n")
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
+ assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C++ function)', '_CPPv41fv', '', None)])
+ assert_node(doctree[2], addnodes.index, entries=[])
+
+
+def test_domain_cpp_parse_mix_decl_duplicate(app, warning):
+ # Issue 8270
+ text = (".. cpp:struct:: A\n"
+ ".. cpp:function:: void A()\n"
+ ".. cpp:struct:: A\n")
+ restructuredtext.parse(app, text)
+ ws = warning.getvalue().split("\n")
+ assert len(ws) == 5
+ assert "index.rst:2: WARNING: Duplicate C++ declaration, also defined at index:1." in ws[0]
+ assert "Declaration is '.. cpp:function:: void A()'." in ws[1]
+ assert "index.rst:3: WARNING: Duplicate C++ declaration, also defined at index:1." in ws[2]
+ assert "Declaration is '.. cpp:struct:: A'." in ws[3]
+ assert ws[4] == ""
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index 52ec0c2d4..2ee2d5f2d 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -477,23 +477,11 @@ def test_optional_pyfunction_signature(app):
def test_pyexception_signature(app):
- text = ".. py:exception:: exceptions.IOError"
- doctree = restructuredtext.parse(app, text)
- assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "exception "],
- [desc_addname, "exceptions."],
- [desc_name, "IOError"])],
- desc_content)]))
- assert_node(doctree[1], desc, desctype="exception",
- domain="py", objtype="exception", noindex=False)
-
-
-def test_exceptions_module_is_ignored(app):
- text = (".. py:exception:: IOError\n"
- " :module: exceptions\n")
+ text = ".. py:exception:: builtins.IOError"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
[desc, ([desc_signature, ([desc_annotation, "exception "],
+ [desc_addname, "builtins."],
[desc_name, "IOError"])],
desc_content)]))
assert_node(doctree[1], desc, desctype="exception",
@@ -1159,6 +1147,9 @@ def test_python_python_use_unqualified_type_names(app, status, warning):
assert (''
'Name' in content)
assert 'foo.Age' in content
+ assert ('name (Name) – blah blah
' in content)
+ assert 'age (foo.Age) – blah blah
' in content
@pytest.mark.sphinx('html', testroot='domain-py-python_use_unqualified_type_names',
@@ -1169,6 +1160,9 @@ def test_python_python_use_unqualified_type_names_disabled(app, status, warning)
assert (''
'foo.Name' in content)
assert 'foo.Age' in content
+ assert ('name (foo.Name) – blah blah
' in content)
+ assert 'age (foo.Age) – blah blah
' in content
@pytest.mark.sphinx('dummy', testroot='domain-py-xref-warning')
diff --git a/tests/test_ext_autodoc_autoattribute.py b/tests/test_ext_autodoc_autoattribute.py
index 5e7220234..20317b8da 100644
--- a/tests/test_ext_autodoc_autoattribute.py
+++ b/tests/test_ext_autodoc_autoattribute.py
@@ -100,6 +100,17 @@ def test_autoattribute_instance_variable_in_alias(app):
]
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autoattribute_instance_variable_without_comment(app):
+ actual = do_autodoc(app, 'attribute', 'target.instance_variable.Bar.attr4')
+ assert list(actual) == [
+ '',
+ '.. py:attribute:: Bar.attr4',
+ ' :module: target.instance_variable',
+ '',
+ ]
+
+
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autoattribute_slots_variable_list(app):
actual = do_autodoc(app, 'attribute', 'target.slots.Foo.attr')
diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py
index de4ad9236..2f805a87a 100644
--- a/tests/test_util_inspect.py
+++ b/tests/test_util_inspect.py
@@ -10,6 +10,7 @@
import ast
import datetime
+import enum
import functools
import sys
import types
@@ -516,6 +517,14 @@ def test_dict_customtype():
assert ": 2" in description
+def test_object_description_enum():
+ class MyEnum(enum.Enum):
+ FOO = 1
+ BAR = 2
+
+ assert inspect.object_description(MyEnum.FOO) == "MyEnum.FOO"
+
+
def test_getslots():
class Foo:
pass
diff --git a/utils/doclinter.py b/utils/doclinter.py
index f8df20bf7..6299fe46a 100644
--- a/utils/doclinter.py
+++ b/utils/doclinter.py
@@ -41,7 +41,7 @@ def lint(path: str) -> int:
pass
else:
spaces = LEADING_SPACES.match(line).group(1)
- if len(spaces) < code_block_depth:
+ if len(spaces) <= code_block_depth:
in_code_block = False
elif LONG_INTERPRETED_TEXT.match(line):
pass