mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
doctest now supports packages
Issue #26641: doctest.DocFileTest and doctest.testfile() now support packages (module splitted into multiple directories) for the package parameter.
This commit is contained in:
parent
6e722bc13f
commit
b1511f789e
2 changed files with 17 additions and 4 deletions
|
@ -381,12 +381,15 @@ class _OutputRedirectingPdb(pdb.Pdb):
|
||||||
sys.stdout = save_stdout
|
sys.stdout = save_stdout
|
||||||
|
|
||||||
# [XX] Normalize with respect to os.path.pardir?
|
# [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):
|
if not inspect.ismodule(module):
|
||||||
raise TypeError('Expected a module: %r' % 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')
|
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.
|
# Find the base directory for the path.
|
||||||
if hasattr(module, '__file__'):
|
if hasattr(module, '__file__'):
|
||||||
# A normal module/package
|
# A normal module/package
|
||||||
|
@ -398,13 +401,19 @@ def _module_relative_path(module, path):
|
||||||
else:
|
else:
|
||||||
basedir = os.curdir
|
basedir = os.curdir
|
||||||
else:
|
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)
|
# A module w/o __file__ (this includes builtins)
|
||||||
raise ValueError("Can't resolve paths relative to the module "
|
raise ValueError("Can't resolve paths relative to the module "
|
||||||
"%r (it has no __file__)"
|
"%r (it has no __file__)"
|
||||||
% module.__name__)
|
% module.__name__)
|
||||||
|
|
||||||
# Combine the base directory and the path.
|
# Combine the base directory and the test path.
|
||||||
return os.path.join(basedir, *(path.split('/')))
|
return os.path.join(basedir, test_path)
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
## 2. Example & DocTest
|
## 2. Example & DocTest
|
||||||
|
|
|
@ -232,6 +232,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #26641: doctest.DocFileTest and doctest.testfile() now support
|
||||||
|
packages (module splitted into multiple directories) for the package
|
||||||
|
parameter.
|
||||||
|
|
||||||
- Issue #25195: Fix a regression in mock.MagicMock. _Call is a subclass of
|
- Issue #25195: Fix a regression in mock.MagicMock. _Call is a subclass of
|
||||||
tuple (changeset 3603bae63c13 only works for classes) so we need to
|
tuple (changeset 3603bae63c13 only works for classes) so we need to
|
||||||
implement __ne__ ourselves. Patch by Andrew Plummer.
|
implement __ne__ ourselves. Patch by Andrew Plummer.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue