[SQL-CVS] r260 - in trunk/SQLObject: sqlobject tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2004-10-02 01:06:15
|
Author: bbollenbach Date: 2004-10-01 16:53:10 -0400 (Fri, 01 Oct 2004) New Revision: 260 Modified: trunk/SQLObject/sqlobject/classregistry.py trunk/SQLObject/tests/test.py Log: Steve Alexander's patch to raise an error when the same SQLObject is defined more than once. I've added a test to prove that this works. Modified: trunk/SQLObject/sqlobject/classregistry.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/sqlobject/classregistry.py 2004-10-01 17:57:08 UTC (r= ev 259) +++ trunk/SQLObject/sqlobject/classregistry.py 2004-10-01 20:53:10 UTC (r= ev 260) @@ -65,6 +65,9 @@ that other classes can find it by name. We also call any callbacks that are waiting for the class. """ + if cls.__name__ in self.classes: + raise ValueError("class %s is already in the registry" + % cls.__name__) self.classes[cls.__name__] =3D cls if self.callbacks.has_key(cls.__name__): for callback, args, kw in self.callbacks[cls.__name__]: Modified: trunk/SQLObject/tests/test.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/tests/test.py 2004-10-01 17:57:08 UTC (rev 259) +++ trunk/SQLObject/tests/test.py 2004-10-01 20:53:10 UTC (rev 260) @@ -24,6 +24,32 @@ curr_db =3D None from sqlobject import cache =20 +class ClassRegistryTest(SQLObjectTest): + def testErrorOnDuplicateClassDefinition(self): + """Raise an error if a class is defined more than once.""" + class Duplicate(SQLObject): + pass + + try: + class Duplicate(SQLObject): + pass + except ValueError, err: + self.assertEqual(str(err), "class Duplicate is already in th= e registry") + else: + self.fail("should have raised an error on duplicate class de= finition") + +## class Billboard(SQLObject): +## message =3D StringCol() + +## class UnicodeTest(SQLObjectTest): +## classes =3D [Billboard] + +## def testUnicodeStrings(self): +## try: +## b =3D Billboard(message =3D u"foobar") +## except Exception, err: +## self.fail("shouldn't have raised an exception.") + ######################################## ## Basic operation ######################################## |