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)
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)
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)
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)
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)
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")
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)
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)