- 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
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):
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
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
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
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:
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)
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):
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)
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)
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)
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):
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
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'),