-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from fusion-energy/concise_tests
shorter tests with less repetition
- Loading branch information
Showing
18 changed files
with
157 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=300) #, allow_errors=True | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
import pytest | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
from .utils import _notebook_run | ||
|
||
return nb, errors | ||
|
||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_01_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_1(): | ||
for notebook in Path().rglob("tasks/tasks/task_01_*/*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=300) #, allow_errors=True | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
import pytest | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
from .utils import _notebook_run | ||
|
||
return nb, errors | ||
|
||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_10_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_10(): | ||
for notebook in Path().rglob("tasks/task_10_*/*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=900) #, allow_errors=True | ||
import pytest | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
from .utils import _notebook_run | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
|
||
return nb, errors | ||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_11_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_11(): | ||
for notebook in Path().rglob("tasks/task_11_*/*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=1400) #, allow_errors=True | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
import pytest | ||
|
||
return nb, errors | ||
from .utils import _notebook_run | ||
|
||
|
||
def test_task_12(): | ||
for notebook in Path().rglob("tasks/task_12_*/1*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_12_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
for notebook in Path().rglob("tasks/task_12_*/2_.ipynb"): | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
|
||
# task 3 is skipped as it causes errors, issue raised | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
import pytest | ||
|
||
from .utils import _notebook_run | ||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=300) #, allow_errors=True | ||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
return nb, errors | ||
|
||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_13_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_13(): | ||
for notebook in Path().rglob("tasks/task_13_*/*.ipynb"): | ||
print(f'tests {notebook}') | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=4000) #, allow_errors=True | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
import pytest | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
from .utils import _notebook_run | ||
|
||
return nb, errors | ||
|
||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_14_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_14(): | ||
for notebook in Path().rglob("tasks/task_14_*/*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,13 @@ | ||
|
||
""" | ||
tests the create_isotope_plot from plotting_utils in the same way the examples | ||
use the function. | ||
""" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert.preprocessors.execute import CellExecutionError | ||
|
||
|
||
def _notebook_run(path): | ||
""" | ||
Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
kernel_name = 'python%d' % sys.version_info[0] | ||
this_file_directory = os.path.dirname(__file__) | ||
errors = [] | ||
|
||
with open(path) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
nb.metadata.get('kernelspec', {})['name'] = kernel_name | ||
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=1900) #, allow_errors=True | ||
|
||
try: | ||
ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) | ||
import pytest | ||
|
||
except CellExecutionError as e: | ||
if "SKIP" in e.traceback: | ||
print(str(e.traceback).split("\n")[-2]) | ||
else: | ||
raise e | ||
from .utils import _notebook_run | ||
|
||
return nb, errors | ||
|
||
@pytest.mark.parametrize("filename", Path().rglob("tasks/task_15_*/*.ipynb")) | ||
def test_task(filename): | ||
|
||
def test_task_14(): | ||
for notebook in Path().rglob("tasks/task_15_*/*.ipynb"): | ||
print(notebook) | ||
nb, errors = _notebook_run(notebook) | ||
assert errors == [] | ||
print(f"Attempting to run {filename}") | ||
_, errors = _notebook_run(filename) | ||
assert errors == [] |
Oops, something went wrong.