merge: [testlib] require explicite overwriting of TestDataBaseHandler. stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 17 Mar 2011 12:07:08 +0100
branchstable
changeset 7091 8052d2452b9c
parent 7089 6c6e0fbd0605 (current diff)
parent 7090 d9e6e79e023a (diff)
child 7094 4f9f13a50484
merge: [testlib] require explicite overwriting of TestDataBaseHandler. A new overwrite (default to False) parametters is added.
--- a/devtools/__init__.py	Thu Mar 17 11:38:52 2011 +0100
+++ b/devtools/__init__.py	Thu Mar 17 12:07:08 2011 +0100
@@ -698,9 +698,14 @@
 
 HANDLERS = {}
 
-def register_handler(handlerkls):
+def register_handler(handlerkls, overwrite=False):
     assert handlerkls is not None
-    HANDLERS[handlerkls.DRIVER] = handlerkls
+    if overwrite or handlerkls.DRIVER not in HANDLERS:
+        HANDLERS[handlerkls.DRIVER] = handlerkls
+    else:
+        msg = "%s: Handler already exists use overwrite if it's intended\n"
+              "(existing handler class is %r)"
+        raise ValueError(msg % (handlerkls.DRIVER, HANDLERS[handlerkls.DRIVER]))
 
 register_handler(PostgresTestDataBaseHandler)
 register_handler(SQLiteTestDataBaseHandler)