From 7b0f4e08129f130d164d0bcb4e8ca5d981d6ef37 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Feb 2017 18:41:22 +0100 Subject: [PATCH] Use mock for open_file tests --- tests/unit/utils/test_utils.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index ef6d1e72c..c790e7a31 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -30,7 +30,7 @@ import socket import re import shlex -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, QUrl from PyQt5.QtGui import QColor, QClipboard import pytest @@ -1020,19 +1020,12 @@ class TestOpenFile: assert re.match( r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result) - def test_system_default_application(self, caplog, config_stub, - monkeypatch): - # pylint: disable=attribute-defined-outside-init - self.open_url_called = False + def test_system_default_application(self, caplog, config_stub, mocker): config_stub.data = {'general': {'default-open-dispatcher': ''}} - monkeypatch.setattr('PyQt5.QtGui.QDesktopServices.openUrl', - self.mock_open_url) + m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={}, + new_callable=mocker.Mock) 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): - # pylint: disable=attribute-defined-outside-init - self.open_url_called = True + m.assert_called_with(QUrl('file:///foo/bar'))