A class used to extract the DocTests that are relevant to a given object, from its docstring and the docstrings of its contained objects. Doctests can currently be extracted from the following object types: modules, functions, classes, methods, staticmethods, classmethods, and
| 836 | ###################################################################### |
| 837 | |
| 838 | class DocTestFinder: |
| 839 | """ |
| 840 | A class used to extract the DocTests that are relevant to a given |
| 841 | object, from its docstring and the docstrings of its contained |
| 842 | objects. Doctests can currently be extracted from the following |
| 843 | object types: modules, functions, classes, methods, staticmethods, |
| 844 | classmethods, and properties. |
| 845 | """ |
| 846 | |
| 847 | def __init__(self, verbose=False, parser=DocTestParser(), |
| 848 | recurse=True, exclude_empty=True): |
| 849 | """ |
| 850 | Create a new doctest finder. |
| 851 | |
| 852 | The optional argument `parser` specifies a class or |
| 853 | function that should be used to create new DocTest objects (or |
| 854 | objects that implement the same interface as DocTest). The |
| 855 | signature for this factory function should match the signature |
| 856 | of the DocTest constructor. |
| 857 | |
| 858 | If the optional argument `recurse` is false, then `find` will |
| 859 | only examine the given object, and not any contained objects. |
| 860 | |
| 861 | If the optional argument `exclude_empty` is false, then `find` |
| 862 | will include tests for objects with empty docstrings. |
| 863 | """ |
| 864 | self._parser = parser |
| 865 | self._verbose = verbose |
| 866 | self._recurse = recurse |
| 867 | self._exclude_empty = exclude_empty |
| 868 | |
| 869 | def find(self, obj, name=None, module=None, globs=None, extraglobs=None): |
| 870 | """ |
| 871 | Return a list of the DocTests that are defined by the given |
| 872 | object's docstring, or by any of its contained objects' |
| 873 | docstrings. |
| 874 | |
| 875 | The optional parameter `module` is the module that contains |
| 876 | the given object. If the module is not specified or is None, then |
| 877 | the test finder will attempt to automatically determine the |
| 878 | correct module. The object's module is used: |
| 879 | |
| 880 | - As a default namespace, if `globs` is not specified. |
| 881 | - To prevent the DocTestFinder from extracting DocTests |
| 882 | from objects that are imported from other modules. |
| 883 | - To find the name of the file containing the object. |
| 884 | - To help find the line number of the object within its |
| 885 | file. |
| 886 | |
| 887 | Contained objects whose module does not match `module` are ignored. |
| 888 | |
| 889 | If `module` is False, no attempt to find the module will be made. |
| 890 | This is obscure, of use mostly in tests: if `module` is False, or |
| 891 | is None but cannot be found automatically, then all objects are |
| 892 | considered to belong to the (non-existent) module, so all contained |
| 893 | objects will (recursively) be searched for doctests. |
| 894 | |
| 895 | The globals for each DocTest is formed by combining `globs` |
no outgoing calls
searching dependent graphs…