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