Merge branch 'bdd_test_spawn_command' of https://github.com/phansch/qutebrowser into phansch-bdd_test_spawn_command

This commit is contained in:
Florian Bruhin 2016-03-29 21:12:29 +02:00
commit fee3b9a02b
5 changed files with 77 additions and 2 deletions

View File

@ -22,6 +22,7 @@
import re
import pprint
import os.path
def print_i(text, indent, error=False):
@ -101,3 +102,13 @@ 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():
"""Get the absolute path to the integration data directory.
Return:
The absolute path to the tests/integration/data directory.
"""
file_abs = os.path.abspath(os.path.dirname(__file__))
return os.path.join(file_abs, '..', 'integration', 'data')

View File

@ -0,0 +1,3 @@
#!/bin/bash
echo "open -t $QUTE_URL" >> "$QUTE_FIFO"

View File

@ -129,9 +129,24 @@ def run_command(quteproc, httpbin, command):
else:
count = None
command = command.replace('(port)', str(httpbin.port))
quteproc.send_cmd(command, count=count)
@bdd.when(bdd.parsers.parse("I execute the userscript {userscript}"))
def run_userscript(quteproc, userscript):
"""Run a userscript located in tests/integration/data/userscripts.
Wrapper around :spawn --userscript {userscript} that uses an absolute
path.
"""
abs_userscript_path = os.path.join(utils.abs_datapath(),
'userscripts', userscript)
cmd = ':spawn --userscript {abs_userscript_path}'
quteproc.send_cmd(cmd.format(abs_userscript_path=abs_userscript_path))
@bdd.when(bdd.parsers.parse("I reload"))
def reload(qtbot, httpbin, quteproc, command):
"""Reload and wait until a new request is received."""
@ -334,8 +349,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(),
os.path.join(*filename.split('/')))
with open(path, 'r', encoding='utf-8') as f:
file_content = f.read()
assert content == file_content

View File

@ -0,0 +1,25 @@
Feature: :spawn
Scenario: Running :spawn
When I run :spawn -v echo "Hello"
Then the message "Command exited successfully." should be shown
Scenario: Running :spawn with command that does not exist
When I run :spawn command_does_not_exist127623
Then the error "Error while spawning command: The process failed to start." should be shown
Scenario: Running :spawn with invalid quoting
When I run :spawn ""'""
Then the error "Error while splitting command: No closing quotation" should be shown
Scenario: Running :spawn with url variable
When I run :spawn echo {url}
Then "Executing echo with args ['about:blank'], userscript=False" should be logged
@posix
Scenario: Running :spawn with userscript
When I execute the userscript open_current_url
And I wait until about:blank is loaded
Then the following tabs should be open:
- about:blank
- about:blank (active)

View File

@ -0,0 +1,21 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2015-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import pytest_bdd as bdd
bdd.scenarios('spawn.feature')