Skip to content

Commit

Permalink
Merge pull request #277 from openego/features/adapt_plotting_example
Browse files Browse the repository at this point in the history
Features/adapt plotting example
  • Loading branch information
birgits committed Jul 26, 2022
2 parents 28cde5a + aad0449 commit e76e220
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 21,722 deletions.
2 changes: 1 addition & 1 deletion edisgo/edisgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ def import_electromobility(
So far, this function requires electromobility data from
`SimBEV <https://github.com/rl-institut/simbev>`_ (required version:
`<3083c5a https://github.com/rl-institut/simbev/commit/
`3083c5a <https://github.com/rl-institut/simbev/commit/
86076c936940365587c9fba98a5b774e13083c5a>`_) and
`TracBEV <https://github.com/rl-institut/tracbev>`_ (required version:
`14d864c <https://github.com/rl-institut/tracbev/commit/
Expand Down
2 changes: 1 addition & 1 deletion examples/edisgo_simple_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"source": [
"## Installation <a class=\"anchor\" id=\"installation\"></a>\n",
"\n",
"This notebook requires a working installation of eDisGo as well as `jupyter notebook` to run the example and `contextily` and `geopandas` to view the grid topology on a map. You can install all of these as follows:\n",
"This notebook requires a working installation of eDisGo as well as `jupyter notebook` to run the example and `contextily` to view the grid topology on a map. You can install all of these as follows:\n",
"\n",
"```python\n",
"pip install eDisGo[examples,geoplot]\n",
Expand Down
21,794 changes: 74 additions & 21,720 deletions examples/plot_example.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def read(fname):
]
dev_requirements = [
"pytest",
"jupyter_contrib_nbextensions",
"sphinx_rtd_theme",
"sphinx-autodoc-typehints",
"pre-commit",
Expand Down
58 changes: 58 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import nbformat
import os
import shutil
import subprocess
import tempfile

import pytest

Expand All @@ -17,3 +20,58 @@ def test_grid_reinforcement_example(self):
# Delete saved grid and results data
edisgo_path = os.path.join(os.path.expanduser("~"), ".edisgo")
shutil.rmtree(os.path.join(edisgo_path, "ding0_example_grid"))

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

@pytest.mark.slow
def test_plot_example_ipynb(self):
examples_dir_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"examples")
nb, errors = self._notebook_run(
os.path.join(examples_dir_path, "plot_example.ipynb")
)
assert errors == []

# ToDo Uncomment once a smaller grid is used and execution does not take as long
# @pytest.mark.slow
# def test_edisgo_simple_example_ipynb(self):
# examples_dir_path = os.path.join(
# os.path.dirname(os.path.dirname(__file__)),
# "examples")
# nb, errors = self._notebook_run(
# os.path.join(examples_dir_path, "edisgo_simple_example.ipynb")
# )
# assert errors == []

0 comments on commit e76e220

Please sign in to comment.