diff options
author | Zachary Ware <zachary.ware@gmail.com> | 2013-11-24 07:19:09 (GMT) |
---|---|---|
committer | Zachary Ware <zachary.ware@gmail.com> | 2013-11-24 07:19:09 (GMT) |
commit | a4b7a7548c43d1d7f4fd52129aa32340ca15af6a (patch) | |
tree | 9993a71599cca9dcfbb51dc3286cbb5ab094b455 /Lib/doctest.py | |
parent | 091167c1ca513d74c7a146d6a527e7b8b07ae7e8 (diff) | |
download | cpython-a4b7a7548c43d1d7f4fd52129aa32340ca15af6a.zip cpython-a4b7a7548c43d1d7f4fd52129aa32340ca15af6a.tar.gz cpython-a4b7a7548c43d1d7f4fd52129aa32340ca15af6a.tar.bz2 |
Issue #3158: doctest can now find doctests in functions and methods
written in C.
As a part of this, a few doctests have been added to the builtins module
(on hex(), oct(), and bin()), a doctest has been fixed (hopefully on all
platforms) on float, and test_builtins now runs doctests in builtins.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 7836fd2..ee4e068 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -918,6 +918,8 @@ class DocTestFinder: return module is inspect.getmodule(object) elif inspect.isfunction(object): return module.__dict__ is object.__globals__ + elif inspect.ismethoddescriptor(object): + return module.__name__ == object.__objclass__.__module__ elif inspect.isclass(object): return module.__name__ == object.__module__ elif hasattr(object, '__module__'): @@ -950,7 +952,7 @@ class DocTestFinder: for valname, val in obj.__dict__.items(): valname = '%s.%s' % (name, valname) # Recurse to functions & classes. - if ((inspect.isfunction(val) or inspect.isclass(val)) and + if ((inspect.isroutine(val) or inspect.isclass(val)) and self._from_module(module, val)): self._find(tests, val, valname, module, source_lines, globs, seen) @@ -962,9 +964,8 @@ class DocTestFinder: raise ValueError("DocTestFinder.find: __test__ keys " "must be strings: %r" % (type(valname),)) - if not (inspect.isfunction(val) or inspect.isclass(val) or - inspect.ismethod(val) or inspect.ismodule(val) or - isinstance(val, str)): + if not (inspect.isroutine(val) or inspect.isclass(val) or + inspect.ismodule(val) or isinstance(val, str)): raise ValueError("DocTestFinder.find: __test__ values " "must be strings, functions, methods, " "classes, or modules: %r" % @@ -983,7 +984,7 @@ class DocTestFinder: val = getattr(obj, valname).__func__ # Recurse to methods, properties, and nested classes. - if ((inspect.isfunction(val) or inspect.isclass(val) or + if ((inspect.isroutine(val) or inspect.isclass(val) or isinstance(val, property)) and self._from_module(module, val)): valname = '%s.%s' % (name, valname) |