Add tests for pluggable hooks.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2015-01-22 15:15:32 +00:00
parent 20a5e43043
commit ce8bed3006
No known key found for this signature in database
GPG key ID: BF535D811F52F68B

View file

@ -253,6 +253,10 @@ class ExampleFile(newfol.filemanip.FileFormat):
return [Record(['a', 'b'])] return [Record(['a', 'b'])]
class ExampleHook(newfol.filemanip.Hook):
pass
class PluggableBackendsTest(unittest.TestCase): class PluggableBackendsTest(unittest.TestCase):
def test_adding_backend(self): def test_adding_backend(self):
FileStorage.register_backend('example', ExampleFile) FileStorage.register_backend('example', ExampleFile)
@ -269,5 +273,18 @@ class PluggableBackendsTest(unittest.TestCase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
FileStorage.BACKENDS['example'] FileStorage.BACKENDS['example']
class PluggableHooksTest(unittest.TestCase):
def test_adding_hook(self):
FileStorage.register_hook('example', ExampleHook)
self.assertEqual(FileStorage.HOOKS['example'], ExampleHook)
def test_removing_hook(self):
FileStorage.register_hook('example', ExampleFile)
self.assertEqual(FileStorage.HOOKS['example'], ExampleFile)
FileStorage.unregister_hook('example')
with self.assertRaises(KeyError):
FileStorage.HOOKS['example']
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()