Add support for removing file format backends.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2015-01-11 17:03:34 +00:00
parent 8c71535123
commit bb3f89f9b0
No known key found for this signature in database
GPG key ID: BF535D811F52F68B
2 changed files with 13 additions and 0 deletions

View file

@ -567,6 +567,13 @@ class FileStorage:
def register_backend(klass, name, obj):
klass.BACKENDS[name] = obj
@classmethod
def unregister_backend(klass, name):
try:
del klass.BACKENDS[name]
except KeyError:
pass
@staticmethod
def _canonicalize_transaction_types(types):
if types is None:

View file

@ -262,6 +262,12 @@ class PluggableBackendsTest(unittest.TestCase):
self.assertEqual(len(recs), 1)
self.assertEqual(recs[0].fields, ['a', 'b'])
def test_removing_backend(self):
FileStorage.register_backend('example', ExampleFile)
self.assertEqual(FileStorage.BACKENDS['example'], ExampleFile)
FileStorage.unregister_backend('example')
with self.assertRaises(KeyError):
FileStorage.BACKENDS['example']
if __name__ == '__main__':
unittest.main()