Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
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
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module = ["cdsapi.*", "multiurl.*", "py.*"]
# Same as Black.
indent-width = 4
line-length = 88
target-version = "py38"

[tool.ruff.lint]
ignore = [
Expand All @@ -53,7 +54,9 @@ select = [
# isort
"I",
# pydocstyle
"D"
"D",
# flake8-future-annotations
"FA"
]

[tool.ruff.lint.pycodestyle]
Expand Down
14 changes: 0 additions & 14 deletions tests/integration_test_40_results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import os
import pathlib
import random
from typing import Any
Expand All @@ -22,19 +21,6 @@ def test_results_asset(results: Results) -> None:
assert results.asset["file:size"] == 1


@pytest.mark.parametrize("target", ("dummy.grib", None))
def test_results_download(
monkeypatch: pytest.MonkeyPatch,
results: Results,
tmp_path: pathlib.Path,
target: str | None,
) -> None:
monkeypatch.chdir(tmp_path)
actual_target = results.download(target=target)
assert (actual_target != target) if target is None else (actual_target == target)
assert os.path.getsize(actual_target) == 1


@pytest.mark.parametrize("progress", [True, False])
def test_results_progress(
api_root_url: str,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_test_50_profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Literal

import pytest
Expand Down
93 changes: 93 additions & 0 deletions tests/test_40_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from __future__ import annotations

import os
import pathlib

import pytest
import responses

from cads_api_client import Results

RESULTS_URL = "http://localhost:8080/api/retrieve/v1/jobs/9bfc1362-2832-48e1-a235-359267420bb2/results"
RESULTS_JSON = {
"asset": {
"value": {
"type": "application/x-grib",
"href": "http://httpbin.org/bytes/1",
"file:size": 1,
}
}
}


@pytest.fixture
def results() -> Results:
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
RESULTS_URL,
json=RESULTS_JSON,
status=200,
content_type="application/json",
)
results = Results.from_request(
"get",
RESULTS_URL,
headers={},
session=None,
retry_options={"maximum_tries": 1},
request_options={},
download_options={},
sleep_max=120,
cleanup=False,
log_callback=None,
)
return results


@pytest.mark.parametrize(
"target,expected",
[
("dummy.grib", "dummy.grib"),
(None, "1"),
],
)
def test_results_download(
monkeypatch: pytest.MonkeyPatch,
results: Results,
tmp_path: pathlib.Path,
target: str | None,
expected: str,
) -> None:
monkeypatch.chdir(tmp_path)
actual = results.download(target=target)
assert actual == expected
assert os.path.getsize(actual) == 1


def test_results_asset(results: Results) -> None:
assert results.asset == {
"file:size": 1,
"href": "http://httpbin.org/bytes/1",
"type": "application/x-grib",
}


def test_results_content_length(results: Results) -> None:
assert results.content_length == 1


def test_results_content_type(results: Results) -> None:
assert results.content_type == "application/x-grib"


def test_results_json(results: Results) -> None:
assert results.json == RESULTS_JSON


def test_results_location(results: Results) -> None:
assert results.location == "http://httpbin.org/bytes/1"


def test_results_url(results: Results) -> None:
assert results.url == RESULTS_URL