mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
In DocFileTest:
- Fixed bug in handling of absolute paths. - If run from an interactive session, make paths relative to the directory containing sys.argv[0] (since __main__ doesn't have a __file__ attribute).
This commit is contained in:
parent
c9f53b4905
commit
0273f5b6b2
2 changed files with 46 additions and 6 deletions
|
@ -2312,10 +2312,27 @@ class DocFileCase(DocTestCase):
|
|||
)
|
||||
|
||||
def DocFileTest(path, package=None, globs=None, **options):
|
||||
package = _normalize_module(package)
|
||||
name = path.split('/')[-1]
|
||||
dir = os.path.split(package.__file__)[0]
|
||||
path = os.path.join(dir, *(path.split('/')))
|
||||
|
||||
# Interpret relative paths as relative to the given package's
|
||||
# directory (or the current module, if no package is specified).
|
||||
if not os.path.isabs(path):
|
||||
package = _normalize_module(package)
|
||||
if hasattr(package, '__file__'):
|
||||
# A normal package/module.
|
||||
dir = os.path.split(package.__file__)[0]
|
||||
path = os.path.join(dir, *(path.split('/')))
|
||||
elif package.__name__ == '__main__':
|
||||
# An interactive session.
|
||||
if sys.argv[0] != '':
|
||||
dir = os.path.split(sys.argv[0])[0]
|
||||
path = os.path.join(dir, *(path.split('/')))
|
||||
else:
|
||||
# A module w/o __file__ (this includes builtins)
|
||||
raise ValueError("Can't resolve paths relative to " +
|
||||
"the module %s (it has" % package +
|
||||
"no __file__)")
|
||||
|
||||
doc = open(path).read()
|
||||
|
||||
if globs is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue