Add a datapath replacement for spawning userscripts

This adds a `(datapath)` replacement for feature tests.

`(datapath)` will expand to the absolute path to the integration data
directory.
This commit is contained in:
Philipp Hansch 2016-03-28 23:48:37 +02:00
parent 0083538491
commit 5811a25299
3 changed files with 17 additions and 3 deletions

View File

@ -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')

View File

@ -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

View File

@ -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