def test_sentence_creation_one_word(self): sentence = Sentence(self._client_context, "One") self.assertIsNotNone(sentence) self.assertEqual(1, sentence.num_words()) with self.assertRaises(Exception): sentence.sentence.word(1) self.assertEqual("One", sentence.text(self._client_context))
def test_sentence_creation_one_word(self): sentence = Sentence(self._bot.brain.tokenizer, "One") self.assertIsNotNone(sentence) self.assertEqual(1, sentence.num_words()) with self.assertRaises(Exception): sentence.sentence.word(1) self.assertEqual("One", sentence.text())
def test_question_create_from_sentence(self): sentence = Sentence(self._client_context.brain.tokenizer, "One Two Three") question = Question.create_from_sentence(sentence) self.assertIsNotNone(question) self.assertEqual(1, len(question.sentences)) self.assertEqual(sentence.text(), question.sentence(0).text()) with self.assertRaises(Exception): question.sentence(1)
def test_sentence_creation_two_words(self): sentence = Sentence(self._bot.brain.tokenizer, "One Two") self.assertIsNotNone(sentence) self.assertEqual(2, sentence.num_words()) self.assertEqual("One", sentence.word(0)) self.assertEqual("Two", sentence.word(1)) self.assertIsNone(sentence.word(2)) self.assertEqual("One Two", sentence.text())
def test_split_into_words(self): sentence = Sentence(self._bot.brain.tokenizer, "HELLO") self.assertIsNotNone(sentence) self.assertEqual(1, sentence.num_words()) self.assertEqual("HELLO", sentence.word(0)) self.assertEqual("HELLO", sentence.words_from_current_pos(0)) self.assertIsNone(sentence.word(1)) self.assertEqual("HELLO", sentence.text())
def test_words_from_current_pos(self): sentence = Sentence(self._bot.brain.tokenizer, "One Two Three") self.assertIsNotNone(sentence) self.assertEqual("One Two Three", sentence.words_from_current_pos(0)) self.assertEqual("Two Three", sentence.words_from_current_pos(1)) self.assertEqual("Three", sentence.words_from_current_pos(2)) with self.assertRaises(Exception): self.assertEqual("Three", sentence.words_from_current_pos(3)) self.assertEqual("One Two Three", sentence.text())
def test_sentence_creation_two_words_diff_split_char(self): tokenizer = Tokenizer(",") sentence = Sentence(tokenizer, "One,Two",) self.assertIsNotNone(sentence) self.assertEqual(2, sentence.num_words()) self.assertEqual("One", sentence.word(0)) self.assertEqual("Two", sentence.word(1)) self.assertIsNone(sentence.word(2)) self.assertEqual("One,Two", sentence.text())
def test_split_into_words(self): sentence = Sentence(self._client_context, "HELLO") self.assertIsNotNone(sentence) self.assertEqual(1, sentence.num_words()) self.assertEqual("HELLO", sentence.word(0)) self.assertEqual( "HELLO", sentence.words_from_current_pos(self._client_context, 0)) with self.assertRaises(Exception): sentence.sentence.word(1) self.assertEqual("HELLO", sentence.text(self._client_context))
def test_words_from_current_pos(self): sentence = Sentence(self._client_context, "One Two Three") self.assertIsNotNone(sentence) self.assertEqual( "One Two Three", sentence.words_from_current_pos(self._client_context, 0)) self.assertEqual( "Two Three", sentence.words_from_current_pos(self._client_context, 1)) self.assertEqual( "Three", sentence.words_from_current_pos(self._client_context, 2)) with self.assertRaises(Exception): self.assertEqual( "Three", sentence.words_from_current_pos(self._client_context, 3)) self.assertEqual("One Two Three", sentence.text(self._client_context))
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")