Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ignore = [

[tool.mypy]
strict = true
mypy_path = "src"
plugins = [
"pydantic.mypy"
]
Expand Down
6 changes: 3 additions & 3 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ def test_apply_defaults_to_siblings_applies_defaults() -> None:
input_ = {"defaults": {1: 1}, "other": {}}
expected = {"other": {1: 1}}
output = _apply_defaults_to_siblings(input_)
assert expected == output
assert output == expected


def test_apply_defaults_to_siblings_does_not_override() -> None:
input_ = {"defaults": {1: 1}, "other": {1: 2}}
expected = {"other": {1: 2}}
output = _apply_defaults_to_siblings(input_)
assert expected == output
assert output == expected


def test_apply_defaults_to_siblings_ignores_nontables() -> None:
input_ = {"defaults": {1: 1}, "other": {1: 2}, "not-a-table": 3}
expected = {"other": {1: 2}, "not-a-table": 3}
output = _apply_defaults_to_siblings(input_)
assert expected == output
assert output == expected


def test_load_configuration_adds_environment_variables(default_configuration_file: Path) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/dependencies/fetch_user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async def test_fetch_user(api_key: str, user: User, user_test: AsyncConnection)
async with aclosing(fetch_user(api_key, user_data=user_test)) as agen:
db_user = await anext(agen)
assert isinstance(db_user, User)
assert user.user_id == db_user.user_id
assert set(await user.get_groups()) == set(await db_user.get_groups())
assert db_user.user_id == user.user_id
assert set(await db_user.get_groups()) == set(await user.get_groups())


async def test_fetch_user_no_key_no_user() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/routers/openml/dataset_tag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ async def test_dataset_tag_invalid_tag_is_rejected(
tag: str,
py_api: httpx.AsyncClient,
) -> None:
new = await py_api.post(
response = await py_api.post(
f"/datasets/tag?api_key={ApiKey.ADMIN}",
json={"data_id": 1, "tag": tag},
)

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


# ── Direct call tests: tag_dataset ──
Expand Down
24 changes: 12 additions & 12 deletions tests/routers/openml/datasets_list_datasets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,39 @@ async def test_list_data_identical(
uri += f"/{'/'.join([str(v) for q in query for v in q])}"
uri += api_key_query

new, original = await asyncio.gather(
py_response, php_response = await asyncio.gather(
py_api.post(f"/datasets/list{api_key_query}", json=new_style),
php_api.get(uri),
)

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

if php_is_error or py_is_error:
# Both should be errors in the same cases
assert php_is_error == py_is_error, (
f"PHP status={original.status_code}, Python status={new.status_code}"
f"PHP status={php_response.status_code}, Python status={py_response.status_code}"
)
# Verify Python API returns RFC 9457 format
assert new.headers["content-type"] == "application/problem+json"
error = new.json()
assert py_response.headers["content-type"] == "application/problem+json"
error = py_response.json()
assert error["type"] == NoResultsError.uri
assert error["code"] == "372"
assert original.json()["error"]["message"] == "No results"
assert php_response.json()["error"]["message"] == "No results"
assert error["detail"] == "No datasets match the search criteria."
return None
new_json = new.json()
py_json = py_response.json()
# Qualities in new response are typed
for dataset in new_json:
for dataset in py_json:
for quality in dataset["quality"]:
quality["value"] = str(quality["value"])

# PHP API has a double nested dictionary that never has other entries
php_json = original.json()["data"]["dataset"]
assert len(php_json) == len(new_json)
assert php_json == new_json
php_json = php_response.json()["data"]["dataset"]
assert len(py_json) == len(php_json)
assert py_json == php_json
return None


Expand Down
36 changes: 18 additions & 18 deletions tests/routers/openml/datasets_qualities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def test_get_quality(py_api: httpx.AsyncClient) -> None:
{"name": "kNN1NErrRate", "value": 0.06347438752783964},
{"name": "kNN1NKappa", "value": 0.8261102938928316},
]
difference = deepdiff.DeepDiff(expected, response.json(), ignore_order=True)
difference = deepdiff.DeepDiff(response.json(), expected, ignore_order=True)
assert not difference


Expand All @@ -130,63 +130,63 @@ async def test_get_quality(py_api: httpx.AsyncClient) -> None:
async def test_get_quality_identical(
data_id: int, py_api: httpx.AsyncClient, php_api: httpx.AsyncClient
) -> None:
python_response, php_response = await asyncio.gather(
py_response, php_response = await asyncio.gather(
py_api.get(f"/datasets/qualities/{data_id}"),
php_api.get(f"/data/qualities/{data_id}"),
)
if php_response.status_code == HTTPStatus.OK:
_assert_get_quality_success_equal(python_response, php_response)
_assert_get_quality_success_equal(py_response, php_response)
return

php_error_code = int(php_response.json()["error"]["code"])
if php_error_code == 361: # noqa: PLR2004
_assert_get_quality_error_dataset_not_found(python_response, php_response)
_assert_get_quality_error_dataset_not_found(py_response, php_response)
elif php_error_code == 364: # noqa: PLR2004
_assert_get_quality_error_dataset_process_error(python_response, php_response)
_assert_get_quality_error_dataset_process_error(py_response, php_response)
else:
msg = f"Dataset {data_id} response not under test:", php_response.json()
raise AssertionError(msg)


def _assert_get_quality_success_equal(
python_response: httpx.Response, php_response: httpx.Response
py_response: httpx.Response, php_response: httpx.Response
) -> None:
assert python_response.status_code == php_response.status_code
assert py_response.status_code == php_response.status_code
expected = [
{
"name": quality["name"],
"value": None if quality["value"] == [] else float(quality["value"]),
}
for quality in php_response.json()["data_qualities"]["quality"]
]
assert python_response.json() == expected
assert py_response.json() == expected


def _assert_get_quality_error_dataset_not_found(
python_response: httpx.Response, php_response: httpx.Response
py_response: httpx.Response, php_response: httpx.Response
) -> None:
assert php_response.status_code == HTTPStatus.PRECONDITION_FAILED
assert python_response.status_code == HTTPStatus.NOT_FOUND
assert py_response.status_code == HTTPStatus.NOT_FOUND

php_error = php_response.json()["error"]
py_error = python_response.json()
py_error = py_response.json()

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


def _assert_get_quality_error_dataset_process_error(
python_response: httpx.Response, php_response: httpx.Response
py_response: httpx.Response, php_response: httpx.Response
) -> None:
assert php_response.status_code == python_response.status_code
assert py_response.status_code == php_response.status_code

php_error = php_response.json()["error"]
py_error = python_response.json()
py_error = py_response.json()

assert php_error["code"] == py_error["code"]
assert py_error["code"] == php_error["code"]
assert php_error["message"] == "Dataset processed with error"
assert py_error["title"] == "Dataset Processing Error"
# The PHP can add some additional unnecessary escapes.
assert php_error["additional_information"][:30] == py_error["detail"][:30]
assert php_error["additional_information"][-30:] == py_error["detail"][-30:]
assert py_error["detail"][:30] == php_error["additional_information"][:30]
assert py_error["detail"][-30:] == php_error["additional_information"][-30:]
Loading
Loading