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

Function _module_relative_path

Lib/doctest.py:418–450  ·  view source on GitHub ↗
(module, test_path)

Source from the content-addressed store, hash-verified

416
417# [XX] Normalize with respect to os.path.pardir?
418def _module_relative_path(module, test_path):
419 if not inspect.ismodule(module):
420 raise TypeError('Expected a module: %r' % module)
421 if test_path.startswith('/'):
422 raise ValueError('Module-relative files may not have absolute paths')
423
424 # Normalize the path. On Windows, replace "/" with "\".
425 test_path = os.path.join(*(test_path.split('/')))
426
427 # Find the base directory for the path.
428 if hasattr(module, '__file__'):
429 # A normal module/package
430 basedir = os.path.split(module.__file__)[0]
431 elif module.__name__ == '__main__':
432 # An interactive session.
433 if len(sys.argv)>0 and sys.argv[0] != '':
434 basedir = os.path.split(sys.argv[0])[0]
435 else:
436 basedir = os.curdir
437 else:
438 if hasattr(module, '__path__'):
439 for directory in module.__path__:
440 fullpath = os.path.join(directory, test_path)
441 if os.path.exists(fullpath):
442 return fullpath
443
444 # A module w/o __file__ (this includes builtins)
445 raise ValueError("Can't resolve paths relative to the module "
446 "%r (it has no __file__)"
447 % module.__name__)
448
449 # Combine the base directory and the test path.
450 return os.path.join(basedir, test_path)
451
452######################################################################
453## 2. Example & DocTest

Callers 1

_load_testfileFunction · 0.85

Calls 6

hasattrFunction · 0.85
lenFunction · 0.85
startswithMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected