summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-29 23:29:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-29 23:29:05 (GMT)
commitb1511f789ea0565296cf9c64f30d2ab4e79b8615 (patch)
tree296cdcf6b8050e1f4b576a38a33b72fe4e3e59f9 /Lib
parent6e722bc13fbe019195e6e760abfb6c9444124b14 (diff)
downloadcpython-b1511f789ea0565296cf9c64f30d2ab4e79b8615.zip
cpython-b1511f789ea0565296cf9c64f30d2ab4e79b8615.tar.gz
cpython-b1511f789ea0565296cf9c64f30d2ab4e79b8615.tar.bz2
doctest now supports packages
Issue #26641: doctest.DocFileTest and doctest.testfile() now support packages (module splitted into multiple directories) for the package parameter.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/doctest.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 38fdd80..5630220 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -381,12 +381,15 @@ class _OutputRedirectingPdb(pdb.Pdb):
sys.stdout = save_stdout
# [XX] Normalize with respect to os.path.pardir?
-def _module_relative_path(module, path):
+def _module_relative_path(module, test_path):
if not inspect.ismodule(module):
raise TypeError('Expected a module: %r' % module)
- if path.startswith('/'):
+ if test_path.startswith('/'):
raise ValueError('Module-relative files may not have absolute paths')
+ # Normalize the path. On Windows, replace "/" with "\".
+ test_path = os.path.join(*(test_path.split('/')))
+
# Find the base directory for the path.
if hasattr(module, '__file__'):
# A normal module/package
@@ -398,13 +401,19 @@ def _module_relative_path(module, path):
else:
basedir = os.curdir
else:
+ if hasattr(module, '__path__'):
+ for directory in module.__path__:
+ fullpath = os.path.join(directory, test_path)
+ if os.path.exists(fullpath):
+ return fullpath
+
# A module w/o __file__ (this includes builtins)
raise ValueError("Can't resolve paths relative to the module "
"%r (it has no __file__)"
% module.__name__)
- # Combine the base directory and the path.
- return os.path.join(basedir, *(path.split('/')))
+ # Combine the base directory and the test path.
+ return os.path.join(basedir, test_path)
######################################################################
## 2. Example & DocTest