diff options
Diffstat (limited to 'tests/helpers/testutils.py')
-rw-r--r-- | tests/helpers/testutils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/helpers/testutils.py b/tests/helpers/testutils.py index a6022a6f9..d74c46fcb 100644 --- a/tests/helpers/testutils.py +++ b/tests/helpers/testutils.py @@ -196,6 +196,24 @@ def abs_datapath(): return path.resolve() +def substitute_testdata(path): + r"""Replace the (testdata) placeholder in path with `abs_datapath()`. + + If path is starting with file://, return path as an URI with file:// removed. This + is useful if path is going to be inserted into an URI: + + >>> path = substitute_testdata("C:\Users\qute") + >>> f"file://{path}/slug # results in valid URI + 'file:///C:/Users/qute/slug' + """ + if path.startswith('file://'): + testdata_path = abs_datapath().as_uri().replace('file://', '') + else: + testdata_path = str(abs_datapath()) + + return path.replace('(testdata)', testdata_path) + + @contextlib.contextmanager def nop_contextmanager(): yield |