예제 #1
0
    def setUp(self):
        client = TestClient()
        self._client_context = ClientContext(client, "testid")
        self._client_context.bot = Bot(BotConfiguration(), client)

        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker"
        self._client_context.bot._spell_checker = SpellingChecker.initiate_spellchecker(spelling_config, None)
예제 #2
0
    def test_initiate_spellchecker_invalid_classname(self):

        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = "programytest.spelling.test_base.InvalidSpellingChecker"

        storage_factory = None

        spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, storage_factory)

        self.assertIsNone(spell_checker)
예제 #3
0
    def test_initiate_spellchecker_no_classname(self):

        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = None

        storage_factory = None

        spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, storage_factory)

        self.assertIsNone(spell_checker)
예제 #4
0
    def test_initiate_spellchecker_no_storage(self):

        spelling_config = BotSpellingConfiguration()
        spelling_config._load = True
        spelling_config._classname = "programy.spelling.norvig.NorvigSpellingChecker"

        client = TestClient()
        storage_factory = client.storage_factory

        spell_checker = SpellingChecker.initiate_spellchecker(spelling_config, storage_factory)

        self.assertIsNotNone(spell_checker)
예제 #5
0
    def test_initiate_spellchecker_load_is_false(self):

        spelling_config = BotSpellingConfiguration()
        spelling_config._load = False
        spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker"

        storage_factory = None

        spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, storage_factory)

        self.assertIsNone(spell_checker)
예제 #6
0
    def test_check_spelling_before_false(self):
        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker"
        spelling_config._check_before = False

        storage_factory = None

        spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, storage_factory)

        client = TestClient()
        client_context = client.create_client_context("user1")

        sentence = Sentence(client_context, "Hello word")

        spell_checker.check_spelling_before(client_context, sentence)

        self.assertEqual(sentence.text(client_context), "Hello word")
예제 #7
0
    def test_check_spelling_and_retry_false(self):
        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker"
        spelling_config._check_and_retry = False

        storage_factory = None

        spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, storage_factory)

        client = TestClient()
        client_context = client.create_client_context("user1")
        tokenizer = client_context.brain.tokenizer
        client_context._brain = MockBrain()

        sentence = Sentence(tokenizer, "Hello word")

        response = spell_checker.check_spelling_and_retry(
            client_context, sentence)

        self.assertIsNone(response)
예제 #8
0
    def setUp(self):
        client = GetAIMLTestClient()
        self._client_context = client.create_client_context("testid")
        self._client_context.brain.properties.load_from_text("""
             default_get:unknown
         """)
        self._client_context.bot.brain.dynamics.add_dynamic_var(
            'gettime', "programy.dynamic.variables.datetime.GetTime", None)
        self._client_context.bot.brain.dynamics.add_dynamic_var(
            'spelling', "programy.dynamic.variables.system.spelling.Spelling",
            None)
        self._client_context.bot.brain.dynamics.add_dynamic_var(
            'splitter',
            "programy.dynamic.variables.system.splitter.SentenceSplitter",
            None)

        spelling_config = BotSpellingConfiguration()
        spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker"
        self._client_context.bot._spell_checker = SpellingChecker.initiate_spellchecker(
            spelling_config, None)

        config = BotSentenceSplitterConfiguration()
        self._client_context.bot._sentence_splitter = SentenceSplitter.initiate_sentence_splitter(
            config)
예제 #9
0
 def initiate_spellchecker(self):
     if self.configuration is not None:
         if self.configuration.spelling is not None:
             self._spell_checker = SpellingChecker.initiate_spellchecker(
                 self.configuration.spelling, self.client.storage_factory)