|
| 1 | +""" |
| 2 | +Testing the wind_turbine module. |
| 3 | +""" |
| 4 | + |
| 5 | +__copyright__ = "Copyright oemof developer group" |
| 6 | +__license__ = "GPLv3" |
| 7 | + |
1 | 8 | import pytest |
2 | 9 | import os |
| 10 | +from windpowerlib.tools import WindpowerlibUserWarning |
3 | 11 |
|
4 | 12 | 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) |
6 | 15 |
|
7 | 16 |
|
8 | 17 | class TestWindTurbine: |
9 | 18 |
|
10 | | - def test_error_raising(self): |
| 19 | + def test_warning(self, recwarn): |
11 | 20 | source = os.path.join(os.path.dirname(__file__), '../example/data') |
12 | 21 | self.test_turbine_data = {'hub_height': 100, |
13 | 22 | 'rotor_diameter': 80, |
14 | 23 | 'turbine_type': 'turbine_not_in_file', |
15 | 24 | 'path': source} |
16 | | - # Raise system exit due to turbine type not in file |
17 | | - # with pytest.raises(SystemExit): |
18 | 25 | assert(WindTurbine(**self.test_turbine_data).power_curve is None) |
| 26 | + assert recwarn.pop(WindpowerlibUserWarning) |
19 | 27 |
|
20 | 28 | def test_get_turbine_data_from_file(self): |
21 | 29 | # Raise FileNotFoundError due to missing |
22 | 30 | with pytest.raises(FileNotFoundError): |
23 | 31 | get_turbine_data_from_file(turbine_type='...', |
24 | 32 | path='not_existent') |
25 | 33 |
|
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') |
0 commit comments