| 84 | # Modified version of the one in the stdlib, that fixes a python bug (doctests |
| 85 | # not found in extension modules, http://bugs.python.org/issue3158) |
| 86 | class DocTestFinder(doctest.DocTestFinder): |
| 87 | |
| 88 | def _from_module(self, module, object): |
| 89 | """ |
| 90 | Return true if the given object is defined in the given |
| 91 | module. |
| 92 | """ |
| 93 | if module is None: |
| 94 | return True |
| 95 | elif inspect.isfunction(object): |
| 96 | return module.__dict__ is object.__globals__ |
| 97 | elif inspect.isbuiltin(object): |
| 98 | return module.__name__ == object.__module__ |
| 99 | elif inspect.isclass(object): |
| 100 | return module.__name__ == object.__module__ |
| 101 | elif inspect.ismethod(object): |
| 102 | # This one may be a bug in cython that fails to correctly set the |
| 103 | # __module__ attribute of methods, but since the same error is easy |
| 104 | # to make by extension code writers, having this safety in place |
| 105 | # isn't such a bad idea |
| 106 | return module.__name__ == object.__self__.__class__.__module__ |
| 107 | elif inspect.getmodule(object) is not None: |
| 108 | return module is inspect.getmodule(object) |
| 109 | elif hasattr(object, '__module__'): |
| 110 | return module.__name__ == object.__module__ |
| 111 | elif isinstance(object, property): |
| 112 | return True # [XX] no way not be sure. |
| 113 | elif inspect.ismethoddescriptor(object): |
| 114 | # Unbound PyQt signals reach this point in Python 3.4b3, and we want |
| 115 | # to avoid throwing an error. See also http://bugs.python.org/issue3158 |
| 116 | return False |
| 117 | else: |
| 118 | raise ValueError("object must be a class or function, got %r" % object) |
| 119 | |
| 120 | def _find(self, tests, obj, name, module, source_lines, globs, seen): |
| 121 | """ |
| 122 | Find tests for the given object and any contained objects, and |
| 123 | add them to `tests`. |
| 124 | """ |
| 125 | print('_find for:', obj, name, module) # dbg |
| 126 | if hasattr(obj,"skip_doctest"): |
| 127 | #print 'SKIPPING DOCTEST FOR:',obj # dbg |
| 128 | obj = DocTestSkip(obj) |
| 129 | |
| 130 | doctest.DocTestFinder._find(self,tests, obj, name, module, |
| 131 | source_lines, globs, seen) |
| 132 | |
| 133 | # Below we re-run pieces of the above method with manual modifications, |
| 134 | # because the original code is buggy and fails to correctly identify |
| 135 | # doctests in extension modules. |
| 136 | |
| 137 | # Local shorthands |
| 138 | from inspect import isroutine, isclass |
| 139 | |
| 140 | # Look for tests in a module's contained objects. |
| 141 | if inspect.ismodule(obj) and self._recurse: |
| 142 | for valname, val in obj.__dict__.items(): |
| 143 | valname1 = '%s.%s' % (name, valname) |