Test a large series of conditionals and assert that results remain correct between all of them within a series of loops.
(self)
| 655 | eq_(bq(session).all(), [(4,)]) |
| 656 | |
| 657 | def test_conditional_step(self): |
| 658 | """Test a large series of conditionals and assert that |
| 659 | results remain correct between all of them within a series |
| 660 | of loops. |
| 661 | |
| 662 | """ |
| 663 | User = self.classes.User |
| 664 | |
| 665 | base_bq = self.bakery(lambda s: s.query(User.id, User.name)) |
| 666 | |
| 667 | base_bq += lambda q: q.order_by(User.id) |
| 668 | |
| 669 | for i in range(4): |
| 670 | for cond1, cond2, cond3, cond4 in itertools.product( |
| 671 | *[(False, True) for j in range(4)] |
| 672 | ): |
| 673 | bq = base_bq._clone() |
| 674 | if cond1: |
| 675 | bq += lambda q: q.filter(User.name != "jack") |
| 676 | if cond2: |
| 677 | bq += lambda q: q.join(User.addresses) |
| 678 | else: |
| 679 | bq += lambda q: q.outerjoin(User.addresses) |
| 680 | elif cond3: |
| 681 | bq += lambda q: q.filter(User.name.like("%ed%")) |
| 682 | else: |
| 683 | bq += lambda q: q.filter(User.name == "jack") |
| 684 | |
| 685 | if cond4: |
| 686 | bq += lambda q: q._legacy_from_self().with_entities( |
| 687 | func.count(User.id) |
| 688 | ) |
| 689 | sess = fixture_session() |
| 690 | result = bq(sess).all() |
| 691 | if cond4: |
| 692 | if cond1: |
| 693 | if cond2: |
| 694 | eq_(result, [(4,)]) |
| 695 | else: |
| 696 | eq_(result, [(5,)]) |
| 697 | elif cond3: |
| 698 | eq_(result, [(2,)]) |
| 699 | else: |
| 700 | eq_(result, [(1,)]) |
| 701 | else: |
| 702 | if cond1: |
| 703 | if cond2: |
| 704 | eq_( |
| 705 | result, |
| 706 | [(8, "ed"), (8, "ed"), (8, "ed"), (9, "fred")], |
| 707 | ) |
| 708 | else: |
| 709 | eq_( |
| 710 | result, |
| 711 | [ |
| 712 | (8, "ed"), |
| 713 | (8, "ed"), |
| 714 | (8, "ed"), |
nothing calls this directly
no test coverage detected