diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 1c8f0db28..6ce7569b5 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -22,6 +22,7 @@ import re import pprint +import os.path def print_i(text, indent, error=False): @@ -101,3 +102,14 @@ def pattern_match(*, pattern, value): """ re_pattern = '.*'.join(re.escape(part) for part in pattern.split('*')) return re.fullmatch(re_pattern, value) is not None + +def abs_datapath(from_file): + """Returns the absolute datapath. + + __FILE__ must be given as an argument + + Return: + The absolute path to the tests/integration/data directory. + """ + file_abs = os.path.abspath(os.path.dirname(from_file)) + return os.path.join(file_abs, '..', 'data') diff --git a/tests/integration/features/conftest.py b/tests/integration/features/conftest.py index 03559ede7..b22cf0924 100644 --- a/tests/integration/features/conftest.py +++ b/tests/integration/features/conftest.py @@ -129,6 +129,8 @@ def run_command(quteproc, httpbin, command): else: count = None command = command.replace('(port)', str(httpbin.port)) + command = command.replace('(datapath)', utils.abs_datapath(__file__)) + quteproc.send_cmd(command, count=count) @@ -334,8 +336,8 @@ def check_contents(quteproc, filename): The filename is interpreted relative to tests/integration/data. """ content = quteproc.get_content(plain=False) - path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', - 'data', os.path.join(*filename.split('/'))) + path = os.path.join(utils.abs_datapath(__file__), + os.path.join(*filename.split('/'))) with open(path, 'r', encoding='utf-8') as f: file_content = f.read() assert content == file_content diff --git a/tests/integration/features/spawn.feature b/tests/integration/features/spawn.feature index 3f31a7acc..32b77fd41 100644 --- a/tests/integration/features/spawn.feature +++ b/tests/integration/features/spawn.feature @@ -17,7 +17,7 @@ Feature: :spawn Then "Executing echo with args ['about:blank'], userscript=False" should be logged Scenario: Running :spawn with userscript - When I run :spawn --userscript open_current_url + When I run :spawn --userscript (datapath)/userscripts/open_current_url And I wait until about:blank is loaded Then the following tabs should be open: - about:blank