summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-30 00:21:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-30 00:21:11 -0400
commit2c8689fd141c278a7bbc250087e553b76a515bc6 (patch)
tree2f6bf4c48b34b0d60f540cf9d79726da515fc0ac
parent1bd578998b89a7e3c08e50d04f37daefbf307a58 (diff)
downloadsqlalchemy-2c8689fd141c278a7bbc250087e553b76a515bc6.tar.gz
- add a new assertsql construct "Or", so that we can test for a UOW flush
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.
-rw-r--r--lib/sqlalchemy/testing/assertsql.py21
-rw-r--r--test/orm/test_unitofworkv2.py27
2 files changed, 38 insertions, 10 deletions
diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py
index 3e0d4c9d3..d77fc18a2 100644
--- a/lib/sqlalchemy/testing/assertsql.py
+++ b/lib/sqlalchemy/testing/assertsql.py
@@ -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:
diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py
index a76f928c7..7025e087c 100644
--- a/test/orm/test_unitofworkv2.py
+++ b/test/orm/test_unitofworkv2.py
@@ -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}]
+ ),
+
+ )
),
)