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