Change clipboard mocking
This commit is contained in:
parent
30d3612a17
commit
537aa22d64
@ -510,11 +510,13 @@ def sanitize_filename(name, replacement='_'):
|
|||||||
|
|
||||||
def set_clipboard(data, selection=False):
|
def set_clipboard(data, selection=False):
|
||||||
"""Set the clipboard to some given data."""
|
"""Set the clipboard to some given data."""
|
||||||
|
global fake_clipboard
|
||||||
if selection and not supports_selection():
|
if selection and not supports_selection():
|
||||||
raise SelectionUnsupportedError
|
raise SelectionUnsupportedError
|
||||||
if log_clipboard:
|
if log_clipboard:
|
||||||
what = 'primary selection' if selection else 'clipboard'
|
what = 'primary selection' if selection else 'clipboard'
|
||||||
log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data)))
|
log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data)))
|
||||||
|
fake_clipboard = data
|
||||||
else:
|
else:
|
||||||
mode = QClipboard.Selection if selection else QClipboard.Clipboard
|
mode = QClipboard.Selection if selection else QClipboard.Clipboard
|
||||||
QApplication.clipboard().setText(data, mode=mode)
|
QApplication.clipboard().setText(data, mode=mode)
|
||||||
|
@ -599,7 +599,7 @@ def check_open_tabs(quteproc, request, tabs):
|
|||||||
r'contain "(?P<content>.*)"'))
|
r'contain "(?P<content>.*)"'))
|
||||||
def clipboard_contains(quteproc, server, what, content):
|
def clipboard_contains(quteproc, server, what, content):
|
||||||
expected = content.replace('(port)', str(server.port))
|
expected = content.replace('(port)', str(server.port))
|
||||||
expected = expected.replace('\\n', '\n')
|
expected = expected.replace('\\n', os.linesep)
|
||||||
quteproc.wait_for(message='Setting fake {}: {}'.format(
|
quteproc.wait_for(message='Setting fake {}: {}'.format(
|
||||||
what, json.dumps(expected)))
|
what, json.dumps(expected)))
|
||||||
|
|
||||||
|
@ -651,6 +651,7 @@ class TestGetSetClipboard:
|
|||||||
autospec=True)
|
autospec=True)
|
||||||
clipboard = m()
|
clipboard = m()
|
||||||
clipboard.text.return_value = 'mocked clipboard text'
|
clipboard.text.return_value = 'mocked clipboard text'
|
||||||
|
mocker.patch('qutebrowser.utils.utils.fake_clipboard', None)
|
||||||
return clipboard
|
return clipboard
|
||||||
|
|
||||||
def test_set(self, clipboard_mock, caplog):
|
def test_set(self, clipboard_mock, caplog):
|
||||||
|
Loading…
Reference in New Issue
Block a user