]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- repair were-never-working instrumentation tests
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 May 2009 21:03:41 +0000 (21:03 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 May 2009 21:03:41 +0000 (21:03 +0000)
- use nicer py3k reraise style detailed in pep3109 (directly affects how the traceback is formatted vs. with_traceback())
- seriously considering writing regular tests for sqlsoup since this is going to be impossible to 2to3-ize

lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/strategies.py
lib/sqlalchemy/ext/sqlsoup.py
lib/sqlalchemy/orm/identity.py
test/orm/instrumentation.py
test/orm/query.py

index a2984c88ce63d3e69e7436bba17fbbf65545b7eb..e2be54c9ff316b6496adc08e0e3033ceaef61a07 100644 (file)
@@ -1048,7 +1048,11 @@ class Connection(Connectable):
 
     def _handle_dbapi_exception(self, e, statement, parameters, cursor, context):
         if getattr(self, '_reentrant_error', False):
+            # Py3K
+            #raise exc.DBAPIError.instance(statement, parameters, e) as e
+            # Py2K
             raise exc.DBAPIError.instance(statement, parameters, e), None, sys.exc_info()[2]
+            # end Py2K
         self._reentrant_error = True
         try:
             if not isinstance(e, self.dialect.dbapi.Error):
@@ -1068,7 +1072,7 @@ class Connection(Connectable):
                 if self.__close_with_result:
                     self.close()
             # Py3K
-            #raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect).with_traceback(sys.exc_info()[2])
+            #raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) as e
             # Py2K
             raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect), None, sys.exc_info()[2]
             # end Py2K
index efe67e75308203c9e96e57eedd437868ea73c3ea..0640cce6f0cb70a5d65856a45d5b25beb0f59c21 100644 (file)
@@ -75,11 +75,10 @@ class DefaultEngineStrategy(EngineStrategy):
                 try:
                     return dialect.connect(*cargs, **cparams)
                 except Exception, e:
-                    import sys
-
                     # Py3K
-                    #raise exc.DBAPIError.instance(None, None, e).with_traceback(sys.exc_info()[2])
+                    #raise exc.DBAPIError.instance(None, None, e) as e
                     # Py2K
+                    import sys
                     raise exc.DBAPIError.instance(None, None, e), None, sys.exc_info()[2]
                     # end Py2K
                     
index d7f8619c55656f86c8cd3daf3de41335e20138c0..b998c0883cc43d6d00c0fbd85b30c93533d13ba5 100644 (file)
@@ -86,7 +86,7 @@ Full query documentation
 Get, filter, filter_by, order_by, limit, and the rest of the
 query methods are explained in detail in the `SQLAlchemy documentation`__.
 
-__ http://www.sqlalchemy.org/docs/04/ormtutorial.html#datamapping_querying
+__ http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_querying
 
 
 Modifying objects
@@ -545,10 +545,14 @@ class SqlSoup:
     def entity(self, attr, schema=None):
         try:
             t = self._cache[attr]
-        except KeyError:
+        except KeyError, ke:
             table = Table(attr, self._metadata, autoload=True, schema=schema or self.schema)
             if not table.primary_key.columns:
+                # Py3K
+                #raise PKNotFoundError('table %r does not have a primary key defined [columns: %s]' % (attr, ','.join(table.c.keys()))) as ke
+                # Py2K
                 raise PKNotFoundError('table %r does not have a primary key defined [columns: %s]' % (attr, ','.join(table.c.keys())))
+                # end Py2K
             if table.columns:
                 t = class_for_table(table)
             else:
index 71527c686dd1046f0fa5da7deefef0f4b3b0901b..1af0c0c9a9035abedce60fdd1006714f0d4e949f 100644 (file)
@@ -226,7 +226,11 @@ class StrongInstanceDict(IdentityMap):
         
         ref_count = len(self)
         dirty = [s.obj() for s in self.all_states() if s.check_modified()]
-        keepers = weakref.WeakValueDictionary(self)
+
+        # work around http://bugs.python.org/issue6149
+        keepers = weakref.WeakValueDictionary()
+        keepers.update(self)
+
         dict.clear(self)
         dict.update(self, keepers)
         self.modified = bool(dirty)
index fd15420d0ad8b20dd929dde1072bcba7aba9de1b..55b351649267dfdb00378828cd2d159c3f59dc55 100644 (file)
@@ -486,7 +486,7 @@ class InstrumentationCollisionTest(_base.ORMTest):
         class B(A):
             __sa_instrumentation_manager__ = staticmethod(mgr_factory)
 
-        self.assertRaises(TypeError, attributes.register_class, B)
+        self.assertRaisesMessage(TypeError, "multiple instrumentation implementations", attributes.register_class, B)
 
     def test_single_up(self):
 
@@ -497,7 +497,7 @@ class InstrumentationCollisionTest(_base.ORMTest):
         class B(A):
             __sa_instrumentation_manager__ = staticmethod(mgr_factory)
         attributes.register_class(B)
-        self.assertRaises(TypeError, attributes.register_class, A)
+        self.assertRaisesMessage(TypeError, "multiple instrumentation implementations", attributes.register_class, A)
 
     def test_diamond_b1(self):
         mgr_factory = lambda cls: attributes.ClassManager(cls)
@@ -505,10 +505,10 @@ class InstrumentationCollisionTest(_base.ORMTest):
         class A(object): pass
         class B1(A): pass
         class B2(A):
-            __sa_instrumentation_manager__ = mgr_factory
+            __sa_instrumentation_manager__ = staticmethod(mgr_factory)
         class C(object): pass
 
-        self.assertRaises(TypeError, attributes.register_class, B1)
+        self.assertRaisesMessage(TypeError, "multiple instrumentation implementations", attributes.register_class, B1)
 
     def test_diamond_b2(self):
         mgr_factory = lambda cls: attributes.ClassManager(cls)
@@ -516,10 +516,11 @@ class InstrumentationCollisionTest(_base.ORMTest):
         class A(object): pass
         class B1(A): pass
         class B2(A):
-            __sa_instrumentation_manager__ = mgr_factory
+            __sa_instrumentation_manager__ = staticmethod(mgr_factory)
         class C(object): pass
-
-        self.assertRaises(TypeError, attributes.register_class, B2)
+        
+        attributes.register_class(B2)
+        self.assertRaisesMessage(TypeError, "multiple instrumentation implementations", attributes.register_class, B1)
 
     def test_diamond_c_b(self):
         mgr_factory = lambda cls: attributes.ClassManager(cls)
@@ -527,11 +528,11 @@ class InstrumentationCollisionTest(_base.ORMTest):
         class A(object): pass
         class B1(A): pass
         class B2(A):
-            __sa_instrumentation_manager__ = mgr_factory
+            __sa_instrumentation_manager__ = staticmethod(mgr_factory)
         class C(object): pass
 
         attributes.register_class(C)
-        self.assertRaises(TypeError, attributes.register_class, B1)
+        self.assertRaisesMessage(TypeError, "multiple instrumentation implementations", attributes.register_class, B1)
 
 
 class OnLoadTest(_base.ORMTest):
index 07705c925638893ce70e4e8fc02f9a3b33309d48..e97d99c7dd55715a4e6c54800edf1017d74d8fcc 100644 (file)
@@ -143,7 +143,12 @@ class GetTest(QueryTest):
             Column('data', Unicode(40)))
         try:
             metadata.create_all()
+            # Py3K
+            #ustring = 'petit voix m\xe2\x80\x99a'
+            # Py2K
             ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8')
+            # end Py2K
+            
             table.insert().execute(id=ustring, data=ustring)
             class LocalFoo(Base):
                 pass
@@ -299,7 +304,12 @@ class OperatorTest(QueryTest, AssertsCompiledSQL):
     def test_arithmetic(self):
         create_session().query(User)
         for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'),
-                                (operator.sub, '-'), (operator.div, '/'),
+                                (operator.sub, '-'), 
+                                # Py3k
+                                #(operator.truediv, '/'),
+                                # Py2K
+                                (operator.div, '/'),
+                                # end Py2K
                                 ):
             for (lhs, rhs, res) in (
                 (5, User.id, ':id_1 %s users.id'),