Exemple #1
0
    def test_find_element_str_not_present(self):
        aiml = ET.fromstring("""
            <category>
                <pattern>HI</pattern>
            </category>
        """)

        store = CategoryReadOnlyStore()
        found = store.find_element_str("topic", aiml)
        self.assertEqual("*", found)
Exemple #2
0
    def test_find_element_str_multi_elements(self):
        aiml = ET.fromstring("""
            <category>
                <pattern>HI</pattern>
                <pattern>HI</pattern>
            </category>
        """)

        store = CategoryReadOnlyStore()
        with self.assertRaises(Exception):
            _ = store.find_element_str("pattern", aiml)
Exemple #3
0
    def test_load_category(self):
        client = CategoryTestClient()
        client_context = client.create_client_context("test1")
        parser = client_context.brain.aiml_parser

        store = CategoryReadOnlyStore()
        store._load_category("group1", "HELLO", "*", "*", "Test Hello!",
                             parser)

        match = parser.match_sentence(client_context,
                                      Sentence(client_context, "HELLO"), "*",
                                      "*")
        self.assertIsNotNone(match)
Exemple #4
0
    def test_load_category_parser_exception2(self):
        client = CategoryTestClient()
        client_context = client.create_client_context("test1")
        parser = client_context.brain.aiml_parser
        parser.brain.configuration.debugfiles._save_errors = True
        parser.brain.configuration.debugfiles._save_duplicates = True
        parser.create_debug_storage()

        store = CategoryReadOnlyStore()
        self.assertEqual(0, len(parser._duplicates))
        store._load_category("group1", "HELLO", "*", "*", "Test Hello!",
                             parser)

        match = parser.match_sentence(client_context,
                                      Sentence(client_context, "HELLO"), "*",
                                      "*")
        self.assertIsNone(match)
Exemple #5
0
    def test_find_all_no_namespace(self):
        aiml = ET.fromstring("""
            <topic>
                    <category>
                        <pattern>HI</pattern>
                        <template>RESPONSE</template>
                    </category>
                    <category>
                        <pattern>HELLO</pattern>
                        <template>RESPONSE</template>
                    </category>
            </topic>
        """)

        store = CategoryReadOnlyStore()
        found = store.find_all(aiml, "category")
        self.assertIsNotNone(found)
        self.assertEqual(2, len(found))
Exemple #6
0
    def test_find_all_with_namespace(self):
        aiml = ET.fromstring("""<?xml version="1.0" encoding="ISO-8859-1"?>
            <a:aiml version="1.01"
                  xmlns="http://alicebot.org/2001/AIML"
                  xmlns:a="http://alicebot.org/2001/AIML"
                  xmlns:html="http://www.w3.org/TR/REC-html40">
                  <a:topic>
                    <a:category>
                        <a:pattern>HI</a:pattern>
                        <a:template>RESPONSE</a:template>
                    </a:category>
                    <a:category>
                        <a:pattern>HELLO</a:pattern>
                        <a:template>RESPONSE</a:template>
                    </a:category>
                  </a:topic>
            </a:aiml>
        """)

        store = CategoryReadOnlyStore()
        found = store.find_all(aiml, "topic",
                               {"a": "http://alicebot.org/2001/AIML"})
        self.assertIsNotNone(found)
        self.assertEqual(1, len(found))
Exemple #7
0
 def test_extract_not_found(self):
     xml = ET.fromstring("<text>test</text>")
     result = CategoryReadOnlyStore.extract_content("other", xml)
     self.assertEquals(None, result)
Exemple #8
0
 def test_extract_content(self):
     xml = ET.fromstring("<text>test</text>")
     result = CategoryReadOnlyStore.extract_content("text", xml)
     self.assertEquals("test", result)
Exemple #9
0
 def __init__(self, storage_engine):
     FileStore.__init__(self, storage_engine)
     CategoryReadOnlyStore.__init__(self)