]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
some nextisms
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 May 2009 19:56:08 +0000 (19:56 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 May 2009 19:56:08 +0000 (19:56 +0000)
test/orm/generative.py
test/orm/inheritance/poly_linked_list.py

index 99523674141c5e061308b01bb9d996f4aea1f82c..9912b7b23d26447b7658a9620e6c1ec8c2271e9c 100644 (file)
@@ -64,9 +64,14 @@ class GenerativeQueryTest(_base.MappedTest):
         assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,)
         
         assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,)
+        # Py3K
+        #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29
+        #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29
+        # Py2K
         assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29
         assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29
-
+        # end Py2K
+        
     @testing.resolve_artifact_names
     def test_aggregate_1(self):
         if (testing.against('mysql') and
@@ -89,10 +94,18 @@ class GenerativeQueryTest(_base.MappedTest):
     def test_aggregate_3(self):
         query = create_session().query(Foo)
 
+        # Py3K
+        #avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0]
+        # Py2K
         avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0]
+        # end Py2K
         assert round(avg_f, 1) == 14.5
 
+        # Py3K
+        #avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0]
+        # Py2K
         avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0]
+        # end Py2K
         assert round(avg_o, 1) == 14.5
 
     @testing.resolve_artifact_names
index 3fe9f9c8d24e5f38a22637f3c261a040284441b5..73bc43ca32fce8aef5e0b6adb88f20e6bd93f35e 100644 (file)
@@ -69,7 +69,7 @@ class PolymorphicCircularTest(ORMTest):
                                    polymorphic_on=table1.c.type,
                                    polymorphic_identity='table1',
                                    properties={
-                                    'next': relation(Table1,
+                                    'nxt': relation(Table1,
                                         backref=backref('prev', foreignkey=join.c.id, uselist=False),
                                         uselist=False, primaryjoin=join.c.id==join.c.related_id),
                                     'data':relation(mapper(Data, data))
@@ -83,15 +83,16 @@ class PolymorphicCircularTest(ORMTest):
 
         # currently, the "eager" relationships degrade to lazy relationships
         # due to the polymorphic load.
-        # the "next" relation used to have a "lazy=False" on it, but the EagerLoader raises the "self-referential"
+        # the "nxt" relation used to have a "lazy=False" on it, but the EagerLoader raises the "self-referential"
         # exception now.  since eager loading would never work for that relation anyway, its better that the user
         # gets an exception instead of it silently not eager loading.
+        # NOTE: using "nxt" instead of "next" to avoid 2to3 turning it into __next__() for some reason.
         table1_mapper = mapper(Table1, table1,
                                #select_table=join,
                                polymorphic_on=table1.c.type,
                                polymorphic_identity='table1',
                                properties={
-                               'next': relation(Table1,
+                               'nxt': relation(Table1,
                                    backref=backref('prev', remote_side=table1.c.id, uselist=False),
                                    uselist=False, primaryjoin=table1.c.id==table1.c.related_id),
                                'data':relation(mapper(Data, data), lazy=False, order_by=data.c.id)
@@ -144,7 +145,7 @@ class PolymorphicCircularTest(ORMTest):
             else:
                 newobj = c
             if obj is not None:
-                obj.next = newobj
+                obj.nxt = newobj
             else:
                 t = newobj
             obj = newobj
@@ -158,7 +159,7 @@ class PolymorphicCircularTest(ORMTest):
         node = t
         while (node):
             assertlist.append(node)
-            n = node.next
+            n = node.nxt
             if n is not None:
                 assert n.prev is node
             node = n
@@ -171,7 +172,7 @@ class PolymorphicCircularTest(ORMTest):
         assertlist = []
         while (node):
             assertlist.append(node)
-            n = node.next
+            n = node.nxt
             if n is not None:
                 assert n.prev is node
             node = n
@@ -185,7 +186,7 @@ class PolymorphicCircularTest(ORMTest):
             assertlist.insert(0, node)
             n = node.prev
             if n is not None:
-                assert n.next is node
+                assert n.nxt is node
             node = n
         backwards = repr(assertlist)