From 1349a36361a2e903e64220c7c00681ef2cad5b69 Mon Sep 17 00:00:00 2001 From: Barbara Vreede Date: Wed, 23 Nov 2022 13:27:28 +0100 Subject: [PATCH 1/3] add test that ensembl and land raises error --- tests/test_cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1184ed1..e0d9be7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -168,6 +168,13 @@ def test_main_fetch(fetch): with pytest.raises(AssertionError): cli._execute(args) + # ensemble members are not available for Land + argv = ['monthly', '--startyear', '1990', '--endyear', '1990', + '--variables', 'total_precipitation', '--ensemble', + '--land'] + args = cli._parse_args(argv) + with pytest.raises(AssertionError): + cli._execute(args) @mock.patch("era5cli.info.Info", autospec=True) def test_main_info(info): From b8b1d546361e11cbb79ae0e7a3b3328a40694159 Mon Sep 17 00:00:00 2001 From: Barbara Vreede Date: Wed, 23 Nov 2022 15:31:32 +0100 Subject: [PATCH 2/3] move test to test_fetch and add error to product type --- era5cli/fetch.py | 6 ++++++ tests/test_cli.py | 7 ------- tests/test_fetch.py | 4 ++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/era5cli/fetch.py b/era5cli/fetch.py index ad3883c..d27e40c 100644 --- a/era5cli/fetch.py +++ b/era5cli/fetch.py @@ -250,6 +250,12 @@ def _split_variable_yr(self): def _product_type(self): """Construct the product type name from the options.""" + if self.land and self.ensemble: + raise ValueError( + "Era5-Land does not contain Ensemble statistics. " + "Aborting." + ) + if self.period == 'hourly' and self.ensemble and self.statistics: # The only configuration to return a list return [ diff --git a/tests/test_cli.py b/tests/test_cli.py index e0d9be7..1184ed1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -168,13 +168,6 @@ def test_main_fetch(fetch): with pytest.raises(AssertionError): cli._execute(args) - # ensemble members are not available for Land - argv = ['monthly', '--startyear', '1990', '--endyear', '1990', - '--variables', 'total_precipitation', '--ensemble', - '--land'] - args = cli._parse_args(argv) - with pytest.raises(AssertionError): - cli._execute(args) @mock.patch("era5cli.info.Info", autospec=True) def test_main_info(info): diff --git a/tests/test_fetch.py b/tests/test_fetch.py index f35f2d4..cc06cf8 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -334,6 +334,10 @@ def test_product_type(): producttype = era5._product_type() assert producttype is None + era5.ensemble = True + with pytest.raises(ValueError): + producttype = era5._product_type() + def test_check_levels(): """Test _check_levels function of Fetch class""" From 7066edfe743fe164d91e68bf20612900768abe7e Mon Sep 17 00:00:00 2001 From: Barbara Vreede Date: Tue, 29 Nov 2022 12:26:44 +0100 Subject: [PATCH 3/3] change ValueError to AssertionError --- era5cli/fetch.py | 6 ++---- tests/test_fetch.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/era5cli/fetch.py b/era5cli/fetch.py index d27e40c..5ce19cd 100644 --- a/era5cli/fetch.py +++ b/era5cli/fetch.py @@ -250,10 +250,8 @@ def _split_variable_yr(self): def _product_type(self): """Construct the product type name from the options.""" - if self.land and self.ensemble: - raise ValueError( - "Era5-Land does not contain Ensemble statistics. " - "Aborting." + assert not (self.land and self.ensemble), ( + 'ERA5-Land does not contain Ensemble statistics.' ) if self.period == 'hourly' and self.ensemble and self.statistics: diff --git a/tests/test_fetch.py b/tests/test_fetch.py index cc06cf8..7187c62 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -335,7 +335,7 @@ def test_product_type(): assert producttype is None era5.ensemble = True - with pytest.raises(ValueError): + with pytest.raises(AssertionError): producttype = era5._product_type()