Beispiel #1
0
 def test_split_into_fields(self):
     store = Store()
     self.assertEquals(["FIELD1"], store.split_into_fields("FIELD1"))
     self.assertEquals(["FIELD1", "FIELD2"],
                       store.split_into_fields("FIELD1,FIELD2"))
     self.assertEquals(["FIELD1", "FIELD2", "FIELD3"],
                       store.split_into_fields("FIELD1,FIELD2,FIELD3"))
Beispiel #2
0
 def test_get_file_processor_csv(self):
     store = Store()
     self.assertIsInstance(
         store.get_file_processor(
             Store.CSV_FORMAT,
             os.path.dirname(__file__) + os.sep + "test.csv"),
         CSVFileReader)
Beispiel #3
0
 def test_upload_from_directory_without_subdir_with_ext(self):
     store = Store()
     final_count, final_success = store.upload_from_directory(
         os.path.dirname(__file__) + os.sep + "testdir",
         subdir=False,
         extension=".txt")
     self.assertEquals(2, final_count)
     self.assertEquals(0, final_success)
Beispiel #4
0
 def test_get_file_processor_other(self):
     store = Store()
     with self.assertRaises(Exception):
         self.assertIsInstance(
             store.get_file_processor(
                 "other",
                 os.path.dirname(__file__) + os.sep + "test.csv"),
             CSVFileReader)
Beispiel #5
0
 def test_upload_from_directory_with_subdir_no_commit(self):
     store = Store()
     final_count, final_success = store.upload_from_directory(
         os.path.dirname(__file__) + os.sep + "testdir",
         subdir=True,
         commit=False)
     self.assertEquals(5, final_count)
     self.assertEquals(0, final_success)
Beispiel #6
0
 def test_upload_from_directory_exception_no_commit(self):
     store = Store()
     final_count, final_success = store.upload_from_directory(
         os.path.dirname(__file__) + os.sep + "testdir",
         subdir=False,
         extension=".txt",
         commit=False)
     self.assertEquals(0, final_count)
     self.assertEquals(0, final_success)
Beispiel #7
0
 def test_get_just_filename_from_filepath(self):
     store = Store()
     self.assertEqual("", store.get_just_filename_from_filepath(""))
     self.assertEqual("TEST", store.get_just_filename_from_filepath("test"))
     self.assertEqual("TEST",
                      store.get_just_filename_from_filepath("test.txt"))
     self.assertEqual(
         "TEST",
         store.get_just_filename_from_filepath(
             os.path.dirname(__file__) + os.sep + "test.txt"))
Beispiel #8
0
    def upload_from_file(self, filename, format=Store.XML_FORMAT, commit=True, verbose=False):
        count = 0
        success = 0

        try:
            groupname = Store.get_just_filename_from_filepath(filename)
            if verbose is True:
                print(groupname)

            tree = ET.parse(filename, parser=LineNumberingParser())
            aiml = tree.getroot()

            for expression in aiml:
                tag_name, namespace = AIMLParser.tag_and_namespace_from_text(expression.tag)
                if tag_name == 'topic':
                    topic = expression.attrib['name']
                    for topic_expression in expression:
                        that = self.find_element_str("that", topic_expression, namespace)
                        pattern = self.find_element_str("pattern", topic_expression, namespace)
                        template = self.find_element_str("template", topic_expression, namespace)
                        if self.store_category(groupname, "*", topic, that, pattern, template) is True:
                            success += 1
                        count += 1

                elif tag_name == 'category':
                    topic = self.find_element_str("topic", expression, namespace)
                    that = self.find_element_str("that", expression, namespace)
                    pattern = self.find_element_str("pattern", expression, namespace)
                    template = self.find_element_str("template", expression, namespace)
                    if self.store_category(groupname, "*", topic, that, pattern, template) is True:
                        success += 1
                    count += 1

        except Exception as excep:
            YLogger.exception(self, "Failed to load contents of AIML file from [%s]", excep, filename)

        return count, success
Beispiel #9
0
 def __init__(self, storage_engine):
     Store.__init__(self)
     self._storage_engine = storage_engine
Beispiel #10
0
 def __init__(self, throw_except=False):
     Store.__init__(self)
     self.throw_except = throw_except
     self.processed = False
     self.committed = False
     self.rolled_back = False
Beispiel #11
0
 def test_process_line(self):
     store = Store()
     self.assertFalse(store.process_line("test", []))
Beispiel #12
0
 def test_get_split_char(self):
     store = Store()
     self.assertEquals(",", store.get_split_char())
Beispiel #13
0
 def test_upload_from_file_fileprocessor_none(self):
     store = Store()
     final_count, final_success = store.upload_from_file(
         os.path.dirname(__file__) + os.sep + "testdir")
     self.assertEquals(0, final_count)
     self.assertEquals(0, final_success)
Beispiel #14
0
 def test_get_file_processor_unknown(self):
     store = Store()
     with self.assertRaises(Exception):
         store.get_file_processor("UNKNOWN")
Beispiel #15
0
 def test_init(self):
     store = Store()
     self.assertIsNotNone(store)
Beispiel #16
0
 def __init__(self):
     Store.__init__(self)
Beispiel #17
0
 def test_get_file_processor_text(self):
     store = Store()
     self.assertIsInstance(
         store.get_file_processor(
             Store.TEXT_FORMAT,
             os.path.dirname(__file__) + os.sep + "test.txt"), TextFile)