import testenv; testenv.configure_for_tests() import unittest import orm.alltests as orm import base.alltests as base import sql.alltests as sql import engine.alltests as engine import dialect.alltests as dialect import ext.alltests as ext import zblog.alltests as zblog import profiling.alltests as profiling # The profiling tests are sensitive to foibles of CPython VM state, so # run them first. Ideally, each should be run in a fresh interpreter. def suite(): alltests = unittest.TestSuite() for suite in (profiling, base, engine, sql, dialect, orm, ext, zblog): alltests.addTest(suite.suite()) return alltests if __name__ == '__main__': testenv.main(suite())
result2 = sess.query(parent_class).get(parent2.id) assert result2.id == parent2.id assert result2.collection[0].id == child_obj.id sess.clear() # assert result via polymorphic load of parent object result = sess.query(A).filter_by(id=parent_obj.id).one() assert result.id == parent_obj.id assert result.collection[0].id == child_obj.id if direction == ONETOMANY: assert result.collection[1].id == child2.id elif direction == MANYTOONE: result2 = sess.query(A).filter_by(id=parent2.id).one() assert result2.id == parent2.id assert result2.collection[0].id == child_obj.id ABCTest.__name__ = "Test%sTo%s%s" % (parent, child, (direction is ONETOMANY and "O2M" or "M2O")) return ABCTest # test all combinations of polymorphic a/b/c related to another of a/b/c for parent in ["a", "b", "c"]: for child in ["a", "b", "c"]: for direction in [ONETOMANY, MANYTOONE]: testclass = produce_test(parent, child, direction) exec("%s = testclass" % testclass.__name__) del testclass if __name__ == "__main__": testenv.main()
setattr(self, '_value', value) value = property(_getValue, _setValue) mapper(User, users, properties={ 'uid':synonym('id'), 'foobar':comparable_property(User.Comparator,User.value), }) sess = create_session() u = User() u.name = 'ed' sess.save(u) sess.flush() sess.expunge(u) sess.merge(u) @testing.resolve_artifact_names def test_cascades_dont_autoflush(self): sess = create_session(autoflush=True) m = mapper(User, users, properties={ 'addresses':relation(mapper(Address, addresses),backref='user')}) user = User(id=8, name='fred', addresses=[Address(email_address='user')]) merged_user = sess.merge(user) assert merged_user in sess.new sess.flush() assert merged_user not in sess.new if __name__ == "__main__": testenv.main()
from testlib import sa_unittest as unittest def suite(): modules_to_test = ( 'orm.inheritance.basic', 'orm.inheritance.query', 'orm.inheritance.manytomany', 'orm.inheritance.single', 'orm.inheritance.concrete', 'orm.inheritance.polymorph', 'orm.inheritance.polymorph2', 'orm.inheritance.poly_linked_list', 'orm.inheritance.abc_polymorphic', 'orm.inheritance.abc_inheritance', 'orm.inheritance.productspec', 'orm.inheritance.magazine', 'orm.inheritance.selects', ) alltests = unittest.TestSuite() for name in modules_to_test: mod = __import__(name) for token in name.split('.')[1:]: mod = getattr(mod, token) alltests.addTest(unittest.findTestCases(mod, suiteClass=None)) return alltests if __name__ == '__main__': testenv.main(suite())