Skip to content

Commit fa34e1a

Browse files
authored
Address click deprecation - use h5netcdf in cli tests (#2233)
### What kind of change does this PR introduce? * Address a Click warning about using `Group` instead of `MultiCommand`. I tested it, and the change is retrocompatible with 8.1 (our lowest click allowed) * Use `h5netcdf` in the CLI tests, hopefully that fixes the worker crashes ? ### Does this PR introduce a breaking change? No
2 parents ecacf95 + f1f3519 commit fa34e1a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/xclim/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ def _format_dict(data, formatter, key_fg="blue", spaces=2):
355355
formatter.write_text(click.style(" " * spaces + attr + " :", fg=key_fg) + " " + str(val))
356356

357357

358-
class XclimCli(click.MultiCommand):
358+
class XclimCli(click.Group):
359359
"""Main cli class."""
360360

361-
def list_commands(self, ctx) -> tuple[str, str, str, str, str, str]: # numpydoc ignore=PR01,RT01
361+
def list_commands(self, ctx) -> list[str, str, str, str, str, str]: # numpydoc ignore=PR01,RT01
362362
"""Return the available commands (other than the indicators)."""
363363
return (
364364
"indices",

tests/test_cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_normal_computation(tasmin_series, tasmax_series, pr_series, tmp_path, i
9494

9595
ds.to_netcdf(input_file, engine="h5netcdf")
9696

97-
args = ["-i", str(input_file), "-o", str(output_file), "-v", indicator]
97+
args = ["-i", str(input_file), "-o", str(output_file), "-v", "--engine", "h5netcdf", indicator]
9898
runner = CliRunner()
9999
results = runner.invoke(cli, args)
100100
for var_name in var_names:
@@ -126,6 +126,8 @@ def test_multi_input(tas_series, pr_series, tmp_path):
126126
"-o",
127127
str(output_file),
128128
"-v",
129+
"--engine",
130+
"h5netcdf",
129131
"solidprcptot",
130132
],
131133
)
@@ -150,6 +152,8 @@ def test_multi_output(tmp_path, open_dataset):
150152
"-o",
151153
str(output_file),
152154
"-v",
155+
"--engine",
156+
"h5netcdf",
153157
"wind_speed_from_vector",
154158
],
155159
)
@@ -172,6 +176,8 @@ def test_renaming_variable(tas_series, tmp_path):
172176
"-o",
173177
str(output_file),
174178
"-v",
179+
"--engine",
180+
"h5netcdf",
175181
"tn_mean",
176182
"--tasmin",
177183
"tas",
@@ -200,6 +206,8 @@ def test_indicator_chain(tas_series, tmp_path):
200206
"-o",
201207
str(output_file),
202208
"-v",
209+
"--engine",
210+
"h5netcdf",
203211
"tg_mean",
204212
"growing_degree_days",
205213
],
@@ -268,7 +276,7 @@ def test_suspicious_precipitation_flags(pr_series, tmp_path):
268276
bad_pr.to_netcdf(input_file)
269277

270278
runner = CliRunner()
271-
runner.invoke(cli, ["-i", str(input_file), "-o", str(output_file), "dataflags", "pr"])
279+
runner.invoke(cli, ["-i", str(input_file), "-o", str(output_file), "--engine", "h5netcdf", "dataflags", "pr"])
272280
with xr.open_dataset(output_file) as ds:
273281
for var in ds.data_vars:
274282
assert var

0 commit comments

Comments
 (0)