MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_test_loc

Function get_test_loc

src/commoncode/testcase.py:51–84  ·  view source on GitHub ↗

Given a `test_path` relative to the `test_data_dir` directory, return the location to a test file or directory for this path. No copy is done. Raise an IOError if `must_exist` is True and the `test_path` does not exists.

(
    test_path,
    test_data_dir,
    debug=False,
    must_exist=True,
)

Source from the content-addressed store, hash-verified

49
50
51def get_test_loc(
52 test_path,
53 test_data_dir,
54 debug=False,
55 must_exist=True,
56):
57 """
58 Given a `test_path` relative to the `test_data_dir` directory, return the
59 location to a test file or directory for this path. No copy is done.
60 Raise an IOError if `must_exist` is True and the `test_path` does not exists.
61 """
62 if debug:
63 import inspect
64
65 caller = inspect.stack()[1][3]
66 print('\nget_test_loc,%(caller)s,"%(test_path)s","%(test_data_dir)s"' % locals())
67
68 assert test_path
69 assert test_data_dir
70
71 if not path.exists(test_data_dir):
72 raise IOError(
73 "[Errno 2] No such directory: test_data_dir not found: '%(test_data_dir)s'" % locals()
74 )
75
76 tpath = to_os_native_path(test_path)
77 test_loc = path.abspath(path.join(test_data_dir, tpath))
78
79 if must_exist and not path.exists(test_loc):
80 raise IOError(
81 "[Errno 2] No such file or directory: test_path not found: '%(test_loc)s'" % locals()
82 )
83
84 return test_loc
85
86
87class FileDrivenTesting(object):

Callers 1

get_test_locMethod · 0.85

Calls 3

to_os_native_pathFunction · 0.85
existsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected