Skip to content

Commit 2359c83

Browse files
committed
Be consistent about comparison order in asserts
1 parent e90ec4d commit 2359c83

13 files changed

Lines changed: 50 additions & 51 deletions

tests/config_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ def test_apply_defaults_to_siblings_applies_defaults() -> None:
99
input_ = {"defaults": {1: 1}, "other": {}}
1010
expected = {"other": {1: 1}}
1111
output = _apply_defaults_to_siblings(input_)
12-
assert expected == output
12+
assert output == expected
1313

1414

1515
def test_apply_defaults_to_siblings_does_not_override() -> None:
1616
input_ = {"defaults": {1: 1}, "other": {1: 2}}
1717
expected = {"other": {1: 2}}
1818
output = _apply_defaults_to_siblings(input_)
19-
assert expected == output
19+
assert output == expected
2020

2121

2222
def test_apply_defaults_to_siblings_ignores_nontables() -> None:
2323
input_ = {"defaults": {1: 1}, "other": {1: 2}, "not-a-table": 3}
2424
expected = {"other": {1: 2}, "not-a-table": 3}
2525
output = _apply_defaults_to_siblings(input_)
26-
assert expected == output
26+
assert output == expected
2727

2828

2929
def test_load_configuration_adds_environment_variables(default_configuration_file: Path) -> None:

tests/dependencies/fetch_user_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ async def test_fetch_user(api_key: str, user: User, user_test: AsyncConnection)
2121
async with aclosing(fetch_user(api_key, user_data=user_test)) as agen:
2222
db_user = await anext(agen)
2323
assert isinstance(db_user, User)
24-
assert user.user_id == db_user.user_id
25-
assert set(await user.get_groups()) == set(await db_user.get_groups())
24+
assert db_user.user_id == user.user_id
25+
assert set(await db_user.get_groups()) == set(await user.get_groups())
2626

2727

2828
async def test_fetch_user_no_key_no_user() -> None:

tests/routers/openml/datasets_list_datasets_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ async def test_list_data_identical(
105105

106106
# PHP API has a double nested dictionary that never has other entries
107107
php_json = original.json()["data"]["dataset"]
108-
assert len(php_json) == len(new_json)
109-
assert php_json == new_json
108+
assert len(new_json) == len(php_json)
109+
assert new_json == php_json
110110
return None
111111

112112

@@ -341,6 +341,6 @@ async def test_list_data_quality(
341341
status=DatasetStatusFilter.ALL,
342342
user=None,
343343
expdb_db=expdb_test,
344-
**{quality: range_}, # type: ignore[arg-type]
344+
**{quality: range_},
345345
)
346346
assert len(result) == count

tests/routers/openml/datasets_qualities_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def test_get_quality(py_api: httpx.AsyncClient) -> None:
119119
{"name": "kNN1NErrRate", "value": 0.06347438752783964},
120120
{"name": "kNN1NKappa", "value": 0.8261102938928316},
121121
]
122-
difference = deepdiff.DeepDiff(expected, response.json(), ignore_order=True)
122+
difference = deepdiff.DeepDiff(response.json(), expected, ignore_order=True)
123123
assert not difference
124124

125125

@@ -171,22 +171,22 @@ def _assert_get_quality_error_dataset_not_found(
171171
php_error = php_response.json()["error"]
172172
py_error = python_response.json()
173173

174-
assert php_error["code"] == py_error["code"]
174+
assert py_error["code"] == php_error["code"]
175175
assert php_error["message"] == "Unknown dataset"
176176
assert re.match(r"Dataset with id \d+ not found.", py_error["detail"])
177177

178178

179179
def _assert_get_quality_error_dataset_process_error(
180180
python_response: httpx.Response, php_response: httpx.Response
181181
) -> None:
182-
assert php_response.status_code == python_response.status_code
182+
assert python_response.status_code == php_response.status_code
183183

184184
php_error = php_response.json()["error"]
185185
py_error = python_response.json()
186186

187-
assert php_error["code"] == py_error["code"]
187+
assert py_error["code"] == php_error["code"]
188188
assert php_error["message"] == "Dataset processed with error"
189189
assert py_error["title"] == "Dataset Processing Error"
190190
# The PHP can add some additional unnecessary escapes.
191-
assert php_error["additional_information"][:30] == py_error["detail"][:30]
192-
assert php_error["additional_information"][-30:] == py_error["detail"][-30:]
191+
assert py_error["detail"][:30] == php_error["additional_information"][:30]
192+
assert py_error["detail"][-30:] == php_error["additional_information"][-30:]

tests/routers/openml/migration/datasets_migration_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ async def test_dataset_response_is_identical( # noqa: C901, PLR0912
2828
if new.status_code == HTTPStatus.FORBIDDEN:
2929
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
3030
else:
31-
assert original.status_code == new.status_code
31+
assert new.status_code == original.status_code
3232

3333
if new.status_code != HTTPStatus.OK:
3434
# RFC 9457: Python API now returns problem+json format
3535
assert new.headers["content-type"] == "application/problem+json"
3636
# Both APIs should return error responses in the same cases
37-
assert original.json()["error"]["code"] == new.json()["code"]
37+
assert new.json()["code"] == original.json()["error"]["code"]
3838
old_error_message = original.json()["error"]["message"]
3939
assert new.json()["detail"].startswith(old_error_message)
4040
return
@@ -95,7 +95,7 @@ async def test_dataset_response_is_identical( # noqa: C901, PLR0912
9595
if "description" not in new_body:
9696
new_body["description"] = []
9797

98-
assert original_json == new_body
98+
assert new_body == original_json
9999

100100

101101
@pytest.mark.parametrize(
@@ -146,7 +146,7 @@ async def test_private_dataset_owner_access(
146146
php_api.get(f"/data/{private_dataset}?api_key={api_key}"),
147147
)
148148
assert old_response.status_code == HTTPStatus.OK
149-
assert old_response.status_code == new_response.status_code
149+
assert new_response.status_code == old_response.status_code
150150
assert new_response.json()["id"] == private_dataset
151151

152152

@@ -201,24 +201,24 @@ async def test_dataset_tag_response_is_identical(
201201
# RFC 9457: Tag conflict now returns 409 instead of 500
202202
if original.status_code == HTTPStatus.INTERNAL_SERVER_ERROR and already_tagged:
203203
assert new.status_code == HTTPStatus.CONFLICT
204-
assert original.json()["error"]["code"] == new.json()["code"]
204+
assert new.json()["code"] == original.json()["error"]["code"]
205205
assert original.json()["error"]["message"] == "Entity already tagged by this tag."
206206
assert re.match(
207207
pattern=r"Dataset \d+ already tagged with " + f"'{tag}'.",
208208
string=new.json()["detail"],
209209
)
210210
return
211211

212-
assert original.status_code == new.status_code, original.json()
212+
assert new.status_code == original.status_code, original.json()
213213
if new.status_code != HTTPStatus.OK:
214-
assert original.json()["error"]["code"] == new.json()["code"]
215-
assert original.json()["error"]["message"] == new.json()["detail"]
214+
assert new.json()["code"] == original.json()["error"]["code"]
215+
assert new.json()["detail"] == original.json()["error"]["message"]
216216
return
217217

218218
original = original.json()
219219
new = new.json()
220220
new = nested_remove_single_element_list(new)
221-
assert original == new
221+
assert new == original
222222

223223

224224
@pytest.mark.parametrize(
@@ -238,12 +238,12 @@ async def test_datasets_feature_is_identical(
238238

239239
if new.status_code != HTTPStatus.OK:
240240
error = original.json()["error"]
241-
assert error["code"] == new.json()["code"]
241+
assert new.json()["code"] == error["code"]
242242
if error["message"] == "No features found. Additionally, dataset processed with error":
243243
pattern = r"No features found. Additionally, dataset \d+ processed with error\."
244244
assert re.match(pattern, new.json()["detail"])
245245
else:
246-
assert error["message"] == new.json()["detail"]
246+
assert new.json()["detail"] == error["message"]
247247
return
248248

249249
python_body = new.json()

tests/routers/openml/migration/flows_migration_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def convert_flow_naming_and_defaults(flow: dict[str, Any]) -> dict[str, Any]:
9494
# differences (e.g., '1.0' vs '1')
9595
expected = nested_str_to_num(expected)
9696
difference = deepdiff.diff.DeepDiff(
97-
expected,
9897
new,
98+
expected,
9999
ignore_order=True,
100100
ignore_numeric_type_changes=True,
101101
)

tests/routers/openml/migration/runs_migration_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_get_run_trace_equal(
3333

3434
php_error = php_response.json()["error"]
3535
py_error = py_response.json()
36-
assert php_error["code"] == py_error["code"]
36+
assert py_error["code"] == php_error["code"]
3737
if php_error["code"] == "571":
3838
assert php_error["message"] == "Run not found."
3939
assert py_error["detail"] == f"Run {run_id} not found."

tests/routers/openml/migration/setups_migration_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ async def test_setup_untag_response_is_identical_when_tag_exists(
8585
)
8686

8787
if new.status_code == HTTPStatus.OK:
88-
assert original.status_code == new.status_code
88+
assert new.status_code == original.status_code
8989
original_untag = original.json()["setup_untag"]
9090
new_untag = new.json()["setup_untag"]
91-
assert original_untag["id"] == new_untag["id"]
91+
assert new_untag["id"] == original_untag["id"]
9292
if tags := original_untag.get("tag"):
9393
if isinstance(tags, str):
94-
assert tags == new_untag["tag"][0]
94+
assert new_untag["tag"][0] == tags
9595
else:
96-
assert tags == new_untag["tag"]
96+
assert new_untag["tag"] == tags
9797
else:
9898
assert new_untag["tag"] == []
9999
return
100100

101101
code, message = original.json()["error"].values()
102102
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
103103
assert new.status_code == HTTPStatus.FORBIDDEN
104-
assert code == new.json()["code"]
104+
assert new.json()["code"] == code
105105
assert message == "Tag is not owned by you"
106106
assert re.match(
107107
r"You may not remove tag \S+ of setup \d+ because it was not created by you.",
@@ -131,7 +131,7 @@ async def test_setup_untag_response_is_identical_setup_doesnt_exist(
131131
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
132132
assert new.status_code == HTTPStatus.NOT_FOUND
133133
assert original.json()["error"]["message"] == "Entity not found."
134-
assert original.json()["error"]["code"] == new.json()["code"]
134+
assert new.json()["code"] == original.json()["error"]["code"]
135135
assert re.match(
136136
r"Setup \d+ not found.",
137137
new.json()["detail"],
@@ -159,7 +159,7 @@ async def test_setup_untag_response_is_identical_tag_doesnt_exist(
159159

160160
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
161161
assert new.status_code == HTTPStatus.NOT_FOUND
162-
assert original.json()["error"]["code"] == new.json()["code"]
162+
assert new.json()["code"] == original.json()["error"]["code"]
163163
assert original.json()["error"]["message"] == "Tag not found."
164164
assert re.match(
165165
r"Setup \d+ does not have tag '\S+'.",
@@ -208,15 +208,15 @@ async def test_setup_tag_response_is_identical_when_tag_doesnt_exist( # noqa: P
208208
)
209209

210210
assert new.status_code == HTTPStatus.OK
211-
assert original.status_code == new.status_code
211+
assert new.status_code == original.status_code
212212
original_tag = original.json()["setup_tag"]
213213
new_tag = new.json()["setup_tag"]
214-
assert original_tag["id"] == new_tag["id"]
214+
assert new_tag["id"] == original_tag["id"]
215215
if tags := original_tag.get("tag"):
216216
if isinstance(tags, str):
217-
assert tags == new_tag["tag"][0]
217+
assert new_tag["tag"][0] == tags
218218
else:
219-
assert set(tags) == set(new_tag["tag"])
219+
assert set(new_tag["tag"]) == set(tags)
220220
else:
221221
assert new_tag["tag"] == []
222222

@@ -243,7 +243,7 @@ async def test_setup_tag_response_is_identical_setup_doesnt_exist(
243243
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
244244
assert new.status_code == HTTPStatus.NOT_FOUND
245245
assert original.json()["error"]["message"] == "Entity not found."
246-
assert original.json()["error"]["code"] == new.json()["code"]
246+
assert new.json()["code"] == original.json()["error"]["code"]
247247
assert re.match(
248248
r"Setup \d+ not found.",
249249
new.json()["detail"],
@@ -293,7 +293,7 @@ async def test_get_setup_response_is_identical_setup_doesnt_exist(
293293
assert original.status_code == HTTPStatus.PRECONDITION_FAILED
294294
assert new.status_code == HTTPStatus.NOT_FOUND
295295
assert original.json()["error"]["message"] == "Unknown setup"
296-
assert original.json()["error"]["code"] == new.json()["code"]
296+
assert new.json()["code"] == original.json()["error"]["code"]
297297
assert new.json()["detail"] == f"Setup {setup_id} not found."
298298

299299

@@ -326,4 +326,4 @@ async def test_get_setup_response_is_identical(
326326
new_json = nested_str_to_num(new.json())
327327
new_json = nested_remove_values(new_json, values=[[], None])
328328

329-
assert original_json == new_json
329+
assert new_json == original_json

tests/routers/openml/migration/tasks_migration_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async def test_list_tasks_equal(
168168
php_ids = {int(t["task_id"]) for t in php_tasks}
169169
py_ids = {int(t["task_id"]) for t in py_tasks}
170170

171-
assert php_ids == py_ids, (
171+
assert py_ids == php_ids, (
172172
f"PHP and Python must return the exact same task IDs: {php_ids ^ py_ids}"
173173
)
174174

tests/routers/openml/qualities_list_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ async def test_list_qualities_identical(
3535
py_api.get("/datasets/qualities/list"),
3636
php_api.get("/data/qualities/list"),
3737
)
38-
assert original.status_code == new.status_code
39-
assert original.json() == new.json()
38+
assert new.status_code == original.status_code
39+
assert new.json() == original.json()
4040
# To keep the test idempotent, we cannot test if reaction to database changes is identical
4141

4242

@@ -157,11 +157,11 @@ async def test_list_qualities(py_api: httpx.AsyncClient, expdb_test: AsyncConnec
157157
],
158158
},
159159
}
160-
assert expected == response.json()
160+
assert response.json() == expected
161161

162162
deleted = expected["data_qualities_list"]["quality"].pop()
163163
await _remove_quality_from_database(quality_name=deleted, expdb_test=expdb_test)
164164

165165
response = await py_api.get("/datasets/qualities/list")
166166
assert response.status_code == HTTPStatus.OK
167-
assert expected == response.json()
167+
assert response.json() == expected

0 commit comments

Comments
 (0)