Exemplo n.º 1
0
    def test_conversation(self):
        brain_config = BrainConfiguration()
        test_brain = Brain(brain_config)
        bot_config = BotConfiguration()
        bot_config.conversations._max_histories = 3
        test_bot = Bot(test_brain, bot_config)

        conversation = Conversation("test", test_bot)
        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._properties))

        with self.assertRaises(Exception):
            conversation.current_question()
        with self.assertRaises(Exception):
            conversation.previous_nth_question(0)

        question1 = Question.create_from_text("Hello There")
        conversation.record_dialog(question1)
        self.assertEqual(question1, conversation.current_question())
        with self.assertRaises(Exception):
            conversation.previous_nth_question(1)

        question2 = Question.create_from_text("Hello There Again")
        conversation.record_dialog(question2)
        self.assertEqual(question2, conversation.current_question())
        self.assertEqual(question1, conversation.previous_nth_question(1))
        with self.assertRaises(Exception):
            conversation.previous_nth_question(3)

        question3 = Question.create_from_text("Hello There Again Again")
        conversation.record_dialog(question3)
        self.assertEqual(question3, conversation.current_question())
        self.assertEqual(question2, conversation.previous_nth_question(1))
        with self.assertRaises(Exception):
            conversation.previous_nth_question(4)

        # 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(question4, conversation.current_question())
        self.assertEqual(question3, conversation.previous_nth_question(1))
        with self.assertRaises(Exception):
            conversation.previous_nth_question(5)
Exemplo n.º 2
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))

        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))
Exemplo n.º 3
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))

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