MCPcopy Index your code
hub / github.com/python/cpython / _load_testfile

Function _load_testfile

Lib/doctest.py:240–255  ·  view source on GitHub ↗
(filename, package, module_relative, encoding)

Source from the content-addressed store, hash-verified

238 raise TypeError("Expected a module, string, or None")
239
240def _load_testfile(filename, package, module_relative, encoding):
241 if module_relative:
242 package = _normalize_module(package, 3)
243 filename = _module_relative_path(package, filename)
244 if (loader := getattr(package, '__loader__', None)) is None:
245 try:
246 loader = package.__spec__.loader
247 except AttributeError:
248 pass
249 if hasattr(loader, 'get_data'):
250 file_contents = loader.get_data(filename)
251 # get_data() opens files as 'rb', so one must do the equivalent
252 # conversion as universal newlines would do.
253 return TextIOWrapper(BytesIO(file_contents), encoding=encoding, newline=None).read(), filename
254 with open(filename, encoding=encoding) as f:
255 return f.read(), filename
256
257def _indent(s, indent=4):
258 """

Callers 2

testfileFunction · 0.85
DocFileTestFunction · 0.85

Calls 7

TextIOWrapperClass · 0.90
BytesIOClass · 0.90
_normalize_moduleFunction · 0.85
_module_relative_pathFunction · 0.85
openFunction · 0.70
get_dataMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…