Test and fix keyutils._parse_keystring
This commit is contained in:
parent
7f8508a367
commit
3c9e8ff9ab
@ -151,10 +151,14 @@ def _parse_keystring(keystr):
|
||||
special = False
|
||||
for c in keystr:
|
||||
if c == '>':
|
||||
assert special
|
||||
yield _normalize_keystr(key)
|
||||
key = ''
|
||||
special = False
|
||||
if special:
|
||||
yield _normalize_keystr(key)
|
||||
key = ''
|
||||
special = False
|
||||
else:
|
||||
yield '>'
|
||||
for c in key:
|
||||
yield 'Shift+' + c if c.isupper() else c
|
||||
elif c == '<':
|
||||
special = True
|
||||
elif special:
|
||||
|
@ -138,6 +138,31 @@ def test_key_info_str(key, modifiers, expected):
|
||||
assert str(keyutils.KeyInfo(key, modifiers)) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('keystr, expected', [
|
||||
('foo', "Could not parse 'foo': error"),
|
||||
(None, "Could not parse keystring: error"),
|
||||
])
|
||||
def test_key_parse_error(keystr, expected):
|
||||
exc = keyutils.KeyParseError(keystr, "error")
|
||||
assert str(exc) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('keystr, parts', [
|
||||
('a', ['a']),
|
||||
('ab', ['a', 'b']),
|
||||
('a<', ['a', '<']),
|
||||
('a>', ['a', '>']),
|
||||
('<a', ['<', 'a']),
|
||||
('>a', ['>', 'a']),
|
||||
('aA', ['a', 'Shift+A']),
|
||||
('a<Ctrl+a>b', ['a', 'ctrl+a', 'b']),
|
||||
('<Ctrl+a>a', ['ctrl+a', 'a']),
|
||||
('a<Ctrl+a>', ['a', 'ctrl+a']),
|
||||
])
|
||||
def test_parse_keystr(keystr, parts):
|
||||
assert list(keyutils._parse_keystring(keystr)) == parts
|
||||
|
||||
|
||||
@pytest.mark.parametrize('keystr, expected', [
|
||||
('<Control-x>', keyutils.KeySequence(Qt.ControlModifier | Qt.Key_X)),
|
||||
('<Meta-x>', keyutils.KeySequence(Qt.MetaModifier | Qt.Key_X)),
|
||||
|
Loading…
Reference in New Issue
Block a user