| 1158 | ) |
| 1159 | |
| 1160 | async def assert_query_result( |
| 1161 | self, |
| 1162 | query, |
| 1163 | exp_result_json, |
| 1164 | exp_result_binary=..., |
| 1165 | *, |
| 1166 | always_typenames=False, |
| 1167 | always_typeids=False, |
| 1168 | msg=None, |
| 1169 | sort=None, |
| 1170 | implicit_limit=0, |
| 1171 | variables=None, |
| 1172 | json_only=False, |
| 1173 | binary_only=False, |
| 1174 | rel_tol=None, |
| 1175 | abs_tol=None, |
| 1176 | language: Literal["sql", "edgeql"] = "edgeql", |
| 1177 | ): |
| 1178 | fetch_args = variables if isinstance(variables, tuple) else () |
| 1179 | fetch_kw = variables if isinstance(variables, dict) else {} |
| 1180 | |
| 1181 | if not binary_only and language != "sql": |
| 1182 | try: |
| 1183 | tx = self.con.transaction() |
| 1184 | await tx.start() |
| 1185 | try: |
| 1186 | res = await self.con._fetchall_json( |
| 1187 | query, |
| 1188 | *fetch_args, |
| 1189 | __limit__=implicit_limit, |
| 1190 | **fetch_kw) |
| 1191 | finally: |
| 1192 | await tx.rollback() |
| 1193 | |
| 1194 | res = json.loads(res) |
| 1195 | if sort is not None: |
| 1196 | assert_data_shape.sort_results(res, sort) |
| 1197 | assert_data_shape.assert_data_shape( |
| 1198 | res, exp_result_json, self.fail, |
| 1199 | message=msg, rel_tol=rel_tol, abs_tol=abs_tol, |
| 1200 | ) |
| 1201 | except Exception: |
| 1202 | self.add_fail_notes(serialization='json') |
| 1203 | if msg: |
| 1204 | self.add_fail_notes(msg=msg) |
| 1205 | raise |
| 1206 | |
| 1207 | if json_only: |
| 1208 | return |
| 1209 | |
| 1210 | if exp_result_binary is ...: |
| 1211 | # The expected result is the same |
| 1212 | exp_result_binary = exp_result_json |
| 1213 | |
| 1214 | typenames = random.choice([True, False]) or always_typenames |
| 1215 | typeids = random.choice([True, False]) or always_typeids |
| 1216 | |
| 1217 | try: |