Extract inner check functions in `test_domain_cpp` (#12336)

This commit is contained in:
Adam Turner 2024-04-29 02:07:56 +01:00 committed by GitHub
parent 172a2aa88e
commit 0d74c85e8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1046,19 +1046,21 @@ def test_domain_cpp_ast_attributes():
check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'}) check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'})
def check_ast_xref_parsing(target):
class Config:
cpp_id_attributes = ["id_attr"]
cpp_paren_attributes = ["paren_attr"]
parser = DefinitionParser(target, location='', config=Config())
parser.parse_xref_object()
parser.assert_end()
def test_domain_cpp_ast_xref_parsing(): def test_domain_cpp_ast_xref_parsing():
def check(target): check_ast_xref_parsing('f')
class Config: check_ast_xref_parsing('f()')
cpp_id_attributes = ["id_attr"] check_ast_xref_parsing('void f()')
cpp_paren_attributes = ["paren_attr"] check_ast_xref_parsing('T f()')
parser = DefinitionParser(target, location=None,
config=Config())
ast, isShorthand = parser.parse_xref_object()
parser.assert_end()
check('f')
check('f()')
check('void f()')
check('T f()')
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -1213,18 +1215,12 @@ def test_domain_cpp_build_misuse_of_roles(app, status, warning):
def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, warning): def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, warning):
app.build(force_all=True) app.build(force_all=True)
def check(spec, text, file):
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
res = re.search(pattern, text)
if not res:
print(f"Pattern\n\t{pattern}\nnot found in {file}")
raise AssertionError
rolePatterns = [ rolePatterns = [
('', 'Sphinx'), 'Sphinx',
('', 'Sphinx::version'), 'Sphinx::version',
('', 'version'), 'version',
('', 'List'), 'List',
('', 'MyEnum'), 'MyEnum',
] ]
parenPatterns = [ parenPatterns = [
('ref function without parens ', r'paren_1\(\)'), ('ref function without parens ', r'paren_1\(\)'),
@ -1237,35 +1233,33 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, war
('ref op call with parens, explicit title ', 'paren_8_title'), ('ref op call with parens, explicit title ', 'paren_8_title'),
] ]
f = 'roles.html' text = (app.outdir / 'roles.html').read_text(encoding='utf8')
t = (app.outdir / f).read_text(encoding='utf8') for ref_text in rolePatterns:
for s in rolePatterns: pattern = f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
check(s, t, f) match = re.search(pattern, text)
for s in parenPatterns: assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
check(s, t, f) for (desc_text, ref_text) in parenPatterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text)
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
f = 'any-role.html' text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
t = (app.outdir / f).read_text(encoding='utf8') for (desc_text, ref_text) in parenPatterns:
for s in parenPatterns: pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
check(s, t, f) match = re.search(pattern, text)
assert match is not None, f"Pattern not found in any-role.html:\n\t{pattern}"
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': False}) @pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': False})
def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, warning): def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, warning):
app.build(force_all=True) app.build(force_all=True)
def check(spec, text, file):
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
res = re.search(pattern, text)
if not res:
print(f"Pattern\n\t{pattern}\nnot found in {file}")
raise AssertionError
rolePatterns = [ rolePatterns = [
('', 'Sphinx'), 'Sphinx',
('', 'Sphinx::version'), 'Sphinx::version',
('', 'version'), 'version',
('', 'List'), 'List',
('', 'MyEnum'), 'MyEnum',
] ]
parenPatterns = [ parenPatterns = [
('ref function without parens ', 'paren_1'), ('ref function without parens ', 'paren_1'),
@ -1278,17 +1272,21 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, wa
('ref op call with parens, explicit title ', 'paren_8_title'), ('ref op call with parens, explicit title ', 'paren_8_title'),
] ]
f = 'roles.html' text = (app.outdir / 'roles.html').read_text(encoding='utf8')
t = (app.outdir / f).read_text(encoding='utf8') for ref_text in rolePatterns:
for s in rolePatterns: pattern = f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
check(s, t, f) match = re.search(pattern, text)
for s in parenPatterns: assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
check(s, t, f) for (desc_text, ref_text) in parenPatterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text)
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
f = 'any-role.html' text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
t = (app.outdir / f).read_text(encoding='utf8') for (desc_text, ref_text) in parenPatterns:
for s in parenPatterns: pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
check(s, t, f) match = re.search(pattern, text)
assert match is not None, f"Pattern not found in any-role.html:\n\t{pattern}"
@pytest.mark.sphinx(testroot='domain-cpp') @pytest.mark.sphinx(testroot='domain-cpp')