MCPcopy Index your code
hub / github.com/RustPython/RustPython / _find

Method _find

Lib/doctest.py:1017–1076  ·  view source on GitHub ↗

Find tests for the given object and any contained objects, and add them to `tests`.

(self, tests, obj, name, module, source_lines, globs, seen)

Source from the content-addressed store, hash-verified

1015 return inspect.isroutine(maybe_routine)
1016
1017 def _find(self, tests, obj, name, module, source_lines, globs, seen):
1018 """
1019 Find tests for the given object and any contained objects, and
1020 add them to `tests`.
1021 """
1022 if self._verbose:
1023 print('Finding tests in %s' % name)
1024
1025 # If we've already processed this object, then ignore it.
1026 if id(obj) in seen:
1027 return
1028 seen[id(obj)] = 1
1029
1030 # Find a test for this object, and add it to the list of tests.
1031 test = self._get_test(obj, name, module, globs, source_lines)
1032 if test is not None:
1033 tests.append(test)
1034
1035 # Look for tests in a module's contained objects.
1036 if inspect.ismodule(obj) and self._recurse:
1037 for valname, val in obj.__dict__.items():
1038 valname = '%s.%s' % (name, valname)
1039
1040 # Recurse to functions & classes.
1041 if ((self._is_routine(val) or inspect.isclass(val)) and
1042 self._from_module(module, val)):
1043 self._find(tests, val, valname, module, source_lines,
1044 globs, seen)
1045
1046 # Look for tests in a module's __test__ dictionary.
1047 if inspect.ismodule(obj) and self._recurse:
1048 for valname, val in getattr(obj, '__test__', {}).items():
1049 if not isinstance(valname, str):
1050 raise ValueError("DocTestFinder.find: __test__ keys "
1051 "must be strings: %r" %
1052 (type(valname),))
1053 if not (inspect.isroutine(val) or inspect.isclass(val) or
1054 inspect.ismodule(val) or isinstance(val, str)):
1055 raise ValueError("DocTestFinder.find: __test__ values "
1056 "must be strings, functions, methods, "
1057 "classes, or modules: %r" %
1058 (type(val),))
1059 valname = '%s.__test__.%s' % (name, valname)
1060 self._find(tests, val, valname, module, source_lines,
1061 globs, seen)
1062
1063 # Look for tests in a class's contained objects.
1064 if inspect.isclass(obj) and self._recurse:
1065 for valname, val in obj.__dict__.items():
1066 # Special handling for staticmethod/classmethod.
1067 if isinstance(val, (staticmethod, classmethod)):
1068 val = val.__func__
1069
1070 # Recurse to methods, properties, and nested classes.
1071 if ((inspect.isroutine(val) or inspect.isclass(val) or
1072 isinstance(val, property)) and
1073 self._from_module(module, val)):
1074 valname = '%s.%s' % (name, valname)

Callers 1

findMethod · 0.95

Calls 9

_get_testMethod · 0.95
_is_routineMethod · 0.95
_from_moduleMethod · 0.95
idFunction · 0.85
getattrFunction · 0.85
isinstanceFunction · 0.85
printFunction · 0.50
appendMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected