|
1 | 1 | import pytest |
2 | | -import pandas as pd |
3 | 2 | import os |
4 | 3 |
|
5 | 4 | from windpowerlib.wind_turbine import (get_turbine_data_from_file, WindTurbine, |
|
8 | 7 |
|
9 | 8 | class TestWindTurbine: |
10 | 9 |
|
11 | | - def test_initialization_power_curve(self): |
12 | | - |
13 | | - # power curve from oedb turbine data |
14 | | - self.test_turbine_data = {'hub_height': 100, |
15 | | - 'power_curve': True, |
16 | | - 'turbine_type': 'E-126/4200'} |
17 | | - try: |
18 | | - WindTurbine(**self.test_turbine_data) |
19 | | - assert True |
20 | | - except: |
21 | | - assert False |
22 | | - # power curve from self provided csv file |
23 | | - self.test_turbine_data = { |
24 | | - 'hub_height': 100, |
25 | | - 'power_curve': 'example_power_curves.csv', |
26 | | - 'turbine_type': 'DUMMY 3', |
27 | | - 'path': os.path.join(os.path.dirname(__file__), '../example/data')} |
28 | | - try: |
29 | | - WindTurbine(**self.test_turbine_data) |
30 | | - assert True |
31 | | - except: |
32 | | - assert False |
33 | | - |
34 | | - # directly provided power curve (dictionary) |
35 | | - self.test_turbine_data = {'hub_height': 100, |
36 | | - 'power_curve': {'wind_speed': [0, 10], |
37 | | - 'value': [0, 3]}} |
38 | | - try: |
39 | | - WindTurbine(**self.test_turbine_data) |
40 | | - assert True |
41 | | - except: |
42 | | - assert False |
43 | | - |
44 | | - # directly provided power curve (dataframe) |
45 | | - self.test_turbine_data = { |
46 | | - 'hub_height': 100, |
47 | | - 'power_curve': pd.DataFrame({'wind_speed': [0, 10], |
48 | | - 'value': [0, 3]})} |
49 | | - try: |
50 | | - WindTurbine(**self.test_turbine_data) |
51 | | - assert True |
52 | | - except: |
53 | | - assert False |
54 | | - |
55 | | - def test_initialization_power_coefficient_curve(self): |
56 | | - |
57 | | - # power coefficient curve from oedb turbine data |
58 | | - self.test_turbine_data = {'hub_height': 100, |
59 | | - 'power_coefficient_curve': True, |
60 | | - 'turbine_type': 'E-126/4200'} |
61 | | - try: |
62 | | - WindTurbine(**self.test_turbine_data) |
63 | | - assert True |
64 | | - except: |
65 | | - assert False |
66 | | - |
67 | | - # power coefficient curve from self provided csv file |
68 | | - self.test_turbine_data = { |
69 | | - 'hub_height': 100, |
70 | | - 'power_coefficient_curve': 'example_power_curves.csv', |
71 | | - 'nominal_power': 'example_turbine_data.csv', |
72 | | - 'turbine_type': 'DUMMY 3', |
73 | | - 'path': os.path.join(os.path.dirname(__file__), '../example/data')} |
74 | | - try: |
75 | | - WindTurbine(**self.test_turbine_data) |
76 | | - assert True |
77 | | - except: |
78 | | - assert False |
79 | | - |
80 | | - # directly provided power coefficient curve (dictionary) |
81 | | - self.test_turbine_data = {'hub_height': 100, |
82 | | - 'power_coefficient_curve': |
83 | | - {'wind_speed': [0, 10], |
84 | | - 'value': [0, 0.3]}, |
85 | | - 'nominal_power': 3e6} |
86 | | - try: |
87 | | - WindTurbine(**self.test_turbine_data) |
88 | | - assert True |
89 | | - except: |
90 | | - assert False |
91 | | - |
92 | | - # directly provided power coefficient curve (dataframe) |
93 | | - self.test_turbine_data = {'hub_height': 100, |
94 | | - 'power_coefficient_curve': |
95 | | - pd.DataFrame({ |
96 | | - 'wind_speed': [0, 10], |
97 | | - 'value': [0, 3]}), |
98 | | - 'nominal_power': 3e6} |
99 | | - try: |
100 | | - WindTurbine(**self.test_turbine_data) |
101 | | - assert True |
102 | | - except: |
103 | | - assert False |
104 | | - |
105 | 10 | def test_error_raising(self): |
106 | | - |
107 | | - # Raise KeyError due to turbine type not in oedb turbine data |
108 | | - self.test_turbine_data = {'hub_height': 100, |
109 | | - 'power_curve': True, |
110 | | - 'turbine_type': 'E-turbine_not_in_file/4200'} |
111 | | - with pytest.raises(KeyError): |
112 | | - WindTurbine(**self.test_turbine_data) |
113 | | - |
114 | | - # Raise KeyError due to turbine type not in file |
115 | | - self.test_turbine_data = { |
116 | | - 'hub_height': 100, |
117 | | - 'power_curve': True, |
118 | | - 'turbine_type': 'turbine_not_in_file', |
119 | | - 'power_coefficient_curve': 'example_power_curves.csv', |
120 | | - 'path': os.path.join(os.path.dirname(__file__), '../example/data')} |
121 | | - with pytest.raises(KeyError): |
122 | | - WindTurbine(**self.test_turbine_data) |
123 | | - |
124 | | - # Raise TypeError due to invalid type for power curve and power |
125 | | - # coefficient curve |
126 | | - self.test_turbine_data = {'hub_height': 100, |
127 | | - 'power_curve': 3.0} |
128 | | - with pytest.raises(TypeError): |
129 | | - WindTurbine(**self.test_turbine_data) |
130 | | - |
131 | | - self.test_turbine_data = {'hub_height': 100, |
132 | | - 'power_coefficient_curve': 3.0} |
133 | | - with pytest.raises(TypeError): |
134 | | - WindTurbine(**self.test_turbine_data) |
135 | | - |
136 | | - # Raise TypeError due to invalid type for nominal power |
137 | | - self.test_turbine_data = {'hub_height': 100, |
138 | | - 'power_curve': True, |
139 | | - 'turbine_type': 'E-126/4200', |
140 | | - 'nominal_power': [3]} |
141 | | - with pytest.raises(TypeError): |
142 | | - WindTurbine(**self.test_turbine_data) |
143 | | - |
144 | | - # Raise AttributeError in case no power or power coefficient curve |
145 | | - # is set |
146 | | - self.test_turbine_data = {'hub_height': 100} |
147 | | - with pytest.raises(AttributeError): |
148 | | - WindTurbine(**self.test_turbine_data) |
149 | | - |
150 | | - # Raise ValueError due to missing nominal power when using power |
151 | | - # coefficient curve |
| 11 | + source = os.path.join(os.path.dirname(__file__), '../example/data') |
152 | 12 | self.test_turbine_data = {'hub_height': 100, |
153 | | - 'power_coefficient_curve': |
154 | | - pd.DataFrame({ |
155 | | - 'wind_speed': [0, 10], |
156 | | - 'value': [0, 3]})} |
157 | | - with pytest.raises(ValueError): |
158 | | - WindTurbine(**self.test_turbine_data) |
| 13 | + 'rotor_diameter': 80, |
| 14 | + 'turbine_type': 'turbine_not_in_file', |
| 15 | + 'path': source} |
| 16 | + # Raise system exit due to turbine type not in file |
| 17 | + # with pytest.raises(SystemExit): |
| 18 | + assert(WindTurbine(**self.test_turbine_data).power_curve is None) |
159 | 19 |
|
160 | 20 | def test_get_turbine_data_from_file(self): |
161 | 21 | # Raise FileNotFoundError due to missing |
162 | 22 | with pytest.raises(FileNotFoundError): |
163 | 23 | get_turbine_data_from_file(turbine_type='...', |
164 | | - file_='not_existent') |
| 24 | + path='not_existent') |
165 | 25 |
|
166 | 26 | def test_get_turbine_types(self): |
167 | | - # local with and without filter |
168 | | - get_turbine_types(turbine_library='local', print_out=True, |
169 | | - filter_=True) |
170 | | - get_turbine_types(turbine_library='local', print_out=False, |
171 | | - filter_=False) |
172 | | - # oedb with and without filter |
173 | | - get_turbine_types(turbine_library='oedb', print_out=False, |
174 | | - filter_=True) |
175 | | - get_turbine_types(turbine_library='oedb', print_out=False, |
176 | | - filter_=False) |
| 27 | + get_turbine_types(print_out=True, filter_=True) |
| 28 | + get_turbine_types(print_out=False, filter_=False) |
0 commit comments