Skip to content

Commit 5af422d

Browse files
authored
Merge pull request #136 from wind-python/features/fix_and_add_automatic_tests
Update windpowerlib to work for newer python versions and add automatic testing
2 parents b493bd6 + b4db824 commit 5af422d

28 files changed

+485
-153
lines changed

.github/workflows/tests-coverage.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Tests with pytest the package and monitors the coverage and sends it to coveralls.io
2+
# Coverage is only send to coveralls.io when no pytest tests fail
3+
name: "Tests & Coverage"
4+
5+
on: [push]
6+
7+
# Cancel jobs on new push
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
build:
14+
name: "${{ matrix.name-suffix }} at py${{ matrix.python-version }} on ${{ matrix.os }}"
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- name-suffix: "coverage"
22+
os: ubuntu-latest
23+
python-version: "3.11"
24+
- name-suffix: "basic"
25+
os: ubuntu-latest
26+
python-version: "3.10"
27+
- name-suffix: "basic"
28+
os: ubuntu-latest
29+
python-version: "3.12"
30+
- name-suffix: "basic"
31+
os: windows-latest
32+
python-version: "3.11"
33+
34+
steps:
35+
- name: Checkout repo
36+
uses: actions/checkout@v3
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v4
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
43+
- name: Set up Conda
44+
if: runner.os == 'Windows'
45+
uses: conda-incubator/setup-miniconda@v2
46+
with:
47+
miniconda-version: "latest"
48+
python-version: ${{ matrix.python-version }}
49+
activate-environment: testenv
50+
51+
- name: Install dependencies
52+
run: |
53+
python -m pip install --upgrade pip wheel setuptools
54+
python -m pip install .[dev]
55+
56+
- name: Run tests
57+
if: ${{ !(runner.os == 'Linux' && matrix.python-version == 3.9 && matrix.name-suffix == 'coverage') }}
58+
run: |
59+
python -m pytest --disable-warnings --color=yes -v
60+
61+
- name: Run tests, coverage and send to coveralls
62+
if: runner.os == 'Linux' && matrix.python-version == 3.9 && matrix.name-suffix == 'coverage'
63+
run: |
64+
coverage run --source=windpowerlib -m pytest --disable-warnings --color=yes -v
65+
coveralls
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
COVERALLS_SERVICE_NAME: github

.readthedocs.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
configuration: doc/conf.py
11+
12+
# Build documentation with MkDocs
13+
#mkdocs:
14+
# configuration: mkdocs.yml
15+
16+
# Optionally build your docs in additional formats such as PDF and ePub
17+
formats: all
18+
19+
# Optionally set the version of Python and requirements required to build your docs
20+
python:
21+
install:
22+
- requirements: doc/requirements.txt
23+
24+
# Set the version of Python
25+
build:
26+
os: ubuntu-22.04
27+
tools:
28+
python: "3.11"

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: python
22

33
matrix:
44
include:
5-
- python: 3.6
6-
- python: 3.7
7-
- python: 3.8
5+
- python: 3.10
6+
- python: 3.11
7+
- python: 3.12
88

99
# command to install dependencies
1010
#before_install:

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ Go to the `download page <http://readthedocs.org/projects/windpowerlib/downloads
3333
Installation
3434
============
3535

36-
If you have a working Python 3 (>= 3.6) environment, use pypi to install the latest windpowerlib version:
36+
If you have a working Python 3 environment, use pypi to install the latest windpowerlib version:
3737

3838
::
3939

4040
pip install windpowerlib
4141

42-
The windpowerlib is designed for Python 3 and tested on Python >= 3.5. We highly recommend to use virtual environments.
42+
The windpowerlib is designed for Python 3 and tested on Python >= 3.10. We highly recommend to use virtual environments.
4343
Please see the `installation page <http://oemof.readthedocs.io/en/stable/installation_and_setup.html>`_ of the oemof documentation for complete instructions on how to install python and a virtual environment on your operating system.
4444

4545
Optional Packages

doc/getting_started.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If you have a working Python 3 environment, use pypi to install the latest windp
4343

4444
pip install windpowerlib
4545

46-
The windpowerlib is designed for Python 3 and tested on Python >= 3.5. We highly recommend to use virtual environments.
46+
The windpowerlib is designed for Python 3 and tested on Python >= 3.10. We highly recommend to use virtual environments.
4747
Please see the `installation page <http://oemof.readthedocs.io/en/stable/installation_and_setup.html>`_ of the oemof documentation for complete instructions on how to install python and a virtual environment on your operating system.
4848

4949
Optional Packages

doc/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sphinx>=1.4
2+
sphinx_rtd_theme
23
ipykernel
34
nbsphinx
45
pandas

doc/whatsnew/v0-2-2.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
v0.2.2 ()
22
++++++++++++++++++++++++++++++
33

4+
* Updated the code basis to work for newer versions of python (support for python 3.6 to
5+
python 3.9 is discontinued, supported python versions are now >= python 3.9) and added
6+
github actions to run tests automatically when changes are pushed to github
7+
(`PR 136 <https://github.com/wind-python/windpowerlib/pull/136>`_).
8+
49
Contributors
510
############
6-
* Author
11+
* Birgit Schachler

example/modelchain_example.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
" file,\n",
145145
" index_col=0,\n",
146146
" header=[0, 1],\n",
147-
" date_parser=lambda idx: pd.to_datetime(idx, utc=True))\n",
147+
" )\n",
148+
" weather_df.index = pd.to_datetime(weather_df.index, utc=True)\n",
148149
" \n",
149150
" # change time zone\n",
150151
" weather_df.index = weather_df.index.tz_convert(\n",

example/modelchain_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def get_weather_data(filename="weather.csv", **kwargs):
8585
file,
8686
index_col=0,
8787
header=[0, 1],
88-
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
8988
)
89+
weather_df.index = pd.to_datetime(weather_df.index, utc=True)
9090

9191
# change time zone
9292
weather_df.index = weather_df.index.tz_convert("Europe/Berlin")

example/simple_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def get_weather_data(filename="weather.csv", **kwargs):
7979
file,
8080
index_col=0,
8181
header=[0, 1],
82-
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
8382
)
83+
weather_df.index = pd.to_datetime(weather_df.index, utc=True)
8484

8585
# change time zone
8686
weather_df.index = weather_df.index.tz_convert("Europe/Berlin")

example/test_examples.py

+15-42
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
"""
55

66
import os
7-
import subprocess
8-
import tempfile
9-
import nbformat
10-
import sys
117
from example import modelchain_example as mc_e
128
from example import turbine_cluster_modelchain_example as tc_mc_e
139
from numpy.testing import assert_allclose
14-
import pytest
10+
import pytest_notebook
1511

1612

1713
class TestExamples:
@@ -42,7 +38,7 @@ def test_turbine_cluster_modelchain_example_flh(self):
4238
)
4339
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
4440
assert_allclose(
45-
1956.164053,
41+
2004.84125,
4642
(example_farm.power_output.sum() / example_farm.nominal_power),
4743
0.01,
4844
)
@@ -57,50 +53,27 @@ def test_turbine_cluster_modelchain_example_flh(self):
5753

5854
def _notebook_run(self, path):
5955
"""
60-
Execute a notebook via nbconvert and collect output.
61-
Returns (parsed nb object, execution errors)
56+
Execute a notebook and collect output.
57+
Returns execution errors.
6258
"""
63-
dirname, __ = os.path.split(path)
64-
os.chdir(dirname)
65-
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
66-
args = [
67-
"jupyter",
68-
"nbconvert",
69-
"--to",
70-
"notebook",
71-
"--execute",
72-
"--ExecutePreprocessor.timeout=60",
73-
"--output",
74-
fout.name,
75-
path,
76-
]
77-
subprocess.check_call(args)
78-
79-
fout.seek(0)
80-
nb = nbformat.read(fout, nbformat.current_nbformat)
81-
82-
errors = [
83-
output
84-
for cell in nb.cells
85-
if "outputs" in cell
86-
for output in cell["outputs"]
87-
if output.output_type == "error"
88-
]
89-
90-
return nb, errors
59+
notebook = pytest_notebook.notebook.load_notebook(path=path)
60+
result = pytest_notebook.execution.execute_notebook(
61+
notebook,
62+
with_coverage=False,
63+
timeout=600,
64+
)
65+
return result.exec_error
9166

92-
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
9367
def test_modelchain_example_ipynb(self):
9468
dir_path = os.path.dirname(os.path.realpath(__file__))
95-
nb, errors = self._notebook_run(
69+
errors = self._notebook_run(
9670
os.path.join(dir_path, "modelchain_example.ipynb")
9771
)
98-
assert errors == []
72+
assert errors is None
9973

100-
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
10174
def test_turbine_cluster_modelchain_example_ipynb(self):
10275
dir_path = os.path.dirname(os.path.realpath(__file__))
103-
nb, errors = self._notebook_run(
76+
errors = self._notebook_run(
10477
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
10578
)
106-
assert errors == []
79+
assert errors is None

0 commit comments

Comments
 (0)