Fix tests on OS X, take two.

This commit is contained in:
Florian Bruhin 2015-05-17 18:59:40 +02:00
parent a9f5d45c34
commit 81ba49e79b
2 changed files with 17 additions and 10 deletions

View File

@ -326,19 +326,24 @@ def keyevent_to_string(e):
A name of the key (combination) as a string or
None if only modifiers are pressed..
"""
modmask2str = collections.OrderedDict([
(Qt.ControlModifier, 'Ctrl'),
(Qt.AltModifier, 'Alt'),
(Qt.MetaModifier, 'Meta'),
(Qt.ShiftModifier, 'Shift'),
])
if sys.platform == 'darwin':
# Qt swaps Ctrl/Meta on OS X, so we switch it back here so the user can
# use it in the config as expected. See:
# https://github.com/The-Compiler/qutebrowser/issues/110
# http://doc.qt.io/qt-5.4/osx-issues.html#special-keys
modmask2str[Qt.MetaModifier] = 'Ctrl'
modmask2str[Qt.ControlModifier] = 'Meta'
modmask2str = collections.OrderedDict([
(Qt.MetaModifier, 'Ctrl'),
(Qt.AltModifier, 'Alt'),
(Qt.ControlModifier, 'Meta'),
(Qt.ShiftModifier, 'Shift'),
])
else:
modmask2str = collections.OrderedDict([
(Qt.ControlModifier, 'Ctrl'),
(Qt.AltModifier, 'Alt'),
(Qt.MetaModifier, 'Meta'),
(Qt.ShiftModifier, 'Shift'),
])
modifiers = (Qt.Key_Control, Qt.Key_Alt, Qt.Key_Shift, Qt.Key_Meta,
Qt.Key_AltGr, Qt.Key_Super_L, Qt.Key_Super_R,
Qt.Key_Hyper_L, Qt.Key_Hyper_R, Qt.Key_Direction_L,

View File

@ -19,6 +19,7 @@
"""Tests for qutebrowser.utils.utils."""
import sys
import enum
import datetime
import os.path
@ -312,10 +313,11 @@ class TestKeyEventToString:
def test_key_and_modifier(self, fake_keyevent_factory):
"""Test with key and modifier pressed."""
evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
assert utils.keyevent_to_string(evt) == 'Ctrl+A'
expected = 'Meta+A' if sys.platform == 'darwin' else 'Ctrl+A'
assert utils.keyevent_to_string(evt) == expected
def test_key_and_modifiers(self, fake_keyevent_factory):
"""Test with key and multiple modifier pressed."""
"""Test with key and multiple modifiers pressed."""
evt = fake_keyevent_factory(
key=Qt.Key_A, modifiers=(Qt.ControlModifier | Qt.AltModifier |
Qt.MetaModifier | Qt.ShiftModifier))