Skip to content

Commit

Permalink
first jupyter notebook tutorial with attempt at smooth unittest integ…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
dataspider committed Jul 14, 2024
1 parent f5a52fa commit 8587bc0
Show file tree
Hide file tree
Showing 5 changed files with 1,406 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: python -m pip install -U pip

- name: Install the package
run: python -m pip install .[test]
run: python -m pip install .[test,tutorial]

- name: Run tests
run: coverage run -m pymnet.tests
Expand Down
2 changes: 2 additions & 0 deletions pymnet/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .sampling_test import test_sampling
from .transforms_test import test_transforms
from .visuals_test import test_visuals
from .tutorial_test import test_tutorials

try:
import networkx
Expand All @@ -29,6 +30,7 @@ def test_all():
codes.append(test_visuals())
codes.append(test_isomorphisms())
codes.append(test_sampling())
codes.append(test_tutorials())
if nximported:
codes.append(test_nxwrap())
return all(codes)
31 changes: 31 additions & 0 deletions pymnet/tests/tutorial_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import nbformat
import unittest
import subprocess


class TestTutorials(unittest.TestCase):
def setUp(self):
self.networktypes = "../tutorials/01_networktypes"

def test_networktypes(self):
res = subprocess.call(
f"jupyter nbconvert --to notebook --execute {self.networktypes}.ipynb",
shell=True,
)
nb = nbformat.read(f"{self.networktypes}.nbconvert.ipynb", as_version=4)
nb_original = nbformat.read(f"{self.networktypes}.ipynb", as_version=4)
out = [c["outputs"] for c in nb.cells if c["cell_type"] == "code"]
out_original = [
c["outputs"] for c in nb_original.cells if c["cell_type"] == "code"
]
self.assertListEqual(out, out_original)

def tearDown(self):
subprocess.call(
f"rm ../tutorials/{self.networktypes}.nbconvert.ipynb", shell=True
)


def test_tutorials():
suite = unittest.TestSuite()
suite.addTest(TestTutorials("test_networktypes"))
Loading

0 comments on commit 8587bc0

Please sign in to comment.