Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test jupyter #59

Open
wants to merge 9 commits into
base: shuklak13-patch-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jupyter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
jupyter nbextension enable --py tensorflow_model_analysis --sys-prefix

- name: Test Jupyter Notebooks
run: python test_runner.py
run: python jupyter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"source": [
"import os\n",
"import tempfile\n",
"import errormoduledoesnotexist\n",
"import apache_beam as beam\n",
"import numpy as np\n",
"import pandas as pd\n",
Expand Down
78 changes: 78 additions & 0 deletions jupyter_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os
import unittest
from nbconvert.preprocessors import ExecutePreprocessor
import nbformat


# TODO(karanshukla): names: _run_notebook and _write_notebook?
def _run_notebook(path):

# TODO(karanshukla): can I comment this out?
# def _write_notebook(notebook):
# dirname = os.path.dirname(path)
# notebookname, _ = os.path.splitext(os.path.basename(path))
# output_path = os.path.join(dirname,
# '{}_all_output.ipynb'.format(notebookname))
# with open(output_path, mode='wt') as f:
# nbformat.write(notebook, f)

with open(path) as f:
notebook = nbformat.read(f, as_version=4)

proc = ExecutePreprocessor(timeout=None, kernel_name='python3')
proc.allow_errors = True
proc.preprocess(notebook, {'metadata': {'path': '/'}})

# _write_notebook(notebook)

errors = []
for cell in notebook.cells:
if 'outputs' in cell:
for output in cell['outputs']:
if output.output_type == 'error':
errors.append(output)

return errors


class TestNotebook(unittest.TestCase):

def test_example(self):
errors = _run_notebook(
'fairness_indicators/examples/Fairness_Indicators_Example_Colab.ipynb')
self.assertEqual(errors, [])


# def test_facessd(self):
# errors = _run_notebook(
# 'fairness_indicators/examples/Facessd_Fairness_Indicators_Example_Colab.ipynb')
# self.assertEqual(errors, [])

# def test_lineage(self):
# errors = _run_notebook(
# 'fairness_indicators/examples/Fairness_Indicators_Lineage_Case_Study.ipynb')
# self.assertEqual(errors, [])

def test_tb(self):
errors = _run_notebook(
'fairness_indicators/examples/Fairness_Indicators_TensorBoard_Plugin_Example_Colab.ipynb')
self.assertEqual(errors, [])

# def test_tfco_celeba(self):
# errors = _run_notebook(
# 'fairness_indicators/examples/Fairness_Indicators_TFCO_CelebA_Case_Study.ipynb')
# self.assertEqual(errors, [])

# def test_tfco_wiki(self):
# errors = _run_notebook(
# 'fairness_indicators/examples/Fairness_Indicators_TFCO_Wiki_Case_Study.ipynb')
# self.assertEqual(errors, [])

# def test_tfhub(self):
# errors = _run_notebook(
# 'fairness_indicators/examples/Fairness_Indicators_on_TF_Hub_Text_Embeddings.ipynb')
# self.assertEqual(errors, [])


if __name__ == '__main__':
unittest.main()
45 changes: 0 additions & 45 deletions test_runner.py

This file was deleted.