Skip to content

Commit 3e9042a

Browse files
authored
Improve consistency of test variable names and ordering (#310)
Update the tests to be more consistent with variable naming and ordering in assertions.
1 parent e90ec4d commit 3e9042a

20 files changed

Lines changed: 246 additions & 246 deletions

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ ignore = [
108108

109109
[tool.mypy]
110110
strict = true
111+
mypy_path = "src"
111112
plugins = [
112113
"pydantic.mypy"
113114
]

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/dataset_tag_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ async def test_dataset_tag_invalid_tag_is_rejected(
3636
tag: str,
3737
py_api: httpx.AsyncClient,
3838
) -> None:
39-
new = await py_api.post(
39+
response = await py_api.post(
4040
f"/datasets/tag?api_key={ApiKey.ADMIN}",
4141
json={"data_id": 1, "tag": tag},
4242
)
4343

44-
assert new.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
45-
assert new.json()["detail"][0]["loc"] == ["body", "tag"]
44+
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
45+
assert response.json()["detail"][0]["loc"] == ["body", "tag"]
4646

4747

4848
# ── Direct call tests: tag_dataset ──

tests/routers/openml/datasets_list_datasets_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,39 @@ async def test_list_data_identical(
7474
uri += f"/{'/'.join([str(v) for q in query for v in q])}"
7575
uri += api_key_query
7676

77-
new, original = await asyncio.gather(
77+
py_response, php_response = await asyncio.gather(
7878
py_api.post(f"/datasets/list{api_key_query}", json=new_style),
7979
php_api.get(uri),
8080
)
8181

8282
# Note: RFC 9457 changed some status codes (PRECONDITION_FAILED -> NOT_FOUND for no results)
8383
# and the error response format, so we can't compare error responses directly.
84-
php_is_error = original.status_code == HTTPStatus.PRECONDITION_FAILED
85-
py_is_error = new.status_code == HTTPStatus.NOT_FOUND
84+
php_is_error = php_response.status_code == HTTPStatus.PRECONDITION_FAILED
85+
py_is_error = py_response.status_code == HTTPStatus.NOT_FOUND
8686

8787
if php_is_error or py_is_error:
8888
# Both should be errors in the same cases
8989
assert php_is_error == py_is_error, (
90-
f"PHP status={original.status_code}, Python status={new.status_code}"
90+
f"PHP status={php_response.status_code}, Python status={py_response.status_code}"
9191
)
9292
# Verify Python API returns RFC 9457 format
93-
assert new.headers["content-type"] == "application/problem+json"
94-
error = new.json()
93+
assert py_response.headers["content-type"] == "application/problem+json"
94+
error = py_response.json()
9595
assert error["type"] == NoResultsError.uri
9696
assert error["code"] == "372"
97-
assert original.json()["error"]["message"] == "No results"
97+
assert php_response.json()["error"]["message"] == "No results"
9898
assert error["detail"] == "No datasets match the search criteria."
9999
return None
100-
new_json = new.json()
100+
py_json = py_response.json()
101101
# Qualities in new response are typed
102-
for dataset in new_json:
102+
for dataset in py_json:
103103
for quality in dataset["quality"]:
104104
quality["value"] = str(quality["value"])
105105

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

112112

tests/routers/openml/datasets_qualities_test.py

Lines changed: 18 additions & 18 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

@@ -130,63 +130,63 @@ async def test_get_quality(py_api: httpx.AsyncClient) -> None:
130130
async def test_get_quality_identical(
131131
data_id: int, py_api: httpx.AsyncClient, php_api: httpx.AsyncClient
132132
) -> None:
133-
python_response, php_response = await asyncio.gather(
133+
py_response, php_response = await asyncio.gather(
134134
py_api.get(f"/datasets/qualities/{data_id}"),
135135
php_api.get(f"/data/qualities/{data_id}"),
136136
)
137137
if php_response.status_code == HTTPStatus.OK:
138-
_assert_get_quality_success_equal(python_response, php_response)
138+
_assert_get_quality_success_equal(py_response, php_response)
139139
return
140140

141141
php_error_code = int(php_response.json()["error"]["code"])
142142
if php_error_code == 361: # noqa: PLR2004
143-
_assert_get_quality_error_dataset_not_found(python_response, php_response)
143+
_assert_get_quality_error_dataset_not_found(py_response, php_response)
144144
elif php_error_code == 364: # noqa: PLR2004
145-
_assert_get_quality_error_dataset_process_error(python_response, php_response)
145+
_assert_get_quality_error_dataset_process_error(py_response, php_response)
146146
else:
147147
msg = f"Dataset {data_id} response not under test:", php_response.json()
148148
raise AssertionError(msg)
149149

150150

151151
def _assert_get_quality_success_equal(
152-
python_response: httpx.Response, php_response: httpx.Response
152+
py_response: httpx.Response, php_response: httpx.Response
153153
) -> None:
154-
assert python_response.status_code == php_response.status_code
154+
assert py_response.status_code == php_response.status_code
155155
expected = [
156156
{
157157
"name": quality["name"],
158158
"value": None if quality["value"] == [] else float(quality["value"]),
159159
}
160160
for quality in php_response.json()["data_qualities"]["quality"]
161161
]
162-
assert python_response.json() == expected
162+
assert py_response.json() == expected
163163

164164

165165
def _assert_get_quality_error_dataset_not_found(
166-
python_response: httpx.Response, php_response: httpx.Response
166+
py_response: httpx.Response, php_response: httpx.Response
167167
) -> None:
168168
assert php_response.status_code == HTTPStatus.PRECONDITION_FAILED
169-
assert python_response.status_code == HTTPStatus.NOT_FOUND
169+
assert py_response.status_code == HTTPStatus.NOT_FOUND
170170

171171
php_error = php_response.json()["error"]
172-
py_error = python_response.json()
172+
py_error = py_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(
180-
python_response: httpx.Response, php_response: httpx.Response
180+
py_response: httpx.Response, php_response: httpx.Response
181181
) -> None:
182-
assert php_response.status_code == python_response.status_code
182+
assert py_response.status_code == php_response.status_code
183183

184184
php_error = php_response.json()["error"]
185-
py_error = python_response.json()
185+
py_error = py_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:]

0 commit comments

Comments
 (0)