From eedf553d3c2e4807dfa282d79a2169298f8f0b32 Mon Sep 17 00:00:00 2001 From: Velibor Zeli Date: Tue, 17 Dec 2019 10:59:15 +0100 Subject: [PATCH 1/3] Raise ValueError for unphysical WindTrubine --- windpowerlib/wind_turbine.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index a4210895..a9a02980 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -163,6 +163,11 @@ def __init__(self, hub_height, nominal_power=None, path='oedb', if self.rotor_diameter is None and turbine_data is not None: self.rotor_diameter = float(turbine_data['rotor_diameter']) + if self.rotor_diameter: + if self.hub_height <= 0.5*self.rotor_diameter: + msg = "1/2*rotor_diameter cannot be higher than hub_height" + raise ValueError(msg) + if self.power_curve is None and self.power_coefficient_curve is None: msg = ("The WindTurbine has been initialised without a power curve" " and without a power coefficient curve.\nYou will not be" From a3823edd1d78d4f4ff5ed5f089828c9ec2ef3368 Mon Sep 17 00:00:00 2001 From: Velibor Zeli Date: Tue, 17 Dec 2019 11:00:05 +0100 Subject: [PATCH 2/3] Test creation of unphysical WindTurbine --- tests/test_wind_turbine.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_wind_turbine.py b/tests/test_wind_turbine.py index 5ba627a2..3e79175f 100644 --- a/tests/test_wind_turbine.py +++ b/tests/test_wind_turbine.py @@ -97,3 +97,13 @@ def test_wrongly_defined_to_group_method(self): match="The 'number' and the 'total_capacity' " "parameter are mutually exclusive."): e_t_1.to_group(5, 3000) + + def test_create_unphysical_turbine(self): + char = { + 'hub_height': 80, + 'rotor_diameter': 160, + 'turbine_type': 'DUMMY 3', + 'path': self.source + } + with pytest.raises(ValueError): + WindTurbine(**char) From 678f291d3a4c53ea4ef28dbbaf6991637bba5428 Mon Sep 17 00:00:00 2001 From: Velibor Zeli Date: Thu, 16 Jan 2020 12:09:16 +0100 Subject: [PATCH 3/3] Match specific error message in test --- tests/test_wind_turbine.py | 3 ++- windpowerlib/wind_turbine.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_wind_turbine.py b/tests/test_wind_turbine.py index 3e79175f..c8766208 100644 --- a/tests/test_wind_turbine.py +++ b/tests/test_wind_turbine.py @@ -99,11 +99,12 @@ def test_wrongly_defined_to_group_method(self): e_t_1.to_group(5, 3000) def test_create_unphysical_turbine(self): + err_msg = "1/2rotor_diameter cannot be greater than hub_height" char = { 'hub_height': 80, 'rotor_diameter': 160, 'turbine_type': 'DUMMY 3', 'path': self.source } - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=err_msg): WindTurbine(**char) diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index a9a02980..851ea306 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -165,7 +165,7 @@ def __init__(self, hub_height, nominal_power=None, path='oedb', if self.rotor_diameter: if self.hub_height <= 0.5*self.rotor_diameter: - msg = "1/2*rotor_diameter cannot be higher than hub_height" + msg = "1/2rotor_diameter cannot be greater than hub_height" raise ValueError(msg) if self.power_curve is None and self.power_coefficient_curve is None: