Skip to content

Commit 3607ddf

Browse files
committed
TST: Refactor test_identify_names2
- split into two tests for implicit and explicit names - avoid repeated testing of first code_str (code_str and expected were extended and the complete code_str tested once more) - turn into parameterized test for better extensibility
1 parent 2c0f3bb commit 3607ddf

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

sphinx_gallery/tests/test_backreferences.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def test_identify_names(unicode_sample):
9999
assert expected == res
100100

101101

102-
def test_identify_names2(tmpdir):
103-
"""Test more name identification."""
102+
def test_identify_names_implicit(tmpdir):
103+
"""Test implicit name identification."""
104104
code_str = b"""
105105
'''
106106
Title
@@ -152,22 +152,22 @@ def test_identify_names2(tmpdir):
152152

153153
assert expected == res
154154

155-
code_str = b"""
156-
'''
157-
Title
158-
-----
159-
160-
This example uses :func:`k.l` and :meth:`~m.n`.
161-
'''
162-
""" + code_str.split(b"'''")[-1]
163-
expected['k.l'] = [{'module': 'k', 'module_short': 'k', 'name': 'l',
164-
'is_class': False, 'is_explicit': True}]
165-
expected['m.n'] = [{'module': 'm', 'module_short': 'm', 'name': 'n',
166-
'is_class': False, 'is_explicit': True}]
167155

168-
fname = tmpdir.join("identify_names.py")
169-
fname.write(code_str, 'wb')
170-
_, script_blocks = split_code_and_text_blocks(fname.strpath)
171-
res = sg.identify_names(script_blocks)
172-
173-
assert expected == res
156+
cobj = dict(module='m', module_short='m', name='n', is_class=False, is_explicit=True)
157+
@pytest.mark.parametrize(
158+
'text, ref, cobj',
159+
[
160+
(':func:`m.n`', 'm.n', cobj),
161+
(':func:`~m.n`', 'm.n', cobj),
162+
],
163+
ids=[
164+
'regular',
165+
'show only last component',
166+
],
167+
)
168+
def test_identify_names_explicit(text, ref, cobj):
169+
'''Test explicit name identification.'''
170+
script_blocks = [('text', text, 1)]
171+
expected = {ref: [cobj]}
172+
actual = sg.identify_names(script_blocks)
173+
assert expected == actual

0 commit comments

Comments
 (0)