spiegel-keyman/linux/keyman-config/tests/test_kvk2ldml.py
Eberhard Beilharz 50228a8266
fix(linux): properly deal with types of names
Names can be Unicode strings or byte arrays. This change allows for both
kinds. Also properly deal with the case when we can't get the name from
the .ttf file. And finally change the test so that we don't need the
`KbdKhmr.ttf` font.
2024-08-24 12:16:04 +08:00

57 lines
1.9 KiB
Python

import os
import shutil
import sys
import tempfile
import unittest
from keyman_config.kvk2ldml import KVKData, NFont, convert_ldml
class Kvk2LdmlTests(unittest.TestCase):
def _createKmpJson(self, packagedir):
kmpJsonFilename = os.path.join(packagedir, 'kmp.json')
with open(kmpJsonFilename, 'w') as file:
file.write('''{
"system": {
"keymanDeveloperVersion": "18.0",
"fileVersion": "7.0"
},
"files": [ {
"name": "khmer_angkor.kmx",
"description": "Keyboard Khmer Angkor"
}, {
"name": "kmp.json",
"description": "Package information (JSON)"
} ],
"keyboards": [ {
"name": "Khmer Angkor",
"id": "khmer_angkor",
"version": "1.5",
"oskFont": "keymanweb-osk.ttf",
"languages": [ {
"name": "Central Khmer (Khmer, Cambodia)",
"id": "km"
} ]}
]}''')
return kmpJsonFilename
def test_convert_ldml__adds_keymanFacename(self):
# Setup
keyboardName = 'khmer_angkor'
kvkData = KVKData()
kvkData.AssociatedKeyboard = keyboardName
kvkData.UnicodeFont = NFont()
kvkData.UnicodeFont.name='DontUseThis!'
workdir = tempfile.TemporaryDirectory()
kmpJsonFilename = self._createKmpJson(workdir.name)
shutil.copy2(os.path.join(sys.path[0], '../../../common/resources/fonts/keymanweb-osk.ttf'),
workdir.name)
# Execute
ldml = convert_ldml(keyboardName, kvkData, kmpJsonFilename)
# Verify
self.assertEqual(ldml.get('locale'), "zzz-keyman")
self.assertEqual(ldml.get('keymanFacename'), 'SymChar')
workdir.cleanup()