fix open-file tests on windows

Windows filenames have backslashes, so we need to escape them, otherwise
shlex.split will delete them.

Also, we can't prodive our own executable on frozen tests.
This commit is contained in:
Daniel Schadt 2017-01-12 15:38:38 +01:00
parent ea56ded7fc
commit 07460832b6

View File

@ -28,6 +28,7 @@ import functools
import collections
import socket
import re
import shlex
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor, QClipboard
@ -989,24 +990,30 @@ def test_random_port():
class TestOpenFile:
@pytest.mark.not_frozen
def test_cmdline_without_argument(self, caplog, config_stub):
config_stub.data = {'general': {'default-open-dispatcher': ''}}
cmdline = '{} -c pass'.format(sys.executable)
executable = shlex.quote(sys.executable)
cmdline = '{} -c pass'.format(executable)
utils.open_file('/foo/bar', cmdline)
result = caplog.records[0].message
assert re.match(
r'Opening /foo/bar with \[.*python.*/foo/bar.*\]', result)
@pytest.mark.not_frozen
def test_cmdline_with_argument(self, caplog, config_stub):
config_stub.data = {'general': {'default-open-dispatcher': ''}}
cmdline = '{} -c pass {{}} raboof'.format(sys.executable)
executable = shlex.quote(sys.executable)
cmdline = '{} -c pass {{}} raboof'.format(executable)
utils.open_file('/foo/bar', cmdline)
result = caplog.records[0].message
assert re.match(
r"Opening /foo/bar with \[.*python.*/foo/bar.*'raboof'\]", result)
@pytest.mark.not_frozen
def test_setting_override(self, caplog, config_stub):
cmdline = '{} -c pass'.format(sys.executable)
executable = shlex.quote(sys.executable)
cmdline = '{} -c pass'.format(executable)
config_stub.data = {'general': {'default-open-dispatcher': cmdline}}
utils.open_file('/foo/bar')
result = caplog.records[0].message