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/test/test_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/test/test_doctest.py')
-rw-r--r-- | Lib/test/test_doctest.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index d4ff049..d99a16a 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -644,6 +644,35 @@ DocTestFinder finds the line number of each example: >>> test = doctest.DocTestFinder().find(f)[0] >>> [e.lineno for e in test.examples] [1, 9, 12] + +Finding Doctests in Modules Not Written in Python +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +DocTestFinder can also find doctests in most modules not written in Python. +We'll use builtins as an example, since it almost certainly isn't written in +plain ol' Python and is guaranteed to be available. + + >>> import builtins + >>> tests = doctest.DocTestFinder().find(builtins) + >>> len(tests) # how many objects checked for doctests + 794 + >>> real_tests = [t for t in tests if len(t.examples) > 0] + >>> len(real_tests) # how many objects actually have doctests + 8 + >>> for t in real_tests: + ... print('{} {}'.format(len(t.examples), t.name)) + ... + 1 builtins.bin + 3 builtins.float.as_integer_ratio + 2 builtins.float.fromhex + 2 builtins.float.hex + 1 builtins.hex + 1 builtins.int + 2 builtins.int.bit_length + 1 builtins.oct + +Note here that 'bin', 'oct', and 'hex' are functions; 'float.as_integer_ratio', +'float.hex', and 'int.bit_length' are methods; 'float.fromhex' is a classmethod, +and 'int' is a type. """ def test_DocTestParser(): r""" |