[Python-checkins] python/dist/src/Lib doctest.py,1.105,1.106
edloper at users.sourceforge.net
edloper at users.sourceforge.net
Sat Sep 18 22:27:06 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9940/dist/src/Lib
Modified Files:
doctest.py
Log Message:
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).
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- doctest.py 13 Sep 2004 14:53:27 -0000 1.105
+++ doctest.py 18 Sep 2004 20:27:04 -0000 1.106
@@ -2312,10 +2312,27 @@
)
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:
More information about the Python-checkins
mailing list