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

Method _find_test_path

Lib/unittest/loader.py:407–480  ·  view source on GitHub ↗

Used by discovery. Loads tests from a single file, or a directories' __init__.py when passed the directory. Returns a tuple (None_or_tests_from_file, should_recurse).

(self, full_path, pattern, namespace=False)

Source from the content-addressed store, hash-verified

405 self._loading_packages.discard(name)
406
407 def _find_test_path(self, full_path, pattern, namespace=False):
408 """Used by discovery.
409
410 Loads tests from a single file, or a directories' __init__.py when
411 passed the directory.
412
413 Returns a tuple (None_or_tests_from_file, should_recurse).
414 """
415 basename = os.path.basename(full_path)
416 if os.path.isfile(full_path):
417 if not VALID_MODULE_NAME.match(basename):
418 # valid Python identifiers only
419 return None, False
420 if not self._match_path(basename, full_path, pattern):
421 return None, False
422 # if the test file matches, load it
423 name = self._get_name_from_path(full_path)
424 try:
425 module = self._get_module_from_name(name)
426 except case.SkipTest as e:
427 return _make_skipped_test(name, e, self.suiteClass), False
428 except:
429 error_case, error_message = \
430 _make_failed_import_test(name, self.suiteClass)
431 self.errors.append(error_message)
432 return error_case, False
433 else:
434 mod_file = os.path.abspath(
435 getattr(module, '__file__', full_path))
436 realpath = _splitext(
437 os.path.realpath(mod_file))
438 fullpath_noext = _splitext(
439 os.path.realpath(full_path))
440 if realpath.lower() != fullpath_noext.lower():
441 module_dir = os.path.dirname(realpath)
442 mod_name = _splitext(
443 os.path.basename(full_path))
444 expected_dir = os.path.dirname(full_path)
445 msg = ("%r module incorrectly imported from %r. Expected "
446 "%r. Is this module globally installed?")
447 raise ImportError(
448 msg % (mod_name, module_dir, expected_dir))
449 return self.loadTestsFromModule(module, pattern=pattern), False
450 elif os.path.isdir(full_path):
451 if (not namespace and
452 not os.path.isfile(os.path.join(full_path, '__init__.py'))):
453 return None, False
454
455 load_tests = None
456 tests = None
457 name = self._get_name_from_path(full_path)
458 try:
459 package = self._get_module_from_name(name)
460 except case.SkipTest as e:
461 return _make_skipped_test(name, e, self.suiteClass), False
462 except:
463 error_case, error_message = \
464 _make_failed_import_test(name, self.suiteClass)

Callers 1

_find_testsMethod · 0.95

Calls 15

_match_pathMethod · 0.95
_get_name_from_pathMethod · 0.95
_get_module_from_nameMethod · 0.95
loadTestsFromModuleMethod · 0.95
_make_skipped_testFunction · 0.85
_make_failed_import_testFunction · 0.85
getattrFunction · 0.85
basenameMethod · 0.80
realpathMethod · 0.80
_splitextFunction · 0.70
isfileMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected