add tests for utils.open_file
This commit is contained in:
parent
536c76848e
commit
2986f7b615
@ -27,6 +27,7 @@ import logging
|
||||
import functools
|
||||
import collections
|
||||
import socket
|
||||
import re
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QColor, QClipboard
|
||||
@ -984,3 +985,45 @@ def test_random_port():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind(('localhost', port))
|
||||
sock.close()
|
||||
|
||||
|
||||
class TestOpenFile:
|
||||
|
||||
def test_cmdline_without_argument(self, caplog, config_stub):
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
cmdline = '{} -c pass'.format(sys.executable)
|
||||
utils.open_file('/foo/bar', cmdline)
|
||||
result = caplog.records[0].message
|
||||
assert re.match(
|
||||
r'Opening /foo/bar with \[.*python.*/foo/bar.*\]', result)
|
||||
|
||||
def test_cmdline_with_argument(self, caplog, config_stub):
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
cmdline = '{} -c pass {{}} raboof'.format(sys.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)
|
||||
|
||||
def test_setting_override(self, caplog, config_stub):
|
||||
cmdline = '{} -c pass'.format(sys.executable)
|
||||
config_stub.data = {'general': {'default-open-dispatcher': cmdline}}
|
||||
utils.open_file('/foo/bar')
|
||||
result = caplog.records[0].message
|
||||
assert re.match(
|
||||
r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
|
||||
|
||||
def test_system_default_application(self, caplog, config_stub,
|
||||
monkeypatch):
|
||||
self.open_url_called = False
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
monkeypatch.setattr('PyQt5.QtGui.QDesktopServices.openUrl',
|
||||
self.mock_open_url)
|
||||
utils.open_file('/foo/bar')
|
||||
result = caplog.records[0].message
|
||||
assert re.match(
|
||||
r"Opening /foo/bar with the system application", result)
|
||||
assert self.open_url_called
|
||||
|
||||
def mock_open_url(self, url):
|
||||
self.open_url_called = True
|
||||
|
Loading…
Reference in New Issue
Block a user