2017-10-18 17:44:29 -04:00
# Copyright (C) 2017 Red Hat, Inc.
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2017-10-18 17:44:29 -04:00
import os
import unittest
from virtinst import hostkeymap
class TestHostkeymap ( unittest . TestCase ) :
"""
Tests for hostkeymap . py file parsing
"""
2017-10-18 18:07:04 -04:00
# pylint: disable=protected-access
2017-10-18 17:44:29 -04:00
def testFiles ( self ) :
def _open ( filename ) :
2017-10-20 15:03:29 -04:00
return open ( os . path . join ( os . getcwd ( ) ,
2017-10-18 17:44:29 -04:00
" tests/hostkeymap " , filename ) )
2017-10-21 12:36:44 +08:00
self . assertEqual (
2017-10-18 18:07:04 -04:00
hostkeymap . _sysconfig_keyboard (
_open ( " sysconfig-comments.txt " ) ) ,
2017-10-11 15:13:26 -06:00
" " )
2017-10-21 12:36:44 +08:00
self . assertEqual (
2017-10-18 18:07:04 -04:00
hostkeymap . _sysconfig_keyboard (
_open ( " sysconfig-rhel5.txt " ) ) ,
" us " )
2017-10-21 12:36:44 +08:00
self . assertEqual (
2017-10-18 18:07:04 -04:00
hostkeymap . _find_xkblayout (
_open ( " default-keyboard-debian9.txt " ) ) ,
" us " )
2017-10-21 12:36:44 +08:00
self . assertEqual (
2017-10-18 18:07:04 -04:00
hostkeymap . _find_xkblayout (
_open ( " console-setup-debian9.txt " ) ) ,
None )
2017-10-21 12:36:44 +08:00
self . assertEqual (
2017-10-18 18:07:04 -04:00
hostkeymap . _xorg_keymap (
_open ( " xorg-rhel5.txt " ) ) ,
" us " )
2018-06-07 11:33:37 -04:00
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 " )