[testlib] require explicite overwriting of TestDataBaseHandler. oldstable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 17 Mar 2011 12:03:50 +0100
brancholdstable
changeset 7090 d9e6e79e023a
parent 7078 bad26a22fe29
child 7091 8052d2452b9c
child 7092 076c5be627f6
[testlib] require explicite overwriting of TestDataBaseHandler. A new overwrite (default to False) parametters is added.
devtools/__init__.py
--- a/devtools/__init__.py	Tue Dec 07 12:18:20 2010 +0100
+++ b/devtools/__init__.py	Thu Mar 17 12:03:50 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)