Skip to content

Commit 5471557

Browse files
committed
Fix tests and add notebook test
commit b1e64add7f6f6db13d16819aa45970afa1303cff Author: Birgit Schachler <birgit.schachler@rl-institut.de> Date: Tue Mar 13 15:36:47 2018 +0100 Set author to be just oemof developing group commit 2182137 Author: Birgit Schachler <birgit.schachler@rl-institut.de> Date: Tue Mar 13 15:07:59 2018 +0100 Rename file to test examples commit 0d8d0a0 Author: Birgit Schachler <birgit.schachler@rl-institut.de> Date: Tue Mar 13 15:07:12 2018 +0100 Fix doctests commit 80c9ad2 Author: Birgit Schachler <birgit.schachler@rl-institut.de> Date: Tue Mar 13 15:06:58 2018 +0100 Add test for jupyter notebook
1 parent 820b46f commit 5471557

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
# General information about the project.
6262
project = u'windpowerlib'
6363
copyright = u'2016, oemof developer group'
64-
author = u'Uwe Krien, oemof developing group'
64+
author = u'oemof developing group'
6565

6666
import windpowerlib
6767

@@ -285,7 +285,7 @@
285285

286286
# Bibliographic Dublin Core info.
287287
epub_title = u'windpowerlib'
288-
epub_author = u'Uwe Krien, oemof developing group'
288+
epub_author = u'oemof developing group'
289289
epub_publisher = u'oemof developing group'
290290
epub_copyright = u'2016, oemof developing group'
291291

example/test_basic_example.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

example/test_examples.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import subprocess
3+
import tempfile
4+
import nbformat
5+
6+
from example import basic_example as be
7+
from numpy.testing import assert_allclose
8+
9+
10+
class TestExamples:
11+
12+
def test_basic_example_flh(self):
13+
# tests full load hours
14+
weather = be.get_weather_data('weather.csv')
15+
my_turbine, e126 = be.initialise_wind_turbines()
16+
be.calculate_power_output(weather, my_turbine, e126)
17+
18+
assert_allclose(1766.6870, (e126.power_output.sum() /
19+
e126.nominal_power), 0.01)
20+
assert_allclose(1882.7567, (my_turbine.power_output.sum() /
21+
my_turbine.nominal_power), 0.01)
22+
23+
def _notebook_run(self, path):
24+
"""
25+
Execute a notebook via nbconvert and collect output.
26+
Returns (parsed nb object, execution errors)
27+
"""
28+
dirname, __ = os.path.split(path)
29+
os.chdir(dirname)
30+
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
31+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
32+
"--ExecutePreprocessor.timeout=60",
33+
"--output", fout.name, path]
34+
subprocess.check_call(args)
35+
36+
fout.seek(0)
37+
nb = nbformat.read(fout, nbformat.current_nbformat)
38+
39+
errors = [output for cell in nb.cells if "outputs" in cell
40+
for output in cell["outputs"]
41+
if output.output_type == "error"]
42+
43+
return nb, errors
44+
45+
def test_basic_example_ipynb(self):
46+
dir_path = os.path.dirname(os.path.realpath(__file__))
47+
nb, errors = self._notebook_run(os.path.join(dir_path,
48+
'basic_example.ipynb'))
49+
assert errors == []

windpowerlib/modelchain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class ModelChain(object):
8888
>>> enerconE126 = {
8989
... 'hub_height': 135,
9090
... 'rotor_diameter': 127,
91-
... 'turbine_name': 'ENERCON E 126 7500'}
91+
... 'turbine_name': 'ENERCON E 126 7500',
92+
... 'fetch_curve': 'power_coefficient_curve'}
9293
>>> e126 = wind_turbine.WindTurbine(**enerconE126)
9394
>>> modelchain_data = {'density_model': 'ideal_gas'}
9495
>>> e126_mc = modelchain.ModelChain(e126, **modelchain_data)

windpowerlib/tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def linear_interpolation_extrapolation(df, target_height):
5757
... columns=[np.array(['wind_speed',
5858
... 'wind_speed']),
5959
... np.array([10, 80])])
60-
>>> linear_interpolation_extrapolation(
61-
... weather_df['wind_speed'], 100)[0]
62-
6.8571428571428577
60+
>>> round(linear_interpolation_extrapolation(
61+
... weather_df['wind_speed'], 100)[0], 2)
62+
6.86
6363
6464
"""
6565
# find closest heights

0 commit comments

Comments
 (0)