-
Notifications
You must be signed in to change notification settings - Fork 100
/
test_examples.py
81 lines (73 loc) · 2.7 KB
/
test_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""
import os
from example import modelchain_example as mc_e
from example import turbine_cluster_modelchain_example as tc_mc_e
from numpy.testing import assert_allclose
import pytest_notebook
class TestExamples:
def test_modelchain_example_flh(self):
# tests full load hours
weather = mc_e.get_weather_data("weather.csv")
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)
assert_allclose(
2730.142, (e126.power_output.sum() / e126.nominal_power), 0.01
)
assert_allclose(
1882.7567,
(my_turbine.power_output.sum() / my_turbine.nominal_power),
0.01,
)
def test_turbine_cluster_modelchain_example_flh(self):
# tests full load hours
weather = mc_e.get_weather_data("weather.csv")
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
example_farm, example_farm_2 = tc_mc_e.initialize_wind_farms(
my_turbine, e126
)
example_cluster = tc_mc_e.initialize_wind_turbine_cluster(
example_farm, example_farm_2
)
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
assert_allclose(
2004.84125,
(example_farm.power_output.sum() / example_farm.nominal_power),
0.01,
)
assert_allclose(
2156.794154,
(
example_cluster.power_output.sum()
/ example_cluster.nominal_power
),
0.01,
)
def _notebook_run(self, path):
"""
Execute a notebook and collect output.
Returns (parsed nb object, execution errors)
"""
dirname, nb_name = os.path.split(path)
os.chdir(dirname)
notebook = pytest_notebook.notebook.load_notebook(path=nb_name)
result = pytest_notebook.execution.execute_notebook(
notebook,
with_coverage=False,
timeout=600,
)
return result.exec_error
def test_modelchain_example_ipynb(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
errors = self._notebook_run(
os.path.join(dir_path, "modelchain_example.ipynb")
)
assert errors is None
def test_turbine_cluster_modelchain_example_ipynb(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
errors = self._notebook_run(
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
)
assert errors is None