Skip to content

Commit a352db5

Browse files
committed
Resolved errors related to SIM
1 parent 2348da4 commit a352db5

8 files changed

Lines changed: 57 additions & 60 deletions

File tree

earthaccess/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def download(
420420
"""
421421
provider = _normalize_location(str(provider))
422422

423-
if isinstance(granules, DataGranule):
423+
if isinstance(granules, DataGranule): # noqa: SIM114
424424
granules = [granules]
425425
elif isinstance(granules, str):
426426
granules = [granules]

earthaccess/search.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -740,13 +740,9 @@ def _valid_state(self) -> bool:
740740
# spatial params must be paired with a collection limiting parameter
741741
spatial_keys = ["point", "polygon", "bounding_box", "line"]
742742
collection_keys = ["short_name", "entry_title", "concept_id"]
743-
744-
if any(key in self.params for key in spatial_keys):
745-
if not any(key in self.params for key in collection_keys):
746-
return False
747-
748-
# all good then
749-
return True
743+
return not any(key in self.params for key in spatial_keys) or any(
744+
key in self.params for key in collection_keys
745+
)
750746

751747
def _is_cloud_hosted(self, granule: Any) -> bool:
752748
"""Check if a granule record, from CMR, advertises "direct access"."""

earthaccess/store.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _sibling_tempfile(sibling: Path) -> Generator[Path, None, None]:
201201
# directory if it does not already exist. Others succeed due to exist_ok.
202202
sibling.parent.mkdir(parents=True, exist_ok=True)
203203

204-
temp_fh = tempfile.NamedTemporaryFile(
204+
temp_fh = tempfile.NamedTemporaryFile( # noqa: SIM115
205205
dir=sibling.parent,
206206
prefix="partial_", # In case auto-delete fails, make it obvious to users
207207
delete=False,
@@ -266,9 +266,7 @@ def _derive_daac_provider(self, daac: str) -> str | None:
266266

267267
def _is_cloud_collection(self, concept_id: list[str]) -> bool:
268268
collection = DataCollections(self.auth).concept_id(concept_id).get()
269-
if len(collection) > 0 and "s3-links" in collection[0]["meta"]:
270-
return True
271-
return False
269+
return len(collection) > 0 and "s3-links" in collection[0]["meta"]
272270

273271
def _own_s3_credentials(self, links: list[dict[str, Any]]) -> str | None:
274272
for link in links:
@@ -293,7 +291,7 @@ def _running_in_us_west_2(self) -> bool:
293291
except Exception:
294292
return False
295293

296-
if resp.status_code == 200 and resp.content == b"us-west-2":
294+
if resp.status_code == 200 and resp.content == b"us-west-2": # noqa: SIM103
297295
# On AWS, in region us-west-2
298296
return True
299297
return False

earthaccess/utils/_validation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33

44
def valid_dataset_parameters(**kwargs: Any) -> bool:
5-
if len(kwargs) == 0:
6-
return False
7-
return True
5+
return len(kwargs) != 0

pyproject.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,6 @@ ignore = [
267267
"S301",
268268
"S603",
269269
"S607",
270-
"SIM101",
271-
"SIM102",
272-
"SIM103",
273-
"SIM114",
274-
"SIM115",
275-
"SIM117",
276-
"SIM300",
277270
"SLF001",
278271
"TD002",
279272
"TD003",

tests/integration/test_api.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ def test_download_immediate_failure(tmp_path: Path):
236236
count=3,
237237
)
238238

239-
with patch.object(earthaccess.__store__, "_download_file", fail_to_download_file):
240-
with pytest.raises(IOError, match="Download failed"):
241-
# By default, we set pqdm exception_behavior to "immediate" so that
242-
# it simply propagates the first download error it encounters, halting
243-
# any further downloads.
244-
earthaccess.download(results, tmp_path, pqdm_kwargs=dict(disable=True))
239+
with (
240+
patch.object(earthaccess.__store__, "_download_file", fail_to_download_file),
241+
pytest.raises(IOError, match="Download failed"),
242+
):
243+
# By default, we set pqdm exception_behavior to "immediate" so that
244+
# it simply propagates the first download error it encounters, halting
245+
# any further downloads.
246+
earthaccess.download(results, tmp_path, pqdm_kwargs=dict(disable=True))
245247

246248

247249
def test_download_deferred_failure(tmp_path: Path):
@@ -253,7 +255,7 @@ def test_download_deferred_failure(tmp_path: Path):
253255
count=count,
254256
)
255257

256-
with patch.object(earthaccess.__store__, "_download_file", fail_to_download_file):
258+
with patch.object(earthaccess.__store__, "_download_file", fail_to_download_file): # noqa: SIM117
257259
# With "deferred" exceptions, pqdm catches all exceptions, then at the end
258260
# raises a single generic Exception, passing the sequence of caught exceptions
259261
# as arguments to the Exception constructor.

tests/unit/test_store.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,12 @@ def test_sibling_tempfile_error(tmp_path):
392392
orig_text = "Should get replaced"
393393
new_text = "New-fangled text"
394394
trg_file.write_text(orig_text)
395-
with pytest.raises(Exception, match="Some error to trigger cleanup"):
396-
with _sibling_tempfile(trg_file) as temp_file:
397-
temp_file.write_text(new_text)
398-
raise RuntimeError("Some error to trigger cleanup")
395+
with (
396+
pytest.raises(Exception, match="Some error to trigger cleanup"),
397+
_sibling_tempfile(trg_file) as temp_file,
398+
):
399+
temp_file.write_text(new_text)
400+
raise RuntimeError("Some error to trigger cleanup")
399401
assert not temp_file.exists()
400402
assert trg_file.exists()
401403
assert trg_file.read_text() == orig_text

tests/unit/test_virtual.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ def test_virtualize_multi_granule_no_concat_dim_raises() -> None:
7272
"""virtualize() raises ValueError for >1 granule without concat_dim."""
7373
from earthaccess.virtual.core import virtualize
7474

75-
with patch(
76-
"earthaccess.virtual.core.build_obstore_registry",
77-
return_value=MagicMock(),
75+
with (
76+
patch(
77+
"earthaccess.virtual.core.build_obstore_registry", return_value=MagicMock(),
78+
),
79+
pytest.raises(ValueError, match="concat_dim"),
7880
):
79-
with pytest.raises(ValueError, match="concat_dim"):
80-
virtualize(_make_granules(2))
81+
virtualize(_make_granules(2))
8182

8283

8384
def test_virtualize_invalid_parser_string_raises() -> None:
@@ -99,9 +100,12 @@ def test_virtualize_load_false_returns_virtual_dataset() -> None:
99100

100101
mock_vds = MagicMock()
101102
reg_patch, open_patch = _patch_internals(mock_vds)
102-
with reg_patch, open_patch:
103-
with patch("earthaccess.virtual.core._load_via_kerchunk") as mock_load:
104-
result = virtualize(_make_granules(1), load=False)
103+
with (
104+
reg_patch,
105+
open_patch,
106+
patch("earthaccess.virtual.core._load_via_kerchunk") as mock_load,
107+
):
108+
result = virtualize(_make_granules(1), load=False)
105109

106110
assert result is mock_vds
107111
mock_load.assert_not_called()
@@ -113,16 +117,18 @@ def test_virtualize_load_true_delegates_to_kerchunk(tmp_path) -> None:
113117

114118
expected_ds = MagicMock()
115119
reg_patch, open_patch = _patch_internals()
116-
with reg_patch, open_patch:
117-
with patch(
118-
"earthaccess.virtual.core._load_via_kerchunk",
119-
return_value=expected_ds,
120-
) as mock_load:
121-
result = virtualize(
122-
_make_granules(1),
123-
load=True,
124-
reference_dir=str(tmp_path),
125-
)
120+
with (
121+
reg_patch,
122+
open_patch,
123+
patch(
124+
"earthaccess.virtual.core._load_via_kerchunk", return_value=expected_ds,
125+
) as mock_load,
126+
):
127+
result = virtualize(
128+
_make_granules(1),
129+
load=True,
130+
reference_dir=str(tmp_path),
131+
)
126132

127133
mock_load.assert_called_once()
128134
assert result is expected_ds
@@ -146,16 +152,18 @@ def side_effect(*args, **kwargs):
146152
raise FileNotFoundError("no .dmrpp sidecar")
147153
return mock_vds_hdf
148154

149-
with patch(
150-
"earthaccess.virtual.core.build_obstore_registry",
151-
return_value=MagicMock(),
152-
):
153-
with patch(
155+
with (
156+
patch(
157+
"earthaccess.virtual.core.build_obstore_registry",
158+
return_value=MagicMock(),
159+
),
160+
patch(
154161
"earthaccess.virtual.core._open_virtual_mfdataset",
155162
side_effect=side_effect,
156-
):
157-
with pytest.warns(UserWarning, match="HDFParser"):
158-
result = virtualize(_make_granules(1), parser="DMRPPParser")
163+
),
164+
pytest.warns(UserWarning, match="HDFParser"),
165+
):
166+
result = virtualize(_make_granules(1), parser="DMRPPParser")
159167

160168
assert result is mock_vds_hdf
161169
assert call_count["n"] == 2

0 commit comments

Comments
 (0)