Skip to content

Commit 6426c78

Browse files
committed
Add tests
1 parent 5dbddcb commit 6426c78

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

tests/test_wind_turbine.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
class TestWindTurbine:
1818

19+
@classmethod
20+
def setup_class(cls):
21+
"""Setup default values"""
22+
cls.source = os.path.join(os.path.dirname(__file__), '../example/data')
23+
1924
def test_warning(self, recwarn):
20-
source = os.path.join(os.path.dirname(__file__), '../example/data')
2125
test_turbine_data = {'hub_height': 100,
2226
'rotor_diameter': 80,
2327
'turbine_type': 'turbine_not_in_file',
24-
'path': source}
28+
'path': self.source}
2529
assert(WindTurbine(**test_turbine_data).power_curve is None)
2630
assert recwarn.pop(WindpowerlibUserWarning)
2731

@@ -50,3 +54,27 @@ def test_wrong_url_load_turbine_data(self):
5054
@pytest.mark.filterwarnings("ignore:The WindTurbine")
5155
def test_string_representation_of_wind_turbine(self):
5256
assert "Wind turbine: ['hub height=120 m'" in repr(WindTurbine(120))
57+
58+
def test_to_group_method(self):
59+
example_turbine = {
60+
'hub_height': 100,
61+
'rotor_diameter': 70,
62+
'turbine_type': 'DUMMY 3',
63+
'path': self.source}
64+
e_t_1 = WindTurbine(**example_turbine)
65+
assert(isinstance(e_t_1.to_group(5), dict))
66+
assert(e_t_1.to_group(5)['number_of_turbines'] == 5)
67+
assert(e_t_1.to_group(number_turbines=5)['number_of_turbines'] == 5)
68+
assert(e_t_1.to_group(total_capacity=3e6)['number_of_turbines'] == 2.0)
69+
70+
def test_wrongly_defined_to_group_method(self):
71+
example_turbine = {
72+
'hub_height': 100,
73+
'rotor_diameter': 70,
74+
'turbine_type': 'DUMMY 3',
75+
'path': self.source}
76+
e_t_1 = WindTurbine(**example_turbine)
77+
with pytest.raises(ValueError,
78+
match="The 'number' and the 'total_capacity"
79+
" parameter are mutually exclusive."):
80+
e_t_1.to_group(5, 3000)

windpowerlib/wind_farm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class WindFarm(object):
9393
>>> example_farm = wind_farm.WindFarm(**example_farm_data)
9494
>>> print(example_farm.nominal_power)
9595
31200000.0
96+
>>> # turbine fleet as list of WindTurbine using the 'to_group' method.
97+
>>> wind_turbine_fleet = [e126.to_group(number_turbines=6),
98+
... v90.to_group(total_capacity=3 * 2e6)]
99+
>>> example_farm = wind_farm.WindFarm(wind_turbine_fleet)
100+
>>> print(example_farm.nominal_power)
101+
31200000.0
96102
97103
"""
98104

windpowerlib/wind_turbine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ def __repr__(self):
200200

201201
def to_group(self, number_turbines=None, total_capacity=None):
202202
if number_turbines is not None and total_capacity is not None:
203-
raise ValueError("The 'number' and the 'total_capacity are"
204-
" mutually exclusive. Use just one of them.")
203+
raise ValueError("The 'number' and the 'total_capacity parameter "
204+
"are mutually exclusive. Use just one of them.")
205205
elif total_capacity is not None:
206206
number_turbines = total_capacity / self.nominal_power
207207
elif number_turbines is None:

0 commit comments

Comments
 (0)