Skip to content

Commit ec7b239

Browse files
MNT: fix develop CI with pandas 3 and pylint 4 (#1211)
* TST: write generic surface CSV fixtures to pathlib paths pandas 3 treats py.path.local as a writable buffer and each chunk overwrites the file, leaving only the last row; tmp_path_factory avoids it. * MNT: silence pylint 4 abstract-method false positives Optional methods that raise NotImplementedError (polations, sensors, plots) are now reported as abstract; also move the broad-exception pragma onto the except line. * BUG: raise RuntimeError when Open-Elevation returns an error payload The API answers {"code": "temporarily_unavailable", ...} without "results", which leaked a KeyError instead of the documented RuntimeError.
2 parents a50d07d + e96d0ff commit ec7b239

6 files changed

Lines changed: 25 additions & 10 deletions

File tree

‎.pylintrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ disable=raw-checker-failed,
501501
method-cache-max-size-none,
502502
no-else-raise, # pointless
503503
unnecessary-lambda-assignment, # ruff already checks this
504+
abstract-method, # NotImplementedError marks optional methods (polations, sensors, plots)
504505

505506

506507

‎rocketpy/environment/fetchers/elevation_fetcher.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ def fetch_open_elevation(lat, lon):
3939
except (
4040
requests.exceptions.RequestException,
4141
requests.exceptions.JSONDecodeError,
42+
KeyError,
43+
IndexError,
4244
) as e:
4345
raise RuntimeError("Unable to reach Open-Elevation API servers.") from e

‎rocketpy/tools.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,7 @@ def wrapper(*args, **kwargs):
12031203
for i in range(max_attempts):
12041204
try:
12051205
return func(*args, **kwargs)
1206-
# pylint: disable=broad-except
1207-
except Exception as e: # pragma: no cover
1206+
except Exception as e: # pragma: no cover # pylint: disable=broad-exception-caught
12081207
if i == max_attempts - 1:
12091208
raise e from None
12101209
delay = min(delay * 2, max_delay)

‎tests/fixtures/generic_surfaces/generic_surfaces_fixtures.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44

55
@pytest.fixture(scope="session")
6-
def filename_valid_coeff(tmpdir_factory):
6+
def filename_valid_coeff(tmp_path_factory):
77
"""Creates temporary files used to test if generic surfaces
88
initializes correctly from CSV files"""
9-
filename = tmpdir_factory.mktemp("aero_surface_data").join("valid_coefficients.csv")
9+
filename = tmp_path_factory.mktemp("aero_surface_data").joinpath(
10+
"valid_coefficients.csv"
11+
)
1012
pd.DataFrame(
1113
{
1214
"alpha": [0, 1, 2, 3, 0.1],
@@ -31,10 +33,10 @@ def filename_valid_coeff(tmpdir_factory):
3133
},
3234
)
3335
)
34-
def filename_invalid_coeff(tmpdir_factory, request):
36+
def filename_invalid_coeff(tmp_path_factory, request):
3537
"""Creates temporary CSV files used to test if generic surfaces
3638
raises errors when initialized incorrectly from CSV files"""
37-
filename = tmpdir_factory.mktemp("aero_surface_data").join(
39+
filename = tmp_path_factory.mktemp("aero_surface_data").joinpath(
3840
"tmp_invalid_coefficients.csv"
3941
)
4042
pd.DataFrame(request.param).to_csv(filename, index=False)

‎tests/fixtures/generic_surfaces/linear_generic_surfaces_fixtures.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44

55
@pytest.fixture(scope="session")
6-
def filename_valid_coeff_linear_generic_surface(tmpdir_factory):
6+
def filename_valid_coeff_linear_generic_surface(tmp_path_factory):
77
"""Creates temporary files used to test if a linear generic surface
88
initializes correctly from CSV files"""
9-
filename = tmpdir_factory.mktemp("aero_surface_data").join(
9+
filename = tmp_path_factory.mktemp("aero_surface_data").joinpath(
1010
"valid_coefficients_lgs.csv"
1111
)
1212
pd.DataFrame(
@@ -33,10 +33,10 @@ def filename_valid_coeff_linear_generic_surface(tmpdir_factory):
3333
},
3434
)
3535
)
36-
def filename_invalid_coeff_linear_generic_surface(tmpdir_factory, request):
36+
def filename_invalid_coeff_linear_generic_surface(tmp_path_factory, request):
3737
"""Creates temporary CSV files used to test if a linear generic surface
3838
raises errors when initialized incorrectly from CSV files"""
39-
filename = tmpdir_factory.mktemp("aero_surface_data").join(
39+
filename = tmp_path_factory.mktemp("aero_surface_data").joinpath(
4040
"tmp_invalid_coefficients_lgs.csv"
4141
)
4242
pd.DataFrame(request.param).to_csv(filename, index=False)

‎tests/unit/environment/test_fetchers.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,14 @@ def test_resolve_noaa_collection_path_rejects_unknown_model():
501501
"""Unknown shortcuts must fail with an actionable ValueError."""
502502
with pytest.raises(ValueError, match="Unknown NOAA model collection"):
503503
fetchers.resolve_noaa_collection_path("not-a-model")
504+
505+
506+
def test_fetch_open_elevation_error_payload_raises_runtime_error(monkeypatch):
507+
"""An error payload (no ``results``) must surface as the documented RuntimeError."""
508+
payload = {"code": "temporarily_unavailable", "error": "Retry shortly."}
509+
monkeypatch.setattr(
510+
fetchers.requests, "get", lambda *a, **k: _FakeResponse(payload)
511+
)
512+
monkeypatch.setattr("rocketpy.tools.time.sleep", lambda _: None)
513+
with pytest.raises(RuntimeError, match="Open-Elevation"):
514+
fetchers.fetch_open_elevation(48.858844, 2.294351)

0 commit comments

Comments
 (0)