Skip to content

Commit 4df187e

Browse files
committed
TST: some tests
1 parent 19d56d3 commit 4df187e

2 files changed

Lines changed: 82 additions & 9 deletions

File tree

tests/integration/environment/test_environment.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ def test_gefs_atmosphere(mock_show, example_spaceport_env): # pylint: disable=u
178178
example_spaceport_env : rocketpy.Environment
179179
Example environment object to be tested.
180180
"""
181-
example_spaceport_env.set_atmospheric_model(type="Ensemble", file="GEFS")
182-
assert example_spaceport_env.all_info() is None
181+
with pytest.raises(
182+
ValueError,
183+
match="GEFS latest-model shortcut is currently unavailable",
184+
):
185+
example_spaceport_env.set_atmospheric_model(type="Ensemble", file="GEFS")
183186

184187

185188
@pytest.mark.slow
@@ -234,13 +237,15 @@ def test_hiresw_ensemble_atmosphere(mock_show, example_spaceport_env): # pylint
234237

235238
example_spaceport_env.set_date(date_info)
236239

237-
example_spaceport_env.set_atmospheric_model(
238-
type="Forecast",
239-
file="HIRESW",
240-
dictionary="HIRESW",
241-
)
242-
243-
assert example_spaceport_env.all_info() is None
240+
with pytest.raises(
241+
ValueError,
242+
match="HIRESW latest-model shortcut is currently unavailable",
243+
):
244+
example_spaceport_env.set_atmospheric_model(
245+
type="Forecast",
246+
file="HIRESW",
247+
dictionary="HIRESW",
248+
)
244249

245250

246251
@pytest.mark.skip(reason="CMC model is currently not working")

tests/unit/environment/test_environment.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytz
77

88
from rocketpy import Environment
9+
from rocketpy.environment.weather_model_mapping import WeatherModelMapping
910
from rocketpy.environment.tools import geodesic_to_utm, utm_to_geodesic
1011

1112

@@ -243,3 +244,70 @@ def test_environment_export_environment_exports_valid_environment_json(
243244
)
244245

245246
os.remove("environment.json")
247+
248+
249+
class _DummyDataset:
250+
"""Small test double that mimics a netCDF dataset variables mapping."""
251+
252+
def __init__(self, variable_names):
253+
self.variables = {name: object() for name in variable_names}
254+
255+
256+
def test_resolve_dictionary_keeps_compatible_mapping(example_plain_env):
257+
"""Keep the user-selected mapping when it already matches dataset keys."""
258+
gfs_mapping = example_plain_env._Environment__weather_model_map.get("GFS")
259+
dataset = _DummyDataset(
260+
[
261+
"time",
262+
"lat",
263+
"lon",
264+
"isobaric",
265+
"Temperature_isobaric",
266+
"Geopotential_height_isobaric",
267+
"u-component_of_wind_isobaric",
268+
"v-component_of_wind_isobaric",
269+
]
270+
)
271+
272+
resolved = example_plain_env._Environment__resolve_dictionary_for_dataset(
273+
gfs_mapping, dataset
274+
)
275+
276+
assert resolved is gfs_mapping
277+
278+
279+
def test_resolve_dictionary_falls_back_to_legacy_mapping(example_plain_env):
280+
"""Fallback to a compatible built-in mapping for legacy NOMADS-style files."""
281+
thredds_gfs_mapping = example_plain_env._Environment__weather_model_map.get("GFS")
282+
dataset = _DummyDataset(
283+
[
284+
"time",
285+
"lat",
286+
"lon",
287+
"lev",
288+
"tmpprs",
289+
"hgtprs",
290+
"ugrdprs",
291+
"vgrdprs",
292+
]
293+
)
294+
295+
resolved = example_plain_env._Environment__resolve_dictionary_for_dataset(
296+
thredds_gfs_mapping, dataset
297+
)
298+
299+
# Explicit legacy mappings should be preferred over unrelated model mappings.
300+
assert resolved == example_plain_env._Environment__weather_model_map.get(
301+
"GFS_LEGACY"
302+
)
303+
assert resolved["level"] == "lev"
304+
assert resolved["temperature"] == "tmpprs"
305+
assert resolved["geopotential_height"] == "hgtprs"
306+
307+
308+
def test_weather_model_mapping_exposes_legacy_aliases():
309+
"""Legacy mapping names should be available and case-insensitive."""
310+
mapping = WeatherModelMapping()
311+
312+
assert mapping.get("GFS_LEGACY")["temperature"] == "tmpprs"
313+
assert mapping.get("gfs_legacy")["temperature"] == "tmpprs"

0 commit comments

Comments
 (0)