another lineparser/utilcmds test revision
* verify exception message in lineparser double open * check for hunter with `pytest.importorskip` * stricter exception checking in debug_trace test
This commit is contained in:
parent
64cf8fcd39
commit
23a62e952d
@ -66,9 +66,10 @@ class TestBaseLineParser:
|
|||||||
mocker.patch('builtins.open', mock.mock_open())
|
mocker.patch('builtins.open', mock.mock_open())
|
||||||
|
|
||||||
with lineparser._open('r'):
|
with lineparser._open('r'):
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(IOError) as excinfo:
|
||||||
with lineparser._open('r'):
|
with lineparser._open('r'):
|
||||||
pass
|
pass
|
||||||
|
assert str(excinfo.value) == 'Refusing to double-open AppendLineParser.'
|
||||||
|
|
||||||
def test_binary(self, mocker):
|
def test_binary(self, mocker):
|
||||||
"""Test if _open and _write correctly handle binary files."""
|
"""Test if _open and _write correctly handle binary files."""
|
||||||
|
@ -26,13 +26,6 @@ import pytest
|
|||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
||||||
_hunter_available = False
|
|
||||||
try:
|
|
||||||
import hunter # pylint: disable=unused-import
|
|
||||||
_hunter_available = True
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from qutebrowser.misc import utilcmds
|
from qutebrowser.misc import utilcmds
|
||||||
|
|
||||||
from qutebrowser.commands import cmdexc
|
from qutebrowser.commands import cmdexc
|
||||||
@ -73,16 +66,22 @@ def test_debug_crash_segfault():
|
|||||||
assert 'Segfault failed' in str(excinfo.value)
|
assert 'Segfault failed' in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not _hunter_available, reason="hunter not available")
|
|
||||||
def test_debug_trace(mocker):
|
def test_debug_trace(mocker):
|
||||||
"""Check if hunter.trace is properly called."""
|
"""Check if hunter.trace is properly called."""
|
||||||
|
# but only if hunter is available
|
||||||
|
pytest.importorskip('hunter')
|
||||||
hunter_mock = mocker.patch('qutebrowser.misc.utilcmds.hunter')
|
hunter_mock = mocker.patch('qutebrowser.misc.utilcmds.hunter')
|
||||||
utilcmds.debug_trace(1)
|
utilcmds.debug_trace(1)
|
||||||
assert hunter_mock.trace.assert_called_with(1)
|
assert hunter_mock.trace.assert_called_with(1)
|
||||||
|
|
||||||
|
def _mock_exception():
|
||||||
|
"""Side effect for testing debug_trace's reraise."""
|
||||||
|
raise Exception('message')
|
||||||
|
|
||||||
hunter_mock.trace.side_effect = Exception
|
hunter_mock.trace.side_effect = Exception
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(CommandError) as excinfo:
|
||||||
utilcmds.debug_trace()
|
utilcmds.debug_trace()
|
||||||
|
assert str(excinfo.value) == 'Exception: message'
|
||||||
|
|
||||||
|
|
||||||
def test_debug_trace_no_hunter(monkeypatch):
|
def test_debug_trace_no_hunter(monkeypatch):
|
||||||
|
Loading…
Reference in New Issue
Block a user