Skip to content

Commit

Permalink
Merge pull request #136 from wind-python/features/fix_and_add_automat…
Browse files Browse the repository at this point in the history
…ic_tests

Update windpowerlib to work for newer python versions and add automatic testing
  • Loading branch information
birgits committed Feb 9, 2024
2 parents b493bd6 + b4db824 commit 5af422d
Show file tree
Hide file tree
Showing 28 changed files with 485 additions and 153 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/tests-coverage.yml
@@ -0,0 +1,68 @@
# Tests with pytest the package and monitors the coverage and sends it to coveralls.io
# Coverage is only send to coveralls.io when no pytest tests fail
name: "Tests & Coverage"

on: [push]

# Cancel jobs on new push
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
name: "${{ matrix.name-suffix }} at py${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include:
- name-suffix: "coverage"
os: ubuntu-latest
python-version: "3.11"
- name-suffix: "basic"
os: ubuntu-latest
python-version: "3.10"
- name-suffix: "basic"
os: ubuntu-latest
python-version: "3.12"
- name-suffix: "basic"
os: windows-latest
python-version: "3.11"

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Set up Conda
if: runner.os == 'Windows'
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
activate-environment: testenv

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install .[dev]
- name: Run tests
if: ${{ !(runner.os == 'Linux' && matrix.python-version == 3.9 && matrix.name-suffix == 'coverage') }}
run: |
python -m pytest --disable-warnings --color=yes -v
- name: Run tests, coverage and send to coveralls
if: runner.os == 'Linux' && matrix.python-version == 3.9 && matrix.name-suffix == 'coverage'
run: |
coverage run --source=windpowerlib -m pytest --disable-warnings --color=yes -v
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
28 changes: 28 additions & 0 deletions .readthedocs.yml
@@ -0,0 +1,28 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/conf.py

# Build documentation with MkDocs
#mkdocs:
# configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF and ePub
formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
install:
- requirements: doc/requirements.txt

# Set the version of Python
build:
os: ubuntu-22.04
tools:
python: "3.11"
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -2,9 +2,9 @@ language: python

matrix:
include:
- python: 3.6
- python: 3.7
- python: 3.8
- python: 3.10
- python: 3.11
- python: 3.12

# command to install dependencies
#before_install:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -33,13 +33,13 @@ Go to the `download page <http://readthedocs.org/projects/windpowerlib/downloads
Installation
============

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

::

pip install windpowerlib

The windpowerlib is designed for Python 3 and tested on Python >= 3.5. We highly recommend to use virtual environments.
The windpowerlib is designed for Python 3 and tested on Python >= 3.10. We highly recommend to use virtual environments.
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.

Optional Packages
Expand Down
2 changes: 1 addition & 1 deletion doc/getting_started.rst
Expand Up @@ -43,7 +43,7 @@ If you have a working Python 3 environment, use pypi to install the latest windp

pip install windpowerlib

The windpowerlib is designed for Python 3 and tested on Python >= 3.5. We highly recommend to use virtual environments.
The windpowerlib is designed for Python 3 and tested on Python >= 3.10. We highly recommend to use virtual environments.
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.

Optional Packages
Expand Down
1 change: 1 addition & 0 deletions doc/requirements.txt
@@ -1,4 +1,5 @@
sphinx>=1.4
sphinx_rtd_theme
ipykernel
nbsphinx
pandas
Expand Down
7 changes: 6 additions & 1 deletion doc/whatsnew/v0-2-2.rst
@@ -1,6 +1,11 @@
v0.2.2 ()
++++++++++++++++++++++++++++++

* Updated the code basis to work for newer versions of python (support for python 3.6 to
python 3.9 is discontinued, supported python versions are now >= python 3.9) and added
github actions to run tests automatically when changes are pushed to github
(`PR 136 <https://github.com/wind-python/windpowerlib/pull/136>`_).

Contributors
############
* Author
* Birgit Schachler
3 changes: 2 additions & 1 deletion example/modelchain_example.ipynb
Expand Up @@ -144,7 +144,8 @@
" file,\n",
" index_col=0,\n",
" header=[0, 1],\n",
" date_parser=lambda idx: pd.to_datetime(idx, utc=True))\n",
" )\n",
" weather_df.index = pd.to_datetime(weather_df.index, utc=True)\n",
" \n",
" # change time zone\n",
" weather_df.index = weather_df.index.tz_convert(\n",
Expand Down
2 changes: 1 addition & 1 deletion example/modelchain_example.py
Expand Up @@ -85,8 +85,8 @@ def get_weather_data(filename="weather.csv", **kwargs):
file,
index_col=0,
header=[0, 1],
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
)
weather_df.index = pd.to_datetime(weather_df.index, utc=True)

# change time zone
weather_df.index = weather_df.index.tz_convert("Europe/Berlin")
Expand Down
2 changes: 1 addition & 1 deletion example/simple_example.py
Expand Up @@ -79,8 +79,8 @@ def get_weather_data(filename="weather.csv", **kwargs):
file,
index_col=0,
header=[0, 1],
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
)
weather_df.index = pd.to_datetime(weather_df.index, utc=True)

# change time zone
weather_df.index = weather_df.index.tz_convert("Europe/Berlin")
Expand Down
57 changes: 15 additions & 42 deletions example/test_examples.py
Expand Up @@ -4,14 +4,10 @@
"""

import os
import subprocess
import tempfile
import nbformat
import sys
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
import pytest_notebook


class TestExamples:
Expand Down Expand Up @@ -42,7 +38,7 @@ def test_turbine_cluster_modelchain_example_flh(self):
)
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
assert_allclose(
1956.164053,
2004.84125,
(example_farm.power_output.sum() / example_farm.nominal_power),
0.01,
)
Expand All @@ -57,50 +53,27 @@ def test_turbine_cluster_modelchain_example_flh(self):

def _notebook_run(self, path):
"""
Execute a notebook via nbconvert and collect output.
Returns (parsed nb object, execution errors)
Execute a notebook and collect output.
Returns execution errors.
"""
dirname, __ = os.path.split(path)
os.chdir(dirname)
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
args = [
"jupyter",
"nbconvert",
"--to",
"notebook",
"--execute",
"--ExecutePreprocessor.timeout=60",
"--output",
fout.name,
path,
]
subprocess.check_call(args)

fout.seek(0)
nb = nbformat.read(fout, nbformat.current_nbformat)

errors = [
output
for cell in nb.cells
if "outputs" in cell
for output in cell["outputs"]
if output.output_type == "error"
]

return nb, errors
notebook = pytest_notebook.notebook.load_notebook(path=path)
result = pytest_notebook.execution.execute_notebook(
notebook,
with_coverage=False,
timeout=600,
)
return result.exec_error

@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
def test_modelchain_example_ipynb(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
nb, errors = self._notebook_run(
errors = self._notebook_run(
os.path.join(dir_path, "modelchain_example.ipynb")
)
assert errors == []
assert errors is None

@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
def test_turbine_cluster_modelchain_example_ipynb(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
nb, errors = self._notebook_run(
errors = self._notebook_run(
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
)
assert errors == []
assert errors is None

0 comments on commit 5af422d

Please sign in to comment.