Пример #1
0
 def test_set_translations(self):
     """ Test set_translations helper """
     with patch.object(l10n, 'translations', {'de': None}):
         self.assertEqual(l10n.translations['de'], None)
         set_translations()
         self.assertIsInstance(l10n.translations['de'], gettext.NullTranslations)
         set_translations(l10n.Translations())
         self.assertIsInstance(l10n.translations['de'], l10n.Translations)
         set_translations({'de': l10n.Translations(), 'en': l10n.Translations()})
         self.assertIsInstance(l10n.translations['en'], l10n.Translations)
         with self.assertRaises(TypeError):
             set_translations(1)
Пример #2
0
 def test_response_returns_message(self):
     """ Test if context._ returns l10n.Message
     """
     l10n.translations = {'de': l10n.Translations()}
     context = create_context('TELEKOM_Demo_Intent')
     with patch('random.randint',
                return_value=Response(
                    text=context._('some text'))) as mock_gde:
         mock_gde.__name__ = 'mock_gde'
         intent = Intent('TELEKOM_Demo_Intent', random.randint)
         response = intent(context)
         self.assertIsInstance(response.text, l10n.Message)
Пример #3
0
import datetime
from datetime import timedelta
from dateutil.tz import tzutc, tzoffset

import importlib
from skill_sdk import l10n

# Reset Location entity, in case it's been overwritten by services.location
from skill_sdk import entities
importlib.reload(entities)

from skill_sdk.entities import Location, Device, TimeRange, TimeSet, AttributeV2
from skill_sdk.entities import snake_to_camel, camel_to_snake, on_off_to_boolean, rank, convert
from skill_sdk.test_helpers import create_context, mock_datetime_now

l10n.translations = {'de': l10n.Translations()}


class TestUtils(unittest.TestCase):
    def test_snake_to_camel(self):
        self.assertEqual(snake_to_camel('abc'), 'abc')
        self.assertEqual(snake_to_camel('a_b_c'), 'aBC')
        self.assertEqual(snake_to_camel('ab_2'), 'ab2')
        self.assertEqual(snake_to_camel('a_bc'), 'aBc')
        self.assertEqual(snake_to_camel('snake_case'), 'snakeCase')
        with self.assertRaises(AttributeError):
            snake_to_camel(123)

    def test_camel_to_snake(self):
        self.assertEqual(camel_to_snake('Simple'), 'simple')
        self.assertEqual(camel_to_snake('SnakeCase'), 'snake_case')
Пример #4
0
import sys
import gevent
import requests
import unittest
import importlib
from typing import List
import requests_mock

from unittest.mock import patch
from skill_sdk import intents, l10n, log, skill
from skill_sdk.__version__ import __version__, __spi_version__
from skill_sdk.l10n import _
from skill_sdk.config import Config
from skill_sdk import test_helpers

l10n.translations = {'de': l10n.Translations(), 'en': l10n.Translations()}
l10n.translations['de']._catalog['HELLO'] = 'Hallo Welt!'
l10n.translations['en']._catalog['HELLO'] = 'Hello World!'


@skill.intent_handler('HELLO_INTENT')
def hello():
    return _('HELLO')


@skill.intent_handler('DRAGONS_INTENT')
def dragons(dragon_list: List[str]):
    return _('DRAGONS')


@skill.intent_handler(skill.FALLBACK_INTENT)