def test_init(self): client_config = ClientConfiguration() yaml = YamlConfigurationFile(client_config) self.assertIsNotNone(yaml) yaml.load_from_text( """ bot: license_keys: $BOT_ROOT/config/license.keys prompt: ">>>" initial_question: Hi, how can I help you today? default_response: Sorry, I don't have an answer for that! exit_response: So long, and thanks for the fish! override_predicates: true """, ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertEqual("./config/license.keys", bot_config.license_keys) self.assertEqual(">>>", bot_config.prompt) self.assertEqual("Hi, how can I help you today?", bot_config.initial_question) self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response) self.assertEqual("So long, and thanks for the fish!", bot_config.exit_response) self.assertTrue(bot_config.override_predicates)
def test_bot_defaultresponses(self): test_brain = Brain(BrainConfiguration()) bot = Bot(test_brain, BotConfiguration()) self.assertIsNotNone(bot) self.assertEqual(bot.prompt, ">>> ") self.assertEqual(bot.default_response, "Sorry, I don't have an answer for that right now") self.assertEqual(bot.exit_response, "Bye!")
def test_bot_chat_loop(self): test_brain = TestBrain(BrainConfiguration()) self.assertIsNotNone(test_brain) self.assertIsInstance(test_brain, Brain) bot = Bot(test_brain, BotConfiguration()) self.assertIsNotNone(bot) self.assertIsInstance(bot, Bot) test_brain.setresponse ("response1") response = bot.ask_question("testid", "hello") self.assertIsNotNone(response) self.assertEqual(response, "response1") test_brain.setresponse ("response2") response = bot.ask_question("testid", "hello again") self.assertIsNotNone(response) self.assertEqual(response, "response2") test_brain.setresponse("response3") response = bot.ask_question("testid", "goodbye") self.assertIsNotNone(response) self.assertEqual(response, "response3") conversation = bot.get_conversation("testid") self.assertIsNotNone(conversation) self.assertEqual(conversation.nth_question(3).sentence(0).text(), "hello") self.assertEqual(conversation.nth_question(3).sentence(0).response, "response1") self.assertEqual(conversation.nth_question(2).sentence(0).text(), "hello again") self.assertEqual(conversation.nth_question(2).sentence(0).response, "response2") self.assertEqual(conversation.nth_question(1).sentence(0).text(), "goodbye") self.assertEqual(conversation.nth_question(1).sentence(0).response, "response3")
class ClientConfiguration(object): def __init__(self): self._brain_config = BrainConfiguration() self._bot_config = BotConfiguration() @property def brain_configuration(self): return self._brain_config @property def bot_configuration(self): return self._bot_config def load_config_data(self, config_file, bot_root): self._brain_config.load_config_section(config_file, bot_root) self._bot_config.load_config_section(config_file, bot_root)
def setUp(self): self.bot = Bot(Brain(BrainConfiguration()), config=BotConfiguration()) self.bot.brain.denormals.process_splits([" dot com ", ".com"]) self.bot.brain.denormals.process_splits([" atsign ", "@"]) self.denormalize = DenormalizePostProcessor() self.punctuation = FormatPunctuationProcessor() self.numbers = FormatNumbersPostProcessor() self.multispaces = RemoveMultiSpacePostProcessor()
def test_init(self): client_config = ClientConfiguration() yaml = YamlConfigurationFile(client_config) self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: prompt: ">>>" initial_question: Hi, how can I help you today? default_response: Sorry, I don't have an answer for that! exit_response: So long, and thanks for the fish! """, ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertEqual(">>>", bot_config.prompt) self.assertEqual("Hi, how can I help you today?", bot_config.initial_question) self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response) self.assertEqual("So long, and thanks for the fish!", bot_config.exit_response)
def test_init(self): client_config = ClientConfiguration() yaml = YamlConfigurationFile(client_config) self.assertIsNotNone(yaml) yaml.load_from_text( """ bot: prompt: ">>>" initial_question: Hi, how can I help you today? default_response: Sorry, I don't have an answer for that! exit_response: So long, and thanks for the fish! """, ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertEqual(">>>", bot_config.prompt) self.assertEqual("Hi, how can I help you today?", bot_config.initial_question) self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response) self.assertEqual("So long, and thanks for the fish!", bot_config.exit_response)
def test_bot_with_conversation(self): test_brain = TestBrain(BrainConfiguration()) self.assertIsNotNone(test_brain) bot = Bot(test_brain, BotConfiguration()) self.assertIsNotNone(bot) self.assertFalse(bot.has_conversation("testid")) response = bot.ask_question("testid", "hello") self.assertIsNotNone(response) self.assertTrue(bot.has_conversation("testid")) response = bot.ask_question("testid", "hello") self.assertIsNotNone(response) self.assertTrue(bot.has_conversation("testid")) response = bot.ask_question("testid2", "hello") self.assertIsNotNone(response) self.assertTrue(bot.has_conversation("testid2"))
def setUp(self): self.bot = Bot(Brain(BrainConfiguration()), config=BotConfiguration())
def test_conversation(self): test_brain = Brain(BrainConfiguration()) test_bot = Bot(test_brain, BotConfiguration()) conversation = Conversation("test", test_bot, max_histories=3) self.assertIsNotNone(conversation) self.assertIsNotNone(conversation._bot) self.assertIsNotNone(conversation._clientid) self.assertEqual(conversation._clientid, "test") self.assertEqual(0, len(conversation._questions)) self.assertEqual(3, conversation._max_histories) self.assertEqual(1, len(conversation._predicates)) with self.assertRaises(Exception): conversation.current_question() with self.assertRaises(Exception): conversation.nth_question(0) question1 = Question.create_from_text("Hello There") conversation.record_dialog(question1) self.assertEqual(1, len(conversation.all_sentences())) self.assertEqual(question1, conversation.current_question()) self.assertEqual(question1, conversation.nth_question(1)) with self.assertRaises(Exception): conversation.nth_question(2) questions = conversation.all_sentences() self.assertEqual(1, len(questions)) question2 = Question.create_from_text("Hello There Again") conversation.record_dialog(question2) self.assertEqual(2, len(conversation.all_sentences())) self.assertEqual(question2, conversation.current_question()) self.assertEqual(question2, conversation.nth_question(1)) with self.assertRaises(Exception): conversation.nth_question(3) questions = conversation.all_sentences() self.assertEqual(2, len(questions)) question3 = Question.create_from_text("Hello There Again Again") conversation.record_dialog(question3) self.assertEqual(3, len(conversation.all_sentences())) self.assertEqual(question3, conversation.current_question()) self.assertEqual(question3, conversation.nth_question(1)) with self.assertRaises(Exception): conversation.nth_question(4) questions = conversation.all_sentences() self.assertEqual(3, len(questions)) # Max Histories for this test is 3 # Therefore we should see the first question, pop of the stack question4 = Question.create_from_text("Hello There Again Again Again") conversation.record_dialog(question4) self.assertEqual(3, len(conversation.all_sentences())) self.assertEqual(question4, conversation.current_question()) self.assertEqual(question4, conversation.nth_question(1)) with self.assertRaises(Exception): conversation.nth_question(5) questions = conversation.all_sentences() self.assertEqual(3, len(questions))
def setUp(self): self.bot = Bot(Brain(BrainConfiguration()), config=BotConfiguration()) self.bot.brain.denormals.process_splits([" dot com ", ".com"])
def test_bot_init_supplied_brain(self): test_brain = Brain(BrainConfiguration()) bot = Bot(test_brain, BotConfiguration()) self.assertIsNotNone(bot) self.assertIsNotNone(bot.brain)
def __init__(self): Bot.__init__(self, Brain(BrainConfiguration()), BotConfiguration()) self._response = "Unknown"
def __init__(self): self._brain_config = BrainConfiguration() self._bot_config = BotConfiguration()