Skip to content

Commit 106a5a3

Browse files
author
Matthias Koeppe
committed
sage.doctest.sources: Distinguish .pxd from .pyx in doctest basenames
1 parent 6ea1fe9 commit 106a5a3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/sage/doctest/sources.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ def get_basename(path):
8484
sage: from sage.doctest.sources import get_basename
8585
sage: from sage.env import SAGE_SRC
8686
sage: import os
87-
sage: get_basename(os.path.join(SAGE_SRC,'sage','doctest','sources.py'))
87+
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'doctest', 'sources.py'))
8888
'sage.doctest.sources'
89+
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'structure', 'element.pxd'))
90+
'sage.structure.element.pxd'
8991
"""
9092
if path is None:
9193
return None
@@ -111,10 +113,14 @@ def get_basename(path):
111113
# it goes.
112114
while is_package_or_sage_namespace_package_dir(root):
113115
root = os.path.dirname(root)
114-
fully_qualified_path = os.path.splitext(path[len(root) + 1:])[0]
116+
fully_qualified_path, ext = os.path.splitext(path[len(root) + 1:])
115117
if os.path.split(path)[1] == '__init__.py':
116118
fully_qualified_path = fully_qualified_path[:-9]
117-
return fully_qualified_path.replace(os.path.sep, '.')
119+
basename = fully_qualified_path.replace(os.path.sep, '.')
120+
if ext in ['.pxd', '.pxi']:
121+
# disambiguate from .pyx with the same basename
122+
basename += ext
123+
return basename
118124

119125

120126
class DocTestSource():

0 commit comments

Comments
 (0)