]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a new assertsql construct "Or", so that we can test for a UOW flush
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 May 2014 04:21:11 +0000 (00:21 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 May 2014 04:21:11 +0000 (00:21 -0400)
that might take one of multiple directions; apply this to test_delete_unloaded_m2o
which is now illustrating multiple paths due to #3060/#3061, though still doing the
right thing.

lib/sqlalchemy/testing/assertsql.py
test/orm/test_unitofworkv2.py

index 3e0d4c9d3c2583a86e2e38790c877a9c202ed0ee..d77fc18a2eecc30153dbb8f0e9d27765f45929b6 100644 (file)
@@ -256,11 +256,30 @@ class AllOf(AssertRule):
             if rule.rule_passed():  # a rule passed, move on
                 self.rules.remove(rule)
                 return len(self.rules) == 0
-        assert False, 'No assertion rules were satisfied for statement'
+        return False
+
+    def rule_passed(self):
+        return self.is_consumed()
 
     def consume_final(self):
         return len(self.rules) == 0
 
+class Or(AllOf):
+    def __init__(self, *rules):
+        self.rules = set(rules)
+        self._consume_final = False
+
+    def is_consumed(self):
+        if not self.rules:
+            return True
+        for rule in list(self.rules):
+            if rule.rule_passed():  # a rule passed
+                self._consume_final = True
+                return True
+        return False
+
+    def consume_final(self):
+        assert self._consume_final, "Unsatisified rules remain"
 
 def _process_engine_statement(query, context):
     if util.jython:
index a76f928c795763385bcb08d3e1098b1ee2bbb6c3..7025e087c5f35a3c17ca3c5db0d504897376d7b3 100644 (file)
@@ -10,7 +10,7 @@ from sqlalchemy.orm import mapper, relationship, backref, \
                             create_session, unitofwork, attributes,\
                             Session, class_mapper, sync, exc as orm_exc
 
-from sqlalchemy.testing.assertsql import AllOf, CompiledSQL
+from sqlalchemy.testing.assertsql import AllOf, CompiledSQL, Or
 
 class AssertsUOW(object):
     def _get_test_uow(self, session):
@@ -1008,14 +1008,23 @@ class SingleCycleTest(UOWTest):
                     "WHERE nodes.id = :param_1",
                     lambda ctx: {'param_1': c2id}
                 ),
-                CompiledSQL(
-                    "DELETE FROM nodes WHERE nodes.id = :id",
-                    lambda ctx: [{'id': c1id}, {'id': c2id}]
-                ),
-                CompiledSQL(
-                    "DELETE FROM nodes WHERE nodes.id = :id",
-                    lambda ctx: {'id': pid}
-                ),
+                Or(
+                    AllOf(
+                        CompiledSQL(
+                            "DELETE FROM nodes WHERE nodes.id = :id",
+                            lambda ctx: [{'id': c1id}, {'id': c2id}]
+                        ),
+                        CompiledSQL(
+                            "DELETE FROM nodes WHERE nodes.id = :id",
+                            lambda ctx: {'id': pid}
+                        ),
+                    ),
+                    CompiledSQL(
+                        "DELETE FROM nodes WHERE nodes.id = :id",
+                        lambda ctx: [{'id': c1id}, {'id': c2id}, {'id': pid}]
+                    ),
+
+                )
             ),
         )