Skip to content

Commit 1b7fe67

Browse files
committed
993 ruff got tough with the code
1 parent 9249d1d commit 1b7fe67

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

tests/extensions/test_custom.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests creating a custom extension"""
22

3-
import unittest
43
from datetime import datetime
54
from typing import Any, Generic, TypeVar, cast
65

@@ -135,6 +134,7 @@ def test_add_to_item_asset(add_extension_hooks: None) -> None:
135134
item_as_dict = item.to_dict()
136135
assert item_as_dict["assets"]["foo"]["test:prop"] == "bar"
137136

137+
138138
def test_add_to_item(add_extension_hooks: None) -> None:
139139
item = Item("an-id", None, None, datetime.now(), {})
140140
custom = CustomExtension.ext(item, add_if_missing=True)
@@ -143,6 +143,7 @@ def test_add_to_item(add_extension_hooks: None) -> None:
143143
item_as_dict = item.to_dict()
144144
assert item_as_dict["properties"]["test:prop"] == "foo"
145145

146+
146147
def test_add_to_catalog(add_extension_hooks: None) -> None:
147148
catalog = Catalog("an-id", "a description")
148149
custom = CustomExtension.ext(catalog, add_if_missing=True)
@@ -151,6 +152,7 @@ def test_add_to_catalog(add_extension_hooks: None) -> None:
151152
catalog_as_dict = catalog.to_dict()
152153
assert catalog_as_dict["test:prop"] == "foo"
153154

155+
154156
def test_add_to_collection(add_extension_hooks: None) -> None:
155157
collection = Collection(
156158
"an-id",
@@ -166,6 +168,7 @@ def test_add_to_collection(add_extension_hooks: None) -> None:
166168
collection_as_dict = collection.to_dict()
167169
assert collection_as_dict["test:prop"] == "foo"
168170

171+
169172
def test_add_to_collection_asset(add_extension_hooks: None) -> None:
170173
collection = Collection(
171174
"an-id",
@@ -182,17 +185,17 @@ def test_add_to_collection_asset(add_extension_hooks: None) -> None:
182185
collection_as_dict = collection.to_dict()
183186
assert collection_as_dict["assets"]["foo"]["test:prop"] == "bar"
184187

188+
185189
def test_ext_non_stac_object(add_extension_hooks: None) -> None:
186190
with pytest.raises(ExtensionTypeError):
187191
CustomExtension.ext({}) # type: ignore
188192

193+
189194
def test_migrates(add_extension_hooks: None) -> None:
190195
item = Item("an-id", None, None, datetime.now(), {})
191196
item_as_dict = item.to_dict()
192197
item_as_dict["stac_version"] = "1.0.0-rc.1"
193-
item_as_dict["stac_extensions"] = [
194-
"https://example.com/v1.0/custom-schema.json"
195-
]
198+
item_as_dict["stac_extensions"] = ["https://example.com/v1.0/custom-schema.json"]
196199
item_as_dict["properties"]["test:old-prop-name"] = "foo"
197200
item = Item.from_dict(item_as_dict, migrate=True)
198201
custom = CustomExtension.ext(item)

tests/extensions/test_eo.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import unittest
32

43
import pytest
54

@@ -32,6 +31,7 @@ def test_band_create() -> None:
3231
assert band.solar_illumination == 42.0
3332
assert band.__repr__() == "<Band name=B01>"
3433

34+
3535
def test_band_description_unknown_band() -> None:
3636
desc = Band.band_description("rainbow")
3737
assert desc is None
@@ -51,6 +51,7 @@ def test_to_from_dict() -> None:
5151
item_dict = json.load(f)
5252
assert_to_from_dict(Item, item_dict)
5353

54+
5455
def test_add_to() -> None:
5556
item = Item.from_file(PLAIN_ITEM)
5657
assert EOExtension.get_schema_uri() not in item.stac_extensions
@@ -69,13 +70,15 @@ def test_add_to() -> None:
6970
]
7071
assert len(eo_uris) == 1
7172

73+
7274
@pytest.mark.vcr()
7375
def test_validate_eo() -> None:
7476
item = pystac.Item.from_file(LANDSAT_EXAMPLE_URI)
7577
item2 = pystac.Item.from_file(BANDS_IN_ITEM_URI)
7678
item.validate()
7779
item2.validate()
7880

81+
7982
@pytest.mark.vcr()
8083
def test_bands() -> None:
8184
item = pystac.Item.from_file(BANDS_IN_ITEM_URI)
@@ -95,17 +98,19 @@ def test_bands() -> None:
9598

9699
EOExtension.ext(item).bands = new_bands
97100
assert (
98-
"Common name: red, Range: 0.6 to 0.7" ==
99-
item.properties["eo:bands"][0]["description"]
101+
"Common name: red, Range: 0.6 to 0.7"
102+
== item.properties["eo:bands"][0]["description"]
100103
)
101104
assert len(EOExtension.ext(item).bands or []) == 3
102105
item.validate()
103106

107+
104108
def test_asset_bands_s2() -> None:
105109
item = pystac.Item.from_file(S2_ITEM_URI)
106110
mtd_asset = item.get_assets()["mtd"]
107111
assert EOExtension.ext(mtd_asset).bands is None
108112

113+
109114
@pytest.mark.vcr()
110115
def test_asset_bands() -> None:
111116
item = pystac.Item.from_file(LANDSAT_EXAMPLE_URI)
@@ -162,6 +167,7 @@ def test_asset_bands() -> None:
162167

163168
assert len(item.assets["test"].extra_fields["eo:bands"]) == 3
164169

170+
165171
@pytest.mark.vcr()
166172
def test_cloud_cover() -> None:
167173
item = pystac.Item.from_file(LANDSAT_EXAMPLE_URI)
@@ -188,6 +194,7 @@ def test_cloud_cover() -> None:
188194

189195
item.validate()
190196

197+
191198
def test_summaries() -> None:
192199
col = pystac.Collection.from_file(EO_COLLECTION_URI)
193200
eo_summaries = EOExtension.summaries(col)
@@ -219,6 +226,7 @@ def test_summaries() -> None:
219226
assert col_dict["summaries"]["eo:cloud_cover"]["minimum"] == 1.0
220227
assert col_dict["summaries"]["eo:snow_cover"]["minimum"] == 4.0
221228

229+
222230
def test_summaries_adds_uri() -> None:
223231
col = pystac.Collection.from_file(EO_COLLECTION_URI)
224232
col.stac_extensions = []
@@ -234,6 +242,7 @@ def test_summaries_adds_uri() -> None:
234242
EOExtension.remove_from(col)
235243
assert EOExtension.get_schema_uri() not in col.stac_extensions
236244

245+
237246
def test_read_pre_09_fields_into_common_metadata() -> None:
238247
eo_item = pystac.Item.from_file(
239248
TestCases.get_path(
@@ -244,6 +253,7 @@ def test_read_pre_09_fields_into_common_metadata() -> None:
244253
assert eo_item.common_metadata.platform == "landsat-8"
245254
assert eo_item.common_metadata.instruments == ["oli_tirs"]
246255

256+
247257
def test_reads_asset_bands_in_pre_1_0_version() -> None:
248258
item = pystac.Item.from_file(
249259
TestCases.get_path(
@@ -256,6 +266,7 @@ def test_reads_asset_bands_in_pre_1_0_version() -> None:
256266
assert len(bands or []) == 1
257267
assert get_opt(bands)[0].common_name == "cirrus"
258268

269+
259270
def test_reads_gsd_in_pre_1_0_version() -> None:
260271
eo_item = pystac.Item.from_file(
261272
TestCases.get_path(
@@ -265,6 +276,7 @@ def test_reads_gsd_in_pre_1_0_version() -> None:
265276

266277
assert eo_item.common_metadata.gsd == 30.0
267278

279+
268280
def test_item_apply() -> None:
269281
item = pystac.Item.from_file(LANDSAT_EXAMPLE_URI)
270282
eo_ext = EOExtension.ext(item)
@@ -279,12 +291,14 @@ def test_item_apply() -> None:
279291
assert test_band.to_dict() == eo_ext.bands[0].to_dict()
280292
assert eo_ext.cloud_cover == 15
281293

294+
282295
def test_extend_invalid_object() -> None:
283296
link = pystac.Link("child", "https://some-domain.com/some/path/to.json")
284297

285298
with pytest.raises(pystac.ExtensionTypeError):
286299
EOExtension.ext(link) # type: ignore
287300

301+
288302
def test_extension_not_implemented() -> None:
289303
# Should raise exception if Item does not include extension URI
290304
item = pystac.Item.from_file(PLAIN_ITEM)
@@ -302,6 +316,7 @@ def test_extension_not_implemented() -> None:
302316
ownerless_asset = pystac.Asset.from_dict(asset.to_dict())
303317
_ = EOExtension.ext(ownerless_asset)
304318

319+
305320
def test_item_ext_add_to() -> None:
306321
item = pystac.Item.from_file(PLAIN_ITEM)
307322
assert EOExtension.get_schema_uri() not in item.stac_extensions
@@ -310,6 +325,7 @@ def test_item_ext_add_to() -> None:
310325

311326
assert EOExtension.get_schema_uri() in item.stac_extensions
312327

328+
313329
def test_asset_ext_add_to() -> None:
314330
item = pystac.Item.from_file(PLAIN_ITEM)
315331
assert EOExtension.get_schema_uri() not in item.stac_extensions
@@ -319,6 +335,7 @@ def test_asset_ext_add_to() -> None:
319335

320336
assert EOExtension.get_schema_uri() in item.stac_extensions
321337

338+
322339
def test_asset_ext_add_to_ownerless_asset() -> None:
323340
item = pystac.Item.from_file(PLAIN_ITEM)
324341
asset_dict = item.assets["thumbnail"].to_dict()
@@ -327,11 +344,13 @@ def test_asset_ext_add_to_ownerless_asset() -> None:
327344
with pytest.raises(pystac.STACError):
328345
_ = EOExtension.ext(asset, add_if_missing=True)
329346

347+
330348
def test_should_raise_exception_when_passing_invalid_extension_object() -> None:
331-
with pytest.raises(ExtensionTypeError,
332-
match=r"^EOExtension does not apply to type 'object'$"):
349+
with pytest.raises(
350+
ExtensionTypeError, match=r"^EOExtension does not apply to type 'object'$"
351+
):
333352
# calling it wrong purposely -------v
334-
EOExtension.ext(object()) # type: ignore
353+
EOExtension.ext(object()) # type: ignore
335354

336355

337356
def test_migration() -> None:

0 commit comments

Comments
 (0)