Skip to content

Commit

Permalink
tests: making sure upper case warnings are raised, not just random wa…
Browse files Browse the repository at this point in the history
…rnings.
  • Loading branch information
bnb32 committed Nov 9, 2024
1 parent de6c088 commit a181ae8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions sup3r/preprocessing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_date_range_kwargs(time_index):
kwargs['drop_leap'] = True

elif uneven_freq:
msg = (f'Got uneven frequency for time index: {time_index}')
msg = f'Got uneven frequency for time index: {time_index}'
warn(msg)
logger.warning(msg)

Expand Down Expand Up @@ -406,7 +406,7 @@ def parse_keys(
if just_coords:
features = list(default_coords)
elif has_feats:
features = _lowered(keys[0]) if keys[0] != 'all' else default_features
features = lowered(keys[0]) if keys[0] != 'all' else default_features
else:
features = []

Expand Down Expand Up @@ -493,6 +493,7 @@ def is_type_of(vals, vtype):


def _get_strings(vals):
vals = [vals] if isinstance(vals, str) else vals
return [v for v in vals if is_type_of(v, str)]


Expand Down
4 changes: 1 addition & 3 deletions tests/bias/test_qdm_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,7 @@ def test_fwp_integration(tmp_path):
f.attrs['log_base'] = 10
f.attrs['time_window_center'] = [182.5]

date_range_kwargs = get_date_range_kwargs(
pd.DatetimeIndex([np.datetime64(t) for t in ds.time.values])
)
date_range_kwargs = get_date_range_kwargs(pd.DatetimeIndex(ds.time.values))
bias_correct_kwargs = {
'u_100m': {
'feature_name': 'u_100m',
Expand Down
2 changes: 1 addition & 1 deletion tests/data_handlers/test_dh_nc_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_data_handling_nc_cc():

# upper case features warning
features = [f'U_{int(plevel)}pa', f'V_{int(plevel)}pa']
with pytest.warns():
with pytest.warns(match='Received some upper case features'):
handler = DataHandlerNCforCC(
pytest.FPS_GCM,
features=features,
Expand Down
2 changes: 1 addition & 1 deletion tests/derivers/test_height_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_plevel_height_interp_nc(shape, target, height, chunks):
assert no_transform.loaded

# warning about upper case features
with pytest.warns():
with pytest.warns(match='Received some upper case features'):
transform = Deriver(
no_transform.data,
derive_features,
Expand Down
4 changes: 2 additions & 2 deletions tests/derivers/test_single_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_unneeded_uv_transform(input_files, shape, target):
rasterizer = Rasterizer(input_files[0], target=target, shape=shape)

# upper case features warning
with pytest.warns():
with pytest.warns(match='Received some upper case features'):
deriver = Deriver(rasterizer.data, features=derive_features)

assert np.array_equal(
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_uv_transform(input_files, shape, target):
)

# warning about upper case features
with pytest.warns():
with pytest.warns(match='Received some upper case features'):
deriver = Deriver(rasterizer.data, features=derive_features)
u, v = transform_rotate_wind(
rasterizer['windspeed_100m'],
Expand Down
4 changes: 2 additions & 2 deletions tests/rasterizers/test_rasterizer_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_get_full_domain_nc():
rasterizer.loader[Dimension.LONGITUDE].min(),
),
)
dim_order = (Dimension.LATITUDE, Dimension.LONGITUDE, Dimension.TIME)
dim_order = (Dimension.SOUTH_NORTH, Dimension.WEST_EAST, Dimension.TIME)

# raise warning about upper case features
with pytest.warns():
with pytest.warns(match='Received some upper case features'):
assert np.array_equal(
rasterizer['U_100m'],
nc_res['u_100m'].transpose(*dim_order).data.astype(np.float32),
Expand Down

0 comments on commit a181ae8

Please sign in to comment.