Skip to content

Commit 9b39abb

Browse files
committed
Fix mypy
1 parent 2119b33 commit 9b39abb

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/stac_api_validator/validations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def is_geojson_type(maybe_type: Optional[str]) -> bool:
278278
def get_catalog(data_dict: Dict[str, Any], r_session: Session) -> Catalog:
279279
stac_io = StacIO.default()
280280
if r_session.headers and r_session.headers.get("Authorization"):
281-
stac_io.headers = r_session.headers
281+
stac_io.headers = r_session.headers # noqa, type: ignore
282282
stac_io.headers["Accept-Encoding"] = "*"
283283
catalog = Catalog.from_dict(data_dict)
284284
catalog._stac_io = stac_io

tests/test_validations.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pathlib
77
import unittest.mock
88
from copy import copy
9+
from typing import Dict
10+
from typing import Generator
911

1012
import pystac
1113
import pytest
@@ -15,12 +17,12 @@
1517

1618

1719
@pytest.fixture
18-
def r_session():
20+
def r_session() -> Generator[requests.Session, None, None]:
1921
yield requests.Session()
2022

2123

2224
@pytest.fixture
23-
def catalog_dict():
25+
def catalog_dict() -> Generator[Dict[str, str], None, None]:
2426
current_path = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
2527

2628
with open(current_path / "resources" / "landing_page.json") as f:
@@ -31,7 +33,7 @@ def catalog_dict():
3133

3234

3335
@pytest.fixture
34-
def sample_item():
36+
def sample_item() -> Generator[pystac.Item, None, None]:
3537
current_path = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
3638

3739
with open(current_path / "resources" / "sample-item.json") as f:
@@ -42,7 +44,7 @@ def sample_item():
4244

4345

4446
@pytest.fixture
45-
def expected_headers():
47+
def expected_headers() -> Generator[Dict[str, str], None, None]:
4648
yield {
4749
"User-Agent": "python-requests/2.28.2",
4850
"Accept-Encoding": "gzip, deflate",
@@ -52,17 +54,23 @@ def expected_headers():
5254
}
5355

5456

55-
def test_get_catalog(r_session, catalog_dict, expected_headers):
56-
r_session.headers = copy(expected_headers)
57+
def test_get_catalog(
58+
r_session: requests.Session,
59+
catalog_dict: Dict[str, str],
60+
expected_headers: Dict[str, str],
61+
) -> None:
62+
r_session.headers = copy(expected_headers) # type: ignore
5763
expected_headers.update({"Accept-Encoding": "*"})
5864

5965
catalog = validations.get_catalog(catalog_dict, r_session)
60-
assert catalog._stac_io.headers == expected_headers
66+
assert catalog._stac_io.headers == expected_headers # type: ignore
6167

6268

63-
def test_retrieve(r_session, expected_headers):
69+
def test_retrieve(
70+
r_session: requests.Session, expected_headers: Dict[str, str]
71+
) -> None:
6472
headers = {"Authorization": "api-key fake-api-key-value"}
65-
r_session.send = unittest.mock.MagicMock()
73+
r_session.send = unittest.mock.MagicMock() # type: ignore
6674
r_session.send.status_code = 500
6775

6876
validations.retrieve(
@@ -78,7 +86,11 @@ def test_retrieve(r_session, expected_headers):
7886
assert prepared_request_headers == expected_headers
7987

8088

81-
def test_validate_api(request, r_session, expected_headers):
89+
def test_validate_api(
90+
request: pytest.FixtureRequest,
91+
r_session: requests.Session,
92+
expected_headers: Dict[str, str],
93+
) -> None:
8294
if request.config.getoption("typeguard_packages"):
8395
pytest.skip(
8496
"The import hook that typeguard uses seems to break the mock below."
@@ -104,14 +116,18 @@ def test_validate_api(request, r_session, expected_headers):
104116

105117

106118
def test_validate_browseable(
107-
request, r_session, catalog_dict, sample_item, expected_headers
108-
):
119+
request: pytest.FixtureRequest,
120+
r_session: requests.Session,
121+
catalog_dict: Dict[str, str],
122+
sample_item: pystac.Item,
123+
expected_headers: Dict[str, str],
124+
) -> None:
109125
if request.config.getoption("typeguard_packages"):
110126
pytest.skip(
111127
"The import hook that typeguard uses seems to break the mock below."
112128
)
113129

114-
r_session.headers = copy(expected_headers)
130+
r_session.headers = copy(expected_headers) # type: ignore
115131

116132
with unittest.mock.patch(
117133
"stac_api_validator.validations.get_catalog"

0 commit comments

Comments
 (0)