Skip to content

Commit f474915

Browse files
committed
Test revised WindTurbine class
1 parent ede47a0 commit f474915

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

tests/test_wind_turbine.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,58 @@
1+
"""
2+
Testing the wind_turbine module.
3+
"""
4+
5+
__copyright__ = "Copyright oemof developer group"
6+
__license__ = "GPLv3"
7+
18
import pytest
29
import os
10+
from windpowerlib.tools import WindpowerlibUserWarning
311

412
from windpowerlib.wind_turbine import (get_turbine_data_from_file, WindTurbine,
5-
get_turbine_types)
13+
get_turbine_types,
14+
load_turbine_data_from_oedb)
615

716

817
class TestWindTurbine:
918

10-
def test_error_raising(self):
19+
def test_warning(self, recwarn):
1120
source = os.path.join(os.path.dirname(__file__), '../example/data')
1221
self.test_turbine_data = {'hub_height': 100,
1322
'rotor_diameter': 80,
1423
'turbine_type': 'turbine_not_in_file',
1524
'path': source}
16-
# Raise system exit due to turbine type not in file
17-
# with pytest.raises(SystemExit):
1825
assert(WindTurbine(**self.test_turbine_data).power_curve is None)
26+
assert recwarn.pop(WindpowerlibUserWarning)
1927

2028
def test_get_turbine_data_from_file(self):
2129
# Raise FileNotFoundError due to missing
2230
with pytest.raises(FileNotFoundError):
2331
get_turbine_data_from_file(turbine_type='...',
2432
path='not_existent')
2533

26-
def test_get_turbine_types(self):
27-
get_turbine_types(print_out=True, filter_=True)
28-
get_turbine_types(print_out=False, filter_=False)
34+
def test_get_turbine_types(self, capsys):
35+
get_turbine_types()
36+
captured = capsys.readouterr()
37+
assert 'Enercon' in captured.out
38+
get_turbine_types('oedb', print_out=False, filter_=False)
39+
msg = "`turbine_library` is 'wrong' but must be 'local' or 'oedb'."
40+
with pytest.raises(ValueError, match=msg):
41+
get_turbine_types('wrong')
42+
43+
def test_deduce_nominal_power(self):
44+
"""Test method to deduce nominal_power from power curve"""
45+
test_turbine_data = {'hub_height': 100,
46+
'rotor_diameter': 80,
47+
'turbine_type': 'N131/3000'}
48+
n131 = WindTurbine(**test_turbine_data)
49+
assert n131.nominal_power == 3000000.0
50+
n131.deduce_nominal_power_from_power_curve()
51+
assert n131.nominal_power == 3000000.0
52+
53+
def test_wrong_url_load_turbine_data(self):
54+
"""Load turbine data from oedb."""
55+
56+
with pytest.raises(ConnectionError,
57+
match="Database connection not successful"):
58+
load_turbine_data_from_oedb('wrong_schema')

windpowerlib/wind_turbine.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,31 @@ def get_turbine_data_from_file(turbine_type, path):
259259
return wpp_df
260260

261261

262-
def load_turbine_data_from_oedb():
262+
def load_turbine_data_from_oedb(schema = 'supply', table = 'turbine_library'):
263263
r"""
264264
Loads turbine library from the OpenEnergy database (oedb).
265265
266266
Turbine data is saved to csv files ('oedb_power_curves.csv',
267267
'oedb_power_coefficient_curves.csv' and 'oedb_nominal_power') for offline
268268
usage of the windpowerlib. If the files already exist they are overwritten.
269269
270+
Parameters
271+
----------
272+
schema : str
273+
Database schema of the turbine library.
274+
table : str
275+
Table name of the turbine library.
276+
270277
Returns
271278
-------
272279
:pandas:`pandas.DataFrame<frame>`
273280
Turbine data of different turbines such as 'manufacturer',
274281
'turbine_type', 'nominal_power'.
275282
276283
"""
277-
# TODO: Test is missing
278-
279284
# url of OpenEnergy Platform that contains the oedb
280285
oep_url = 'http://oep.iks.cs.ovgu.de/'
281-
# location of data
282-
schema = 'supply'
283-
table = 'turbine_library'
286+
284287
# load data
285288
result = requests.get(
286289
oep_url + '/api/v0/schema/{}/tables/{}/rows/?'.format(
@@ -399,7 +402,7 @@ def get_turbine_types(turbine_library='local', print_out=True, filter_=True):
399402
elif turbine_library == 'oedb':
400403
df = load_turbine_data_from_oedb()
401404
else:
402-
raise ValueError("`turbine_library` is {} ".format(turbine_library) +
405+
raise ValueError("`turbine_library` is '{}' ".format(turbine_library) +
403406
"but must be 'local' or 'oedb'.")
404407
if filter_:
405408
cp_curves_df = df.loc[df['has_cp_curve']][

0 commit comments

Comments
 (0)