diff --git a/tests/test_task_1.py b/tests/test_task_1.py index f2991f18..9eb3490e 100644 --- a/tests/test_task_1.py +++ b/tests/test_task_1.py @@ -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 == [] diff --git a/tests/test_task_10.py b/tests/test_task_10.py index 1e2713e4..df8f32f7 100644 --- a/tests/test_task_10.py +++ b/tests/test_task_10.py @@ -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 == [] diff --git a/tests/test_task_11.py b/tests/test_task_11.py index bc252879..fe918852 100644 --- a/tests/test_task_11.py +++ b/tests/test_task_11.py @@ -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 == [] diff --git a/tests/test_task_12.py b/tests/test_task_12.py index b0638d1b..4d8d6863 100644 --- a/tests/test_task_12.py +++ b/tests/test_task_12.py @@ -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 \ No newline at end of file + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_13.py b/tests/test_task_13.py index 23549f8b..30b22020 100644 --- a/tests/test_task_13.py +++ b/tests/test_task_13.py @@ -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 == [] diff --git a/tests/test_task_14.py b/tests/test_task_14.py index 039c5b68..4f6e2f3a 100644 --- a/tests/test_task_14.py +++ b/tests/test_task_14.py @@ -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 == [] diff --git a/tests/test_task_15.py b/tests/test_task_15.py index ef284f1e..d0d75a0c 100644 --- a/tests/test_task_15.py +++ b/tests/test_task_15.py @@ -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 == [] diff --git a/tests/test_task_16.py b/tests/test_task_16.py index 28143141..d337137b 100644 --- a/tests/test_task_16.py +++ b/tests/test_task_16.py @@ -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_16_*/*.ipynb")) +def test_task(filename): -def test_task_14(): - for notebook in Path().rglob("tasks/task_16_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_17.py b/tests/test_task_17.py new file mode 100644 index 00000000..5fd2800e --- /dev/null +++ b/tests/test_task_17.py @@ -0,0 +1,13 @@ +from pathlib import Path + +import pytest + +from .utils import _notebook_run + + +@pytest.mark.parametrize("filename", Path().rglob("tasks/task_17_*/*.ipynb")) +def test_task(filename): + + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_2.py b/tests/test_task_2.py index 46ddf45d..c1ec4e51 100644 --- a/tests/test_task_2.py +++ b/tests/test_task_2.py @@ -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_02_*/*.ipynb")) +def test_task(filename): -def test_task_2(): - for notebook in Path().rglob("tasks/task_02_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_3.py b/tests/test_task_3.py index 32bbf8ad..65da2e67 100644 --- a/tests/test_task_3.py +++ b/tests/test_task_3.py @@ -1,47 +1,13 @@ - -""" -tests the create_isotope_plot from plotting_utils in the same way the examples -use the function. -""" - -import os -import sys -import unittest 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_03_*/*.ipynb")) +def test_task(filename): -def test_task_3(): - for notebook in Path().rglob("tasks/task_03_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_4.py b/tests/test_task_4.py index af2d3e5e..5fdba0d0 100644 --- a/tests/test_task_4.py +++ b/tests/test_task_4.py @@ -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=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_04_*/*.ipynb")) +def test_task(filename): -def test_task_4(): - for notebook in Path().rglob("tasks/task_04_*/*_.ipynb"): - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_5.py b/tests/test_task_5.py index bbb8c974..08ebb834 100644 --- a/tests/test_task_5.py +++ b/tests/test_task_5.py @@ -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_05_*/*.ipynb")) +def test_task(filename): -def test_task_5(): - for notebook in Path().rglob("tasks/task_05_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_6.py b/tests/test_task_6.py index 118961b2..2adebb87 100644 --- a/tests/test_task_6.py +++ b/tests/test_task_6.py @@ -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_06_*/*.ipynb")) +def test_task(filename): -def test_task_6(): - for notebook in Path().rglob("tasks/task_06_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_7.py b/tests/test_task_7.py index 26fbbe38..fe877b35 100644 --- a/tests/test_task_7.py +++ b/tests/test_task_7.py @@ -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_07_*/*.ipynb")) +def test_task(filename): -def test_task_7(): - for notebook in Path().rglob("tasks/task_07_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_8.py b/tests/test_task_8.py index 4866f603..4a81ccde 100644 --- a/tests/test_task_8.py +++ b/tests/test_task_8.py @@ -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_08_*/*.ipynb")) +def test_task(filename): -def test_task_8(): - for notebook in Path().rglob("tasks/task_08_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/test_task_9.py b/tests/test_task_9.py index 78ce0f3f..a8d2627b 100644 --- a/tests/test_task_9.py +++ b/tests/test_task_9.py @@ -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_09_*/*.ipynb")) +def test_task(filename): -def test_task_9(): - for notebook in Path().rglob("tasks/task_09_*/*.ipynb"): - print(notebook) - nb, errors = _notebook_run(notebook) - assert errors == [] + print(f"Attempting to run {filename}") + _, errors = _notebook_run(filename) + assert errors == [] diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 00000000..4220ab23 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,32 @@ + +import sys + +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] + 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': path.parent}}) + print(f'running notebook from this path {path.parent}') + + except CellExecutionError as e: + if "SKIP" in e.traceback: + print(str(e.traceback).split("\n")[-2]) + else: + raise e + + return nb, errors