Mike Bayer avatar Mike Bayer committed 7a818e8

- added an extremely rudimental set of python 2.3 compatible tests. these
can at least confirm that we're even on the grid python 2.3-wise.
- fixed usage of native set(), generator expressions
- will release 0.4.7p1

Comments (0)

Files changed (7)

 =======
 CHANGES
 =======
-0.4.8
+0.4.7p1
 =====
 - orm 
     - Added "add()" and "add_all()" to scoped_session
             ScopedSession, "add", instrument("add"))
         setattr(
             ScopedSession, "add_all", instrument("add_all"))
-        
+
+    - Fixed non-2.3 compatible usage of set() and generator
+      expression within relation().
+
 0.4.7
 =====
 - orm
-0.4.8
+0.4.7p1

lib/sqlalchemy/orm/properties.py

         if self._legacy_foreignkey and not self._refers_to_parent_table():
             self.foreign_keys = self._legacy_foreignkey
 
-        arg_foreign_keys = set(expression._literal_as_column(x) for x in util.to_set(self.foreign_keys))
+        arg_foreign_keys = util.Set([expression._literal_as_column(x) for x in util.to_set(self.foreign_keys)])
 
         if self._arg_local_remote_pairs:
             if not arg_foreign_keys:
             else:
                 eq_pairs = self._arg_local_remote_pairs
         elif self.remote_side:
-            remote_side = set(expression._literal_as_column(x) for x in util.to_set(self.remote_side))
+            remote_side = util.Set([expression._literal_as_column(x) for x in util.to_set(self.remote_side)])
             
             if self.direction is MANYTOONE:
                 eq_pairs = criterion_as_pairs(self.primaryjoin, consider_as_referenced_keys=remote_side, any_operator=True)

Empty file added.

test/py23/alltests.py

+import unittest
+
+
+def suite():
+    modules_to_test = (
+        'py23.test_sql',
+        'py23.test_orm',
+        )
+    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__':
+    runner = unittest.TextTestRunner()
+    runner.run(suite())

test/py23/test_orm.py

+import unittest
+from sqlalchemy import *
+from sqlalchemy.orm import *
+
+class ORMTest(unittest.TestCase):
+    def setUp(self):
+        global engine, users, addresses
+        engine = create_engine('sqlite://')
+        meta = MetaData(engine)
+        users = Table('users', meta,
+              Column('id', Integer, primary_key=True),
+              Column('name', String(255))
+        )
+        addresses = Table('addresses', meta,
+              Column('id', Integer, primary_key=True),
+              Column('email', String(255)),
+              Column('user_id', Integer, ForeignKey('users.id'))
+        )
+
+        meta.create_all()
+
+ 
+    def tearDown(self):
+        engine.dispose()
+
+    def test_orm_roundtrip(self):
+        class User(object):
+            def __init__(self, name):
+                self.name = name
+        class Address(object):
+            def __init__(self, email):
+                self.email = email
+
+        mapper(User, users, properties={
+           'addresses':relation(Address, backref='user', cascade="all, delete-orphan")
+        })
+        mapper(Address, addresses)
+
+        sess = sessionmaker()()
+        u1 = User('ed')
+        u2 = User('wendy')
+        u1.addresses.append(Address('ed@ed.com'))
+        u2.addresses.append(Address('wendy@wendy.com'))
+        sess.add_all([u1, u2])
+        sess.commit()
+
+        self.assertEquals(sess.query(User).order_by(User.name).all(), [u1, u2])
+
+	sess.clear()
+        u1 = sess.query(User).get(1)
+        self.assertEquals(u1.name, 'ed')
+        self.assertEquals(u1.addresses[0].email, 'ed@ed.com')
+        sess.delete(u1)
+        sess.commit()
+        self.assertEquals(sess.query(User).count(), 1)
+               
+
+if __name__ == '__main__':
+    unittest.main()

test/py23/test_sql.py

+import unittest
+from sqlalchemy import *
+
+class SQLTest(unittest.TestCase):
+    def setUp(self):
+        global engine
+        engine = create_engine('sqlite://')
+
+    def tearDown(self):
+        engine.dispose()
+
+    def test_select_roundtrip(self):
+        meta = MetaData(engine)
+        users = Table('users', meta,
+              Column('id', Integer, primary_key=True),
+              Column('name', String(255))
+        )
+        addresses = Table('addresses', meta,
+              Column('id', Integer, primary_key=True),
+              Column('email', String(255)),
+              Column('user_id', Integer, ForeignKey('users.id'))
+        )
+
+        meta.create_all()
+        users.insert().execute(id=1, name='ed')
+        users.insert().execute(id=2, name='wendy')
+        addresses.insert().execute(id=1, user_id=1, email='ed@foo.com')
+        addresses.insert().execute(id=2, user_id=2, email='wendy@foo.com')
+        self.assertEquals(users.join(addresses).select().execute().fetchall(), 
+           [(1, 'ed', 1, 'ed@foo.com', 1), (2, 'wendy', 2, 'wendy@foo.com', 2)]
+        )
+
+        
+
+if __name__ == '__main__':
+    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.