diff options
author | Edward Loper <edloper@gradient.cis.upenn.edu> | 2004-09-18 20:27:04 +0000 |
---|---|---|
committer | Edward Loper <edloper@gradient.cis.upenn.edu> | 2004-09-18 20:27:04 +0000 |
commit | 0273f5b6b29486629f74f184da84172cb43fe221 (patch) | |
tree | e9e40f3848892fe671b6595e5cc7b486eae517af /Lib/doctest.py | |
parent | c9f53b4905c17deaee2ae9a2265602fccba123d4 (diff) | |
download | cpython-git-0273f5b6b29486629f74f184da84172cb43fe221.tar.gz |
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).
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index c1a87b3881..3414f4abce 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -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: |