Esempio n. 1
0
    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))

        question = Question.create_from_text("Hello There")
        conversation.record_dialog(question)
        self.assertEqual(1, len(conversation._questions))

        question = Question.create_from_text("Hello There Again")
        conversation.record_dialog(question)
        self.assertEqual(2, len(conversation._questions))

        question = Question.create_from_text("Hello There Again Again")
        conversation.record_dialog(question)
        self.assertEqual(3, len(conversation._questions))

        question = Question.create_from_text("Hello There Again Again Again")
        conversation.record_dialog(question)
        self.assertEqual(3, len(conversation._questions))
Esempio n. 2
0
    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")
Esempio n. 3
0
 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!")
Esempio n. 4
0
    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"))
Esempio n. 5
0
    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)
Esempio n. 6
0
 def setUp(self):
     self.bot = Bot(Brain(BrainConfiguration()), config=BotConfiguration())
Esempio n. 7
0
 def test_bot_init_supplied_brain(self):
     test_brain = Brain(BrainConfiguration())
     bot = Bot(test_brain, BotConfiguration())
     self.assertIsNotNone(bot)
     self.assertIsNotNone(bot.brain)
Esempio n. 8
0
 def __init__(self):
     Bot.__init__(self, Brain(BrainConfiguration()), BotConfiguration())
     self._response = "Unknown"