Skip to content

Commit adcb014

Browse files
committed
Move test parameters to functions and rename to "parameters"
1 parent e8bcfbe commit adcb014

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

tests/test_wind_speed.py

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,63 @@
88

99
class TestWindSpeed:
1010

11-
@classmethod
12-
def setup_class(self):
13-
self.logarithmic = {'v_wind': pd.Series(data=[5.0, 6.5]),
14-
'z_0': pd.Series(data=[0.15, 0.15]),
15-
'hub_height': 100,
16-
'v_wind_height': 10,
17-
'obstacle_height': 0}
18-
19-
self.hellman = {'v_wind': pd.Series(data=[5.0, 6.5]),
20-
'hub_height': 100,
21-
'v_wind_height': 10,
22-
'z_0': None,
23-
'hellman_exp': None}
24-
2511
def test_logarithmic_wind_profile(self):
12+
parameters = {'v_wind': pd.Series(data=[5.0, 6.5]),
13+
'z_0': pd.Series(data=[0.15, 0.15]),
14+
'hub_height': 100,
15+
'v_wind_height': 10,
16+
'obstacle_height': 0}
2617
# Test pandas.Series
2718
v_wind_hub_exp = pd.Series(data=[7.74136523, 10.0637748])
28-
assert_series_equal(logarithmic_wind_profile(**self.logarithmic),
19+
assert_series_equal(logarithmic_wind_profile(**parameters),
2920
v_wind_hub_exp)
3021
# Test numpy array
31-
self.logarithmic['z_0'] = np.array(self.logarithmic['z_0'])
32-
self.logarithmic['v_wind'] = np.array(self.logarithmic['v_wind'])
33-
assert_allclose(logarithmic_wind_profile(**self.logarithmic),
34-
v_wind_hub_exp)
22+
parameters['z_0'] = np.array(parameters['z_0'])
23+
parameters['v_wind'] = np.array(parameters['v_wind'])
24+
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
3525
# Test z_0 is float and obstacle height
3626
v_wind_hub_exp = np.array([13.54925281, 17.61402865])
37-
self.logarithmic['z_0'] = self.logarithmic['z_0'][0]
38-
self.logarithmic['obstacle_height'] = 12
39-
assert_allclose(logarithmic_wind_profile(**self.logarithmic),
40-
v_wind_hub_exp)
27+
parameters['z_0'] = parameters['z_0'][0]
28+
parameters['obstacle_height'] = 12
29+
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
4130
# Raise ValueError due to 0.7 * `obstacle_height` > `v_wind_height`
4231
with pytest.raises(ValueError):
43-
logarithmic_wind_profile(v_wind=5.5, v_wind_height=10,
44-
hub_height=100, z_0=0.15,
45-
obstacle_height=20)
32+
parameters['obstacle_height'] = 20
33+
logarithmic_wind_profile(**parameters)
4634

4735
def test_v_wind_hellman(self):
36+
parameters = {'v_wind': pd.Series(data=[5.0, 6.5]),
37+
'hub_height': 100,
38+
'v_wind_height': 10,
39+
'z_0': None,
40+
'hellman_exp': None}
4841
# Test pandas.Series and z_0 is None
4942
v_wind_hub_exp = pd.Series(data=[6.9474774, 9.03172])
50-
assert_series_equal(v_wind_hellman(**self.hellman), v_wind_hub_exp)
43+
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
5144

5245
# Test z_0 is float
5346
v_wind_hub_exp = pd.Series(data=[7.12462437, 9.26201168])
54-
self.hellman['z_0'] = 0.15
55-
assert_series_equal(v_wind_hellman(**self.hellman), v_wind_hub_exp)
47+
parameters['z_0'] = 0.15
48+
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
5649

5750
# Test array and z_0 is pandas.Series
58-
self.hellman['v_wind'] = np.array(self.hellman['v_wind'])
59-
self.hellman['z_0'] = pd.Series(data=[0.15, 0.15])
60-
assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp)
51+
parameters['v_wind'] = np.array(parameters['v_wind'])
52+
parameters['z_0'] = pd.Series(data=[0.15, 0.15])
53+
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
6154

6255
# Test z_0 is array
63-
self.hellman['z_0'] = np.array(self.hellman['z_0'])
64-
assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp)
56+
parameters['z_0'] = np.array(parameters['z_0'])
57+
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
6558

6659
# Test hellman_exp is not None
6760
v_wind_hub_exp = np.array([7.92446596, 10.30180575])
68-
self.hellman['hellman_exp'] = 0.2
69-
assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp)
61+
parameters['hellman_exp'] = 0.2
62+
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
7063

7164
# Raise TypeErrors due to wrong types of `hellman_exp`.
65+
parameters['hellman_exp'] = 8
7266
with pytest.raises(TypeError):
73-
v_wind_hellman(v_wind=5.5, v_wind_height=10, hub_height=100,
74-
hellman_exp=8)
67+
v_wind_hellman(**parameters)
7568
with pytest.raises(TypeError):
76-
v_wind_hellman(v_wind=5.5, v_wind_height=10, hub_height=100,
77-
hellman_exp=False)
69+
parameters['hellman_exp'] = False
70+
v_wind_hellman(**parameters)

0 commit comments

Comments
 (0)