| 125 | (False, 2), |
| 126 | ) |
| 127 | def test_one_or_none(self, one_or_first, rows_present): |
| 128 | # TODO: this is not testing the ORM level "scalar_mapping" |
| 129 | # mode which has a different performance profile |
| 130 | t, t2 = self.tables("table1", "table2") |
| 131 | |
| 132 | with testing.db.connect().execution_options( |
| 133 | compiled_cache=None |
| 134 | ) as conn: |
| 135 | stmt = t.select() |
| 136 | if rows_present == 0: |
| 137 | stmt = stmt.where(1 == 0) |
| 138 | elif rows_present == 1: |
| 139 | stmt = stmt.limit(1) |
| 140 | |
| 141 | result = conn.execute(stmt) |
| 142 | |
| 143 | @profiling.function_call_count() |
| 144 | def go(): |
| 145 | if one_or_first: |
| 146 | result.one() |
| 147 | else: |
| 148 | result.first() |
| 149 | |
| 150 | try: |
| 151 | go() |
| 152 | finally: |
| 153 | # hmmmm, connection close context manager does not |
| 154 | # seem to be handling this for a profile that skips |
| 155 | result.close() |
| 156 | |
| 157 | def test_contains_doesnt_compile(self, connection): |
| 158 | t, t2 = self.tables("table1", "table2") |