diff --git a/lib/newfol/filemanip.py b/lib/newfol/filemanip.py index 6e23f93..d1a0f29 100644 --- a/lib/newfol/filemanip.py +++ b/lib/newfol/filemanip.py @@ -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: diff --git a/test/testfilemanip.py b/test/testfilemanip.py index 091f047..d9adc2a 100755 --- a/test/testfilemanip.py +++ b/test/testfilemanip.py @@ -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()