def test_load_regex(self): config = FileStorageConfiguration() config._regex_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "regex-templates.txt", fileformat="text", encoding="utf-8", delete_on_start=False) engine = FileStorageEngine(config) engine.initialise() store = FileRegexStore(engine) collection = RegexTemplatesCollection() store.load(collection) self.assertIsNotNone(store.get_regular_expressions()) self.assertTrue(collection.has_regex("anything")) self.assertEqual(re.compile('^.*$', re.IGNORECASE), collection.regex("anything")) self.assertTrue(collection.has_regex("legion")) self.assertFalse(collection.has_regex("XXXXX"))
def assert_upload_from_file(self, store): store.empty() store.upload_from_file( os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "regex-templates.txt") store.commit() collection = RegexTemplatesCollection() store.load(collection) self.assertTrue(collection.has_regex("anything")) self.assertEqual(re.compile('^.*$', re.IGNORECASE), collection.regex("anything")) self.assertTrue(collection.has_regex("legion")) self.assertFalse(collection.has_regex("XXXXX"))
def test_properties_operations(self): collection = RegexTemplatesCollection() self.assertIsNotNone(collection) collection.add_regex("name", ".*") self.assertTrue(collection.has_regex("name")) self.assertEqual(".*", collection.regex("name"))