From: Mike Bayer Date: Fri, 30 May 2014 04:21:11 +0000 (-0400) Subject: - add a new assertsql construct "Or", so that we can test for a UOW flush X-Git-Tag: rel_1_0_0b1~410^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2c8689fd141c278a7bbc250087e553b76a515bc6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py index 3e0d4c9d3c..d77fc18a2e 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 a76f928c79..7025e087c5 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}] + ), + + ) ), )