Add tests for MycroftSkill translate methods

Verifies that resources are read from both locale and dialog folders.
Also checks that fallbacks to en-us from other languages works as
expected.
pull/2443/head
Åke Forslund 2019-12-28 23:34:24 +01:00
parent 5f02e7a086
commit 2c65e8188c
11 changed files with 76 additions and 0 deletions

View File

@ -552,6 +552,56 @@ class TestMycroftSkill(unittest.TestCase):
self.assertFalse(s.voc_match("My hovercraft is full of eels",
"turn_off_test"))
def test_translate_locations(self):
"""Assert that the a translatable list can be loaded from dialog and
locale.
"""
# Check that translatables can be loaded from the dialog directory
s = SimpleSkill1()
s.root_dir = abspath(join(dirname(__file__),
'translate', 'in-dialog/'))
lst = s.translate_list('good_things')
self.assertTrue(isinstance(lst, list))
vals = s.translate_namedvalues('named_things')
self.assertTrue(isinstance(vals, dict))
template = s.translate_template('test',
data={'thing': 'test framework'})
self.assertEqual(template,
['Oh look it\'s my favourite test framework'])
# Check that translatables can be loaded from locale folder
s = SimpleSkill1()
s.root_dir = abspath(join(dirname(__file__),
'translate', 'in-locale'))
lst = s.translate_list('good_things')
self.assertTrue(isinstance(lst, list))
vals = s.translate_namedvalues('named_things')
self.assertTrue(isinstance(vals, dict))
template = s.translate_template('test',
data={'thing': 'test framework'})
self.assertEqual(template,
['Oh look it\'s my favourite test framework'])
# Check loading in a non-en-us language
s = SimpleSkill1()
s.config_core['lang'] = 'de-de'
s.root_dir = abspath(join(dirname(__file__),
'translate', 'in-locale'))
lst = s.translate_list('good_things')
self.assertEqual(lst, ['sonne', 'mycroft', 'zahne'])
vals = s.translate_namedvalues('named_things')
self.assertEqual(vals['blau'], '2')
template = s.translate_template('test',
data={'thing': 'test framework'})
self.assertEqual(template,
['Aber setzen sie sich herr test framework'])
# Check fallback to english
lst = s.translate_list('not_in_german')
self.assertEqual(lst, ['not', 'in', 'German'])
# Restore lang to en-us
s.config_core['lang'] = 'en-us'
class _TestSkill(MycroftSkill):
def __init__(self):

View File

@ -0,0 +1,3 @@
sunshine
mycroft
licorice

View File

@ -0,0 +1,4 @@
dot,0
line,1
circle,2
ball,3

View File

@ -0,0 +1 @@
Oh look it's my favourite {thing}

View File

@ -0,0 +1,3 @@
sonne
mycroft
zahne

View File

@ -0,0 +1,3 @@
gelb,0
rot,1
blau,2

View File

@ -0,0 +1 @@
Aber setzen sie sich herr {thing}

View File

@ -0,0 +1,3 @@
sunshine
mycroft
licorice

View File

@ -0,0 +1,4 @@
dot,0
line,1
circle,2
ball,3

View File

@ -0,0 +1,3 @@
not
in
German

View File

@ -0,0 +1 @@
Oh look it's my favourite {thing}