Use json.dumps for logged fake clipboard.
For some reason, when comparing the repr in the two processes, we get different results on OS X and Windows: - expected: "fünf" - "f\xfcnf" coming back from the subprocess on OS X - "fnf" on Windows Instead we're comparing the json dump now, which should be more predictable.
This commit is contained in:
parent
79f83a033d
commit
0b491f6caf
@ -22,6 +22,7 @@
|
||||
import io
|
||||
import sys
|
||||
import enum
|
||||
import json
|
||||
import os.path
|
||||
import collections
|
||||
import functools
|
||||
@ -762,7 +763,7 @@ def set_clipboard(data, selection=False):
|
||||
raise SelectionUnsupportedError
|
||||
if log_clipboard:
|
||||
what = 'primary selection' if selection else 'clipboard'
|
||||
log.misc.debug("Setting fake {}: {!r}".format(what, data))
|
||||
log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data)))
|
||||
else:
|
||||
mode = QClipboard.Selection if selection else QClipboard.Clipboard
|
||||
clipboard.setText(data, mode=mode)
|
||||
|
@ -400,13 +400,15 @@ def check_open_tabs(quteproc, tabs):
|
||||
def clipboard_contains(quteproc, httpbin, what, content):
|
||||
expected = content.replace('(port)', str(httpbin.port))
|
||||
expected = expected.replace('\\n', '\n')
|
||||
quteproc.wait_for(message='Setting fake {}: {!r}'.format(what, expected))
|
||||
quteproc.wait_for(message='Setting fake {}: {!r}'.format(
|
||||
what, json.dumps(expected)))
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.parse('the clipboard should contain:\n{content}'))
|
||||
def clipboard_contains_multiline(quteproc, content):
|
||||
expected = textwrap.dedent(content)
|
||||
quteproc.wait_for(message='Setting fake clipboard: {!r}'.format(expected))
|
||||
quteproc.wait_for(message='Setting fake clipboard: {}'.format(
|
||||
json.dumps(expected)))
|
||||
|
||||
|
||||
@bdd.then("qutebrowser should quit")
|
||||
|
@ -953,15 +953,17 @@ class TestGetSetClipboard:
|
||||
with pytest.raises(utils.SelectionUnsupportedError):
|
||||
utils.set_clipboard('foo', selection=True)
|
||||
|
||||
@pytest.mark.parametrize('selection, what', [
|
||||
(True, 'primary selection'),
|
||||
(False, 'clipboard'),
|
||||
@pytest.mark.parametrize('selection, what, text, expected', [
|
||||
(True, 'primary selection', 'fake text', 'fake text'),
|
||||
(False, 'clipboard', 'fake text', 'fake text'),
|
||||
(False, 'clipboard', 'füb', r'f\u00fcb'),
|
||||
])
|
||||
def test_set_logging(self, clipboard_mock, caplog, selection, what):
|
||||
def test_set_logging(self, clipboard_mock, caplog, selection, what,
|
||||
text, expected):
|
||||
utils.log_clipboard = True
|
||||
utils.set_clipboard('fake clipboard text', selection=selection)
|
||||
utils.set_clipboard(text, selection=selection)
|
||||
assert not clipboard_mock.setText.called
|
||||
expected = "Setting fake {}: 'fake clipboard text'".format(what)
|
||||
expected = 'Setting fake {}: "{}"'.format(what, expected)
|
||||
assert caplog.records[0].message == expected
|
||||
|
||||
def test_get(self):
|
||||
|
Loading…
Reference in New Issue
Block a user