mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
hostkeymap: Fix sanitize_keymap on python3
And add test cases to cover the failure https://bugzilla.redhat.com/show_bug.cgi?id=1585574
This commit is contained in:
@@ -40,3 +40,11 @@ class TestHostkeymap(unittest.TestCase):
|
||||
hostkeymap._xorg_keymap(
|
||||
_open("xorg-rhel5.txt")),
|
||||
"us")
|
||||
|
||||
def testSanitize(self):
|
||||
def san(inp):
|
||||
return hostkeymap.sanitize_keymap(inp)
|
||||
|
||||
self.assertEqual(san("pt"), "pt")
|
||||
self.assertEqual(san("de-us"), "de")
|
||||
self.assertEqual(san("en_us"), "en-us")
|
||||
|
||||
@@ -186,11 +186,8 @@ def sanitize_keymap(kt):
|
||||
# Try a more intelligent lookup: strip out all '-' and '_', sort
|
||||
# the keytable keys putting the longest first, then compare
|
||||
# by string prefix
|
||||
def len_cmp(a, b):
|
||||
return len(b) - len(a)
|
||||
|
||||
clean_kt = kt.replace("-", "").replace("_", "")
|
||||
sorted_keys = sorted(list(keytable.keys()), len_cmp)
|
||||
sorted_keys = sorted(list(keytable.keys()), key=len)
|
||||
|
||||
for key in sorted_keys:
|
||||
origkey = key
|
||||
|
||||
Reference in New Issue
Block a user