コード例 #1
0
ファイル: test_input.py プロジェクト: zippyy/program-y
    def test_resolve_with_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateInputNode()
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(0, node.index)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(
            self._client_context, "Hello world",
            self._client_context.bot.sentence_splitter)
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        self._client_context.bot._conversation_mgr._conversations[
            "testid"] = conversation

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "Hello world")
コード例 #2
0
ファイル: test_request.py プロジェクト: Freiza/program-y
    def test_resolve_no_sentence(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateRequestNode(index=3)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(3, node.index)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you. Are you well")
        question.current_sentence()._response = "Fine thanks"
        conversation.record_dialog(question)

        self._client_context.bot._conversations["testid"] = conversation

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "")
コード例 #3
0
ファイル: bot.py プロジェクト: minhdc/documented-programy
    def get_conversation(self, client_context):
        '''
            Nếu user.id tồn tại trong conversations hiện thời thì load convo này ra
            Nếu không thì khởi tạo 1 convo mới dựa trên ClientContext hiện tại
                Không chỉ khởi tạo mà còn load convo này
        '''
        # TODO move this to Conversations base class
        if client_context.userid in self._conversations:
            YLogger.info(client_context,
                         "Retrieving conversation for client %s",
                         client_context.userid)
            return self._conversations[client_context.userid]

        else:
            YLogger.info(client_context,
                         "Creating new conversation for client %s",
                         client_context.userid)

            conversation = Conversation(client_context)

            if client_context.brain.properties is not None:
                conversation.load_initial_variables(
                    client_context.brain.variables)

            self._conversations[client_context.userid] = conversation

            self.load_conversation(client_context.userid)

            return conversation
コード例 #4
0
ファイル: conversation.py プロジェクト: zippyy/program-y
    def get_conversation(self, client_context):

        assert (client_context is not None)
        assert (client_context.userid  is not None)

        if client_context.userid in self._conversations:
            YLogger.info(client_context, "Retrieving conversation for client %s", client_context.userid)
            conversation = self._conversations[client_context.userid]

            # Load existing conversation from cache
            if self.configuration.multi_client:
                if self._conversation_storage is not None:
                    self._conversation_storage.load_conversation(client_context, conversation)

        else:
            YLogger.info(client_context, "Creating new conversation for client %s", client_context.userid)

            conversation = Conversation(client_context)

            if client_context.brain.default_variables is not None:
                conversation.load_initial_variables(client_context.brain.default_variables)

            self._conversations[client_context.userid] = conversation

            if self._conversation_storage is not None:
                self._conversation_storage.load_conversation(client_context, conversation)

            if self.configuration.restore_last_topic is True:
                pass

        return conversation
コード例 #5
0
    def assert_conversation_storage(self,
                                    store,
                                    can_empty=True,
                                    test_load=True):

        if can_empty is True:
            store.empty()

        client = TestClient()
        client_context = client.create_client_context("user1")

        conversation = Conversation(client_context)

        question1 = Question.create_from_text(client_context, "Hello There")
        question1.sentence(0).response = "Hi"
        conversation.record_dialog(question1)

        store.store_conversation(client_context, conversation)
        store.commit()

        if test_load is True:
            conversation2 = Conversation(client_context)
            store.load_conversation(client_context, conversation2)

            self.assertEqual(1, len(conversation2.questions))
            self.assertEqual(1, len(conversation2.questions[0].sentences))
            self.assertEqual("Hello There",
                             conversation2.questions[0].sentences[0].text())
            self.assertEqual("Hi",
                             conversation2.questions[0].sentences[0].response)
コード例 #6
0
ファイル: test_response.py プロジェクト: Freiza/program-y
    def test_resolve_with_no_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateResponseNode(index=1)
        self.assertIsNotNone(node)
        self.assertEqual(1, node.index)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello1 question")
        question.current_sentence()._response = "Hello1 response"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello quesiton2")
        question.current_sentence()._response = "Hello2 response"
        conversation.record_dialog(question)

        self._client_context.bot._conversations["testid"] = conversation

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "Hello1 response")
コード例 #7
0
ファイル: test_conversation.py プロジェクト: zippyy/program-y
    def test_init_context_and_converstion(self):

        client = TestClient()
        client_context = client.create_client_context("tesuser")

        convo = Convo(client_context)

        question = Question.create_from_text(client_context, "Hello world")
        question.current_sentence()._response = "Hello matey"
        convo.record_dialog(question)

        conversation = Conversation(client_context, convo)
        self.assertIsNotNone(conversation)

        self.assertEqual(client_context.client.id, conversation.clientid)
        self.assertEqual(client_context.userid, conversation.userid)
        self.assertEqual(client_context.bot.id, conversation.botid)
        self.assertEqual(client_context.brain.id, conversation.brainid)
        self.assertIsNotNone(conversation.conversation)

        doc = conversation.to_document()
        self.assertEqual({'clientid': 'testclient', 'userid': 'tesuser', 'botid': 'bot', 'brainid': 'brain', 'conversation': {'client_context': {'clientid': 'testclient', 'userid': 'tesuser', 'botid': 'bot', 'brainid': 'brain', 'depth': 0}, 'questions': [{'sentences': [{'question': 'Hello world', 'response': 'Hello matey'}], 'srai': False, 'properties': {}, 'current_sentence_no': -1}], 'max_histories': 100, 'properties': {'topic': '*'}}},
                          doc)

        conversation2 = Conversation.from_document(client_context, doc)
        self.assertIsNotNone(conversation2)
        self.assertEqual(conversation2.clientid, conversation.clientid)
        self.assertEqual(conversation2.userid, conversation.userid)
        self.assertEqual(conversation2.botid, conversation.botid)
        self.assertEqual(conversation2.brainid, conversation.brainid)
コード例 #8
0
ファイル: test_star.py プロジェクト: nitinpanuganti/program-y
    def test_node_no_sentences(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation("testid", self._bot)
        question = Question()
        conversation.record_dialog(question)
        self._bot._conversations["testid"] = conversation

        self.assertEqual("", root.resolve(self._bot, self._clientid))
コード例 #9
0
ファイル: test_star.py プロジェクト: Freiza/program-y
    def test_node_no_sentences(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation(self._client_context)
        question = Question()
        conversation.record_dialog(question)
        self._client_context.bot._conversations["testid"] = conversation

        self.assertEqual("", root.resolve(self._client_context))
コード例 #10
0
    def test_store_conversation(self):
        client = TestClient()
        client_context = client.create_client_context("user1")

        conversation = Conversation(client_context)

        question1 = Question.create_from_text(client_context, "Hello There")
        question1.sentence(0).response = "Hi"
        conversation.record_dialog(question1)

        convo_store = ConversationStore()
        with self.assertRaises(NotImplementedError):
            convo_store.store_conversation(client_context, conversation)
コード例 #11
0
ファイル: test_topicstar.py プロジェクト: zippyy/program-y
    def test_resolve_no_defaults_inside_topic(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateTopicStarNode(index=1)
        self.assertIsNotNone(node)
        self.assertEqual(1, node.index)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(self._client_context, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._client_context, "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)

        match = PatternOneOrMoreWildCardNode("*")
        context = MatchContext(max_search_depth=100, max_search_timeout=-1, tokenizer=self._client_context.brain.tokenizer)
        context.add_match(Match(Match.TOPIC, match, "Matched"))
        question.current_sentence()._matched_context = context
        conversation.record_dialog(question)

        self._client_context.bot._conversation_mgr._conversations["testid"] = conversation

        self.assertEqual("Matched", node.resolve(self._client_context))
コード例 #12
0
ファイル: test_star.py プロジェクト: zippyy/program-y
    def test_node_with_star(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation(self._client_context)
        question = Question.create_from_text(
            self._client_context, "Hello world",
            self._client_context.bot.sentence_splitter)
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)
        question = Question.create_from_text(
            self._client_context, "How are you",
            self._client_context.bot.sentence_splitter)
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)
        match = PatternOneOrMoreWildCardNode("*")
        context = MatchContext(max_search_depth=100,
                               max_search_timeout=-1,
                               tokenizer=self._client_context.brain.tokenizer)
        context.add_match(Match(Match.WORD, match, "Matched"))
        question.current_sentence()._matched_context = context

        conversation.record_dialog(question)
        self._client_context.bot._conversation_mgr._conversations[
            "testid"] = conversation

        self.assertEqual("Matched", root.resolve(self._client_context))
コード例 #13
0
ファイル: test_utils.py プロジェクト: zippyy/program-y
    def conversation_asserts(self, storage_engine, visit=True):

        client = TestClient()
        client_context = client.create_client_context("user1")

        conversation = Conversation(client_context)

        question1 = Question.create_from_text(client_context, "Hello There")
        question1.sentence(0).response = "Hi"
        conversation.record_dialog(question1)

        convo_store = storage_engine.conversation_store()
        convo_store.store_conversation(client_context, conversation)
        convo_store.commit()
コード例 #14
0
ファイル: test_star.py プロジェクト: Freiza/program-y
    def test_node_no_star(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation(self._client_context)
        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)
        question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)
        self._client_context.bot._conversations["testid"] = conversation

        self.assertEqual("", root.resolve(self._client_context))
コード例 #15
0
    def test_resolve_with_no_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateRequestNode(index=1)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(1, node.index)

        conversation = Conversation(self._client_context)
        self._client_context.bot._conversations["testid"] = conversation

        question = Question.create_from_text(
            self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation._questions.append(question)

        question = Question.create_from_text(
            self._client_context.brain.tokenizer, "What did you say")
        question.current_sentence()._response = "Hello matey"
        conversation._questions.append(question)

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "Hello world")
コード例 #16
0
ファイル: test_topicstar.py プロジェクト: Freiza/program-y
    def test_resolve_no_defaults_inside_topic(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateTopicStarNode(index=1)
        self.assertIsNotNone(node)
        self.assertEqual(1, node.index)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)

        match = PatternOneOrMoreWildCardNode("*")
        context = MatchContext(max_search_depth=100, max_search_timeout=-1, tokenizer=self._client_context.brain.tokenizer)
        context.add_match(Match(Match.TOPIC, match, "Matched"))
        question.current_sentence()._matched_context = context
        conversation.record_dialog(question)

        self._client_context.bot._conversations["testid"] = conversation

        self.assertEqual("Matched", node.resolve(self._client_context))
コード例 #17
0
ファイル: test_star.py プロジェクト: nitinpanuganti/program-y
    def test_node_no_question(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation("testid", self._bot)
        self._bot._conversations["testid"] = conversation

        self.assertEqual("", root.resolve(self._bot, self._clientid))
コード例 #18
0
    def get_conversation(self, client_context):
        # TODO move this to Conversations base class
        if client_context.userid in self._conversations:
            YLogger.info(client_context, "Retrieving conversation for client %s", client_context.userid)
            return self._conversations[client_context.userid]

        else:
            YLogger.info(client_context, "Creating new conversation for client %s", client_context.userid)

            conversation = Conversation(client_context)

            if client_context.brain.properties is not None:
                conversation.load_initial_variables(client_context.brain.variables)

            self._conversations[client_context.userid] = conversation

            self.load_conversation(client_context.userid)

            return conversation
コード例 #19
0
ファイル: test_redis.py プロジェクト: Freiza/program-y
    def test_persistence(self):

        storage_config = BotConversationsRedisStorageConfiguration("redis")
        redis = ConversationRedisStorage(storage_config)
        self.assertIsNotNone(redis)

        client = TestClient()
        client_context = client.create_client_context("testid")
        conversation1 = Conversation(client_context)
        conversation1.set_property("topic", "topic1")

        redis.save_conversation(conversation1, client_context.userid)

        conversation2 = Conversation(client_context)
        redis.load_conversation(conversation2, client_context.userid)
        self.assertIsNotNone(conversation2)
        self.assertIsNotNone(conversation2.properties)

        self.assertEquals(conversation1.properties, conversation2.properties)
コード例 #20
0
    def test_persistence(self):

        storage_config = BotConversationsRedisStorageConfiguration("redis")
        redis = ConversationRedisStorage(storage_config)
        self.assertIsNotNone(redis)

        client = TestClient()
        client_context = client.create_client_context("testid")
        conversation1 = Conversation(client_context)
        conversation1.set_property("topic", "topic1")

        redis.save_conversation(conversation1, client_context.userid)

        conversation2 = Conversation(client_context)
        redis.load_conversation(conversation2, client_context.userid)
        self.assertIsNotNone(conversation2)
        self.assertIsNotNone(conversation2.properties)

        self.assertEqual(conversation1.properties, conversation2.properties)
コード例 #21
0
    def get_conversation(self, clientid: str):
        # TODO move this to Conversations base class
        if clientid in self._conversations:
            if logging.getLogger().isEnabledFor(logging.INFO):
                logging.info("Retrieving conversation for client %s", clientid)
            return self._conversations[clientid]
        else:
            if logging.getLogger().isEnabledFor(logging.INFO):
                logging.info("Creating new conversation for client %s",
                             clientid)

            conversation = Conversation(clientid, self)

            if self.brain.properties is not None:
                conversation.load_initial_variables(self.brain.variables)

            self._conversations[clientid] = conversation

            self.load_conversation(clientid)

            return conversation
コード例 #22
0
    def test_resolve_no_sentence(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateRequestNode(index=3)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(3, node.index)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(
            self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(
            self._client_context.brain.tokenizer, "How are you. Are you well")
        question.current_sentence()._response = "Fine thanks"
        conversation.record_dialog(question)

        self._client_context.bot._conversations["testid"] = conversation

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "")
コード例 #23
0
    def test_resolve_with_no_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateThatNode(question=1, sentence=1)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(1, node.question)
        self.assertEqual(1, node.sentence)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)

        self._client_context.bot._conversations["testid"] = conversation

        self.assertEqual("Hello matey", node.resolve(self._client_context))
コード例 #24
0
    def test_resolve_with_no_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateResponseNode(index=1)
        self.assertIsNotNone(node)
        self.assertEqual(1, node.index)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        conversation = Conversation("testid", self._bot)

        question = Question.create_from_text(self._bot.brain.tokenizer,
                                             "Hello1 question")
        question.current_sentence()._response = "Hello1 response"
        conversation.record_dialog(question)

        question = Question.create_from_text(self._bot.brain.tokenizer,
                                             "Hello quesiton2")
        question.current_sentence()._response = "Hello2 response"
        conversation.record_dialog(question)

        self._bot._conversations["testid"] = conversation

        response = root.resolve(self._bot, "testid")
        self.assertIsNotNone(response)
        self.assertEqual(response, "Hello1 response")
コード例 #25
0
    def test_parse_last_sentences_from_response(self):

        client = TestClient()
        client_context = ClientContext(client, "testid")
        client_context.bot = Bot(BotConfiguration(), client)
        client_context.bot.configuration.conversations._max_histories = 3
        client_context.brain = client_context.bot.brain

        conversation = Conversation(client_context)
        self.assertIsNotNone(conversation)

        response = "Hello World"
        that = conversation.parse_last_sentences_from_response(response)
        self.assertEqual("Hello World", that)

        response = "Hello World. Second sentence"
        that = conversation.parse_last_sentences_from_response(response)
        self.assertEqual("Second sentence", that)

        response = "Hello World. Second sentence. Third Sentence"
        that = conversation.parse_last_sentences_from_response(response)
        self.assertEqual("Third Sentence", that)
コード例 #26
0
ファイル: test_star.py プロジェクト: nitinpanuganti/program-y
    def test_node_no_star(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation("testid", self._bot)
        question = Question.create_from_text(self._bot.brain.tokenizer,
                                             "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)
        question = Question.create_from_text(self._bot.brain.tokenizer,
                                             "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)
        self._bot._conversations["testid"] = conversation

        self.assertEqual("", root.resolve(self._bot, self._clientid))
コード例 #27
0
ファイル: test_star.py プロジェクト: Freiza/program-y
    def test_node_with_star(self):
        root = TemplateNode()
        node = TemplateStarNode()
        root.append(node)

        conversation = Conversation(self._client_context)
        question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)
        question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you")
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)
        match = PatternOneOrMoreWildCardNode("*")
        context = MatchContext(max_search_depth=100, max_search_timeout=-1, tokenizer=self._client_context.brain.tokenizer)
        context.add_match(Match(Match.WORD, match, "Matched"))
        question.current_sentence()._matched_context = context

        conversation.record_dialog(question)
        self._client_context.bot._conversations["testid"] = conversation

        self.assertEqual("Matched", root.resolve(self._client_context))
コード例 #28
0
    def test_node_no_star(self):
        root = TemplateNode()
        node = TemplateThatStarNode()
        root.append(node)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(
            self._client_context, "Hello world",
            self._client_context.bot.sentence_splitter)
        question.current_sentence()._response = "Hello matey"
        conversation.record_dialog(question)

        question = Question.create_from_text(
            self._client_context, "How are you",
            self._client_context.bot.sentence_splitter)
        question.current_sentence()._response = "Very well thanks"
        conversation.record_dialog(question)

        self._client_context.bot._conversation_mgr._conversations[
            "testid"] = conversation

        self.assertEqual("", root.resolve(self._client_context))
コード例 #29
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(test_bot.brain.tokenizer,
                                              "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(test_bot.brain.tokenizer,
                                              "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(test_bot.brain.tokenizer,
                                              "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(test_bot.brain.tokenizer,
                                              "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)
コード例 #30
0
    def test_conversation(self):

        client = TestClient()
        client_context = ClientContext(client, "testid")
        client_context.bot = Bot(BotConfiguration(), client)
        client_context.bot.configuration.conversations._max_histories = 3
        client_context.brain = client_context.bot.brain

        conversation = Conversation(client_context)
        self.assertIsNotNone(conversation)
        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(client_context, "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(client_context,
                                              "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(client_context,
                                              "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(client_context,
                                              "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)
コード例 #31
0
ファイル: test_dialog.py プロジェクト: Freiza/program-y
    def test_conversation(self):

        client_context = ClientContext(TestClient(), "testid")
        client_context.bot = Bot(BotConfiguration())
        client_context.bot.configuration.conversations._max_histories = 3
        client_context.brain = client_context.bot.brain

        conversation = Conversation(client_context)
        self.assertIsNotNone(conversation)
        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(client_context.brain.tokenizer, "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(client_context.brain.tokenizer, "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(client_context.brain.tokenizer, "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(client_context.brain.tokenizer, "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)