Return a DocTest for the given object, if it defines a docstring; otherwise, return None.
(self, obj, name, module, globs, source_lines)
| 1076 | globs, seen) |
| 1077 | |
| 1078 | def _get_test(self, obj, name, module, globs, source_lines): |
| 1079 | """ |
| 1080 | Return a DocTest for the given object, if it defines a docstring; |
| 1081 | otherwise, return None. |
| 1082 | """ |
| 1083 | # Extract the object's docstring. If it doesn't have one, |
| 1084 | # then return None (no test for this object). |
| 1085 | if isinstance(obj, str): |
| 1086 | docstring = obj |
| 1087 | else: |
| 1088 | try: |
| 1089 | if obj.__doc__ is None: |
| 1090 | docstring = '' |
| 1091 | else: |
| 1092 | docstring = obj.__doc__ |
| 1093 | if not isinstance(docstring, str): |
| 1094 | docstring = str(docstring) |
| 1095 | except (TypeError, AttributeError): |
| 1096 | docstring = '' |
| 1097 | |
| 1098 | # Find the docstring's location in the file. |
| 1099 | lineno = self._find_lineno(obj, source_lines) |
| 1100 | |
| 1101 | # Don't bother if the docstring is empty. |
| 1102 | if self._exclude_empty and not docstring: |
| 1103 | return None |
| 1104 | |
| 1105 | # Return a DocTest for this object. |
| 1106 | if module is None: |
| 1107 | filename = None |
| 1108 | else: |
| 1109 | # __file__ can be None for namespace packages. |
| 1110 | filename = getattr(module, '__file__', None) or module.__name__ |
| 1111 | if filename[-4:] == ".pyc": |
| 1112 | filename = filename[:-1] |
| 1113 | return self._parser.get_doctest(docstring, globs, name, |
| 1114 | filename, lineno) |
| 1115 | |
| 1116 | def _find_lineno(self, obj, source_lines): |
| 1117 | """ |
no test coverage detected