From f21ad4185ae8a8490e750a1de308d0981c1b8341 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Thu, 4 Feb 2021 19:36:55 -0800 Subject: [PATCH 01/25] add test for notebooks --- test_notebooks/__init__.py | 0 test_notebooks/conftest.py | 13 ++++++++ test_notebooks/notebook_tests.py | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test_notebooks/__init__.py create mode 100644 test_notebooks/conftest.py create mode 100644 test_notebooks/notebook_tests.py diff --git a/test_notebooks/__init__.py b/test_notebooks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test_notebooks/conftest.py b/test_notebooks/conftest.py new file mode 100644 index 0000000000..b3afe61860 --- /dev/null +++ b/test_notebooks/conftest.py @@ -0,0 +1,13 @@ +import os +import sys +import pytest +_MY_DIR = os.path.realpath(os.path.dirname(__file__)) +# Allow import of the test utilities packages + + +@pytest.fixture(scope="session") +def notebooks_path(): + + notebook_path = os.path.join( + _MY_DIR, os.pardir, os.pardir, "notebooks") + return os.path.abs(notebook_path) diff --git a/test_notebooks/notebook_tests.py b/test_notebooks/notebook_tests.py new file mode 100644 index 0000000000..c04db645bb --- /dev/null +++ b/test_notebooks/notebook_tests.py @@ -0,0 +1,57 @@ + + +from nbconvert.preprocessors import CellExecutionError +from nbconvert.preprocessors import ExecutePreprocessor +import nbformat +import subprocess +import os +import pytest +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) + + +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) +PARENT_DIR = os.path.join(TEST_DIR, os.pardir, '..') + + +def process_notebook(notebook_filename, html_directory='notebook-html'): + '''Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs). + ''' + with open(notebook_filename) as f: + nb = nbformat.read(f, as_version=4) + + ep = ExecutePreprocessor( + timeout=600, kernel_name='python3', allow_errors=True) + + try: + # Check that the notebook runs + ep.preprocess(nb, {'metadata': {'path': ''}}) + except CellExecutionError: + raise + + print(f"Successfully executed {notebook_filename}") + return + + +def test_all_notebooks(remove_fail_test=True): + '''Runs `process_notebook` on all notebooks in the git repository. + ''' + # Get all files included in the git repository + git_files = (subprocess + .check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True) + .decode('utf-8') + .splitlines()) + + # Get just the notebooks from the git files + notebooks = [fn for fn in git_files if fn.endswith(".ipynb")] + print(notebooks) + + # Test each notebook + for notebook in notebooks: + print("Testing", notebook) + process_notebook(os.path.join(PARENT_DIR, notebook)) + + return + + +if __name__ == '__main__': + test_all_notebooks() From 393cc99c4d00d7600188da7804dc910153f7c029 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Thu, 4 Feb 2021 19:37:12 -0800 Subject: [PATCH 02/25] removed incorrect badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 92ccf95a85..382da3c5df 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![License](http://img.shields.io/:license-Apache%202-blue.svg)](https://github.com/whylabs/whylogs-python/blob/mainline/LICENSE) [![PyPI version](https://badge.fury.io/py/whylogs.svg)](https://badge.fury.io/py/whylogs) [![Coverage Status](https://coveralls.io/repos/github/whylabs/whylogs-python/badge.svg?branch=mainline&service=github)](https://coveralls.io/github/whylabs/whylogs-python?branch=mainline) -[![Python Version](https://img.shields.io/pypi/pyversions/whylogs)](https://pypi.org/project/whylogs/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4490/badge)](https://bestpractices.coreinfrastructure.org/projects/4490) [![PyPi Downloads](https://pepy.tech/badge/whylogs)](https://pepy.tech/project/whylogs) From 3aa9ce1a432c33b0e009b28c449571847f0fb6c5 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Mon, 8 Feb 2021 08:45:47 -0800 Subject: [PATCH 03/25] =?UTF-8?q?=F0=9F=91=B7=E2=80=8D=E2=99=80=EF=B8=8Fad?= =?UTF-8?q?d=20notetbook=20test=20to=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/continuous-integration.yml | 5 ++++ test_notebooks/notebook_tests.py | 30 ++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 857da2924f..1f445af94f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -55,6 +55,8 @@ jobs: finish: needs: test runs-on: ubuntu-latest + strategy: + max-parallel: 2 steps: - name: Coveralls Finished env: @@ -63,4 +65,7 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} + - name: Check example notebook + run: + pytest test_notebooks/notebook_tests.py diff --git a/test_notebooks/notebook_tests.py b/test_notebooks/notebook_tests.py index c04db645bb..6e9ffd8cf8 100644 --- a/test_notebooks/notebook_tests.py +++ b/test_notebooks/notebook_tests.py @@ -1,30 +1,25 @@ - - from nbconvert.preprocessors import CellExecutionError from nbconvert.preprocessors import ExecutePreprocessor import nbformat import subprocess import os import pytest -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) - TEST_DIR = os.path.dirname(os.path.abspath(__file__)) -PARENT_DIR = os.path.join(TEST_DIR, os.pardir, '..') +PARENT_DIR = os.path.join(TEST_DIR, os.pardir, "..") + +def process_notebook(notebook_filename, html_directory="notebook-html"): + """Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs).""" -def process_notebook(notebook_filename, html_directory='notebook-html'): - '''Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs). - ''' with open(notebook_filename) as f: nb = nbformat.read(f, as_version=4) - ep = ExecutePreprocessor( - timeout=600, kernel_name='python3', allow_errors=True) + ep = ExecutePreprocessor(timeout=600, kernel_name="python3", allow_errors=True) try: # Check that the notebook runs - ep.preprocess(nb, {'metadata': {'path': ''}}) + ep.preprocess(nb, {"metadata": {"path": ""}}) except CellExecutionError: raise @@ -33,13 +28,12 @@ def process_notebook(notebook_filename, html_directory='notebook-html'): def test_all_notebooks(remove_fail_test=True): - '''Runs `process_notebook` on all notebooks in the git repository. - ''' + """ + Runs `process_notebook` on all notebooks in the git repository. + """ + # Get all files included in the git repository - git_files = (subprocess - .check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True) - .decode('utf-8') - .splitlines()) + git_files = subprocess.check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True).decode("utf-8").splitlines() # Get just the notebooks from the git files notebooks = [fn for fn in git_files if fn.endswith(".ipynb")] @@ -53,5 +47,5 @@ def test_all_notebooks(remove_fail_test=True): return -if __name__ == '__main__': +if __name__ == "__main__": test_all_notebooks() From 387586305b2e08f417cacce53902e169400362b2 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Mon, 8 Feb 2021 19:30:59 -0800 Subject: [PATCH 04/25] fix drafter --- .github/workflows/release-drafter.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index d8d6ff0180..5b3f0acc03 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -5,6 +5,7 @@ on: # branches to consider in the event; optional, defaults to all branches: - mainline + - WHY-2304_notebook_tests jobs: update_release_draft: @@ -12,8 +13,8 @@ jobs: steps: # Drafts your next Release notes as Pull Requests are merged into "mainline" - uses: release-drafter/release-drafter@v5 - with: + #with: # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml # config-name: my-config.yml env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From a674ce61ce8032761902e95c0ade436acbc44df5 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 18:48:04 -0800 Subject: [PATCH 05/25] remove space --- .github/workflows/release-drafter.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 5b3f0acc03..918f16e851 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -13,8 +13,5 @@ jobs: steps: # Drafts your next Release notes as Pull Requests are merged into "mainline" - uses: release-drafter/release-drafter@v5 - #with: - # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml - # config-name: my-config.yml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 5406b314255b2d367719cb02acaaafdd448025cc Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:06:23 -0800 Subject: [PATCH 06/25] test notebook after test --- .github/workflows/continuous-integration.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1f445af94f..c9712287ea 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -43,6 +43,10 @@ jobs: - name: Test with tox run: | make test-all + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python >= 3.8}} + run: | + pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel if: ${{matrix.os == 'ubuntu-latest'}} env: @@ -65,7 +69,4 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} - - name: Check example notebook - run: - pytest test_notebooks/notebook_tests.py From ae2297efb11e12c1c2baf7b764891b5df1ff59fb Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:26:57 -0800 Subject: [PATCH 07/25] fix logic in notebook test --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c9712287ea..2d4d50d4bf 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' & matrix.python >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From b5d493ae39358226cfc85086641a01916acf7afc Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:27:36 -0800 Subject: [PATCH 08/25] fix matrix python variable name --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2d4d50d4bf..dc1a0c7d32 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' & matrix.python >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' & matrix.python-version >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From 9fb22110741fdb748d542dfb08b1606e5a692680 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:36:06 -0800 Subject: [PATCH 09/25] fix logical --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index dc1a0c7d32..07c7b17eda 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' & matrix.python-version >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From 71c6fdc45cbfb8d52737fcc83cd19e58e8dd76a4 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:58:02 -0800 Subject: [PATCH 10/25] push notebook test after coverage computation --- .github/workflows/continuous-integration.yml | 8 ++++---- requirements-test.txt | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 07c7b17eda..9bfa9870b7 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -43,10 +43,6 @@ jobs: - name: Test with tox run: | make test-all - - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} - run: | - pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel if: ${{matrix.os == 'ubuntu-latest'}} env: @@ -56,6 +52,10 @@ jobs: flag-name: run-${{ matrix.os }}-${{matrix.python-version}} parallel: true github-token : ${{ secrets.GITHUB_TOKEN}} + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} + run: | + pytest test_notebooks/notebook_tests.py finish: needs: test runs-on: ubuntu-latest diff --git a/requirements-test.txt b/requirements-test.txt index 172bd41ffb..385485e970 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -31,3 +31,4 @@ xlrd==2.0.1 openpyxl==3.0.6 smart-open==4.1.2 tqdm==4.54.0 +nbconvert==6.0.7 \ No newline at end of file From 934e17a9155be3f226846f20f17f0cc95a40422c Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 20:13:09 -0800 Subject: [PATCH 11/25] install pytest and reqs for notebook --- .github/workflows/continuous-integration.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9bfa9870b7..32a97284d6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -52,10 +52,7 @@ jobs: flag-name: run-${{ matrix.os }}-${{matrix.python-version}} parallel: true github-token : ${{ secrets.GITHUB_TOKEN}} - - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} - run: | - pytest test_notebooks/notebook_tests.py + finish: needs: test runs-on: ubuntu-latest @@ -69,4 +66,14 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} + - name: Set up Python 3.8 for notebook + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} + run: | + python -m pip install --upgrade pip + pip install -r requirements-test.txt + pytest test_notebooks/notebook_tests.py From 77ba887fa46cee317eeb8f4f7444f7ba7af37045 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 21:04:42 -0800 Subject: [PATCH 12/25] remove unused matrix --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 32a97284d6..946cd6545e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -71,7 +71,6 @@ jobs: with: python-version: 3.8 - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} run: | python -m pip install --upgrade pip pip install -r requirements-test.txt From be3c4e4b1d8a33d9a6dc8384a45469146a509ca9 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Wed, 10 Feb 2021 10:10:39 -0800 Subject: [PATCH 13/25] remove pip install --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 946cd6545e..4564890ee1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -72,7 +72,6 @@ jobs: python-version: 3.8 - name: Test with notebook run: | - python -m pip install --upgrade pip pip install -r requirements-test.txt pytest test_notebooks/notebook_tests.py From 285d68957d902289adc03fee043538bd7b6cdfa1 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Thu, 4 Feb 2021 19:36:55 -0800 Subject: [PATCH 14/25] add test for notebooks --- test_notebooks/__init__.py | 0 test_notebooks/conftest.py | 13 ++++++++ test_notebooks/notebook_tests.py | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test_notebooks/__init__.py create mode 100644 test_notebooks/conftest.py create mode 100644 test_notebooks/notebook_tests.py diff --git a/test_notebooks/__init__.py b/test_notebooks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test_notebooks/conftest.py b/test_notebooks/conftest.py new file mode 100644 index 0000000000..b3afe61860 --- /dev/null +++ b/test_notebooks/conftest.py @@ -0,0 +1,13 @@ +import os +import sys +import pytest +_MY_DIR = os.path.realpath(os.path.dirname(__file__)) +# Allow import of the test utilities packages + + +@pytest.fixture(scope="session") +def notebooks_path(): + + notebook_path = os.path.join( + _MY_DIR, os.pardir, os.pardir, "notebooks") + return os.path.abs(notebook_path) diff --git a/test_notebooks/notebook_tests.py b/test_notebooks/notebook_tests.py new file mode 100644 index 0000000000..c04db645bb --- /dev/null +++ b/test_notebooks/notebook_tests.py @@ -0,0 +1,57 @@ + + +from nbconvert.preprocessors import CellExecutionError +from nbconvert.preprocessors import ExecutePreprocessor +import nbformat +import subprocess +import os +import pytest +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) + + +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) +PARENT_DIR = os.path.join(TEST_DIR, os.pardir, '..') + + +def process_notebook(notebook_filename, html_directory='notebook-html'): + '''Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs). + ''' + with open(notebook_filename) as f: + nb = nbformat.read(f, as_version=4) + + ep = ExecutePreprocessor( + timeout=600, kernel_name='python3', allow_errors=True) + + try: + # Check that the notebook runs + ep.preprocess(nb, {'metadata': {'path': ''}}) + except CellExecutionError: + raise + + print(f"Successfully executed {notebook_filename}") + return + + +def test_all_notebooks(remove_fail_test=True): + '''Runs `process_notebook` on all notebooks in the git repository. + ''' + # Get all files included in the git repository + git_files = (subprocess + .check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True) + .decode('utf-8') + .splitlines()) + + # Get just the notebooks from the git files + notebooks = [fn for fn in git_files if fn.endswith(".ipynb")] + print(notebooks) + + # Test each notebook + for notebook in notebooks: + print("Testing", notebook) + process_notebook(os.path.join(PARENT_DIR, notebook)) + + return + + +if __name__ == '__main__': + test_all_notebooks() From a0f0341162fb5c373c91a9c00ef55c971c7695b5 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Mon, 8 Feb 2021 08:45:47 -0800 Subject: [PATCH 15/25] =?UTF-8?q?=F0=9F=91=B7=E2=80=8D=E2=99=80=EF=B8=8Fad?= =?UTF-8?q?d=20notetbook=20test=20to=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/continuous-integration.yml | 5 ++++ test_notebooks/notebook_tests.py | 30 ++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 857da2924f..1f445af94f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -55,6 +55,8 @@ jobs: finish: needs: test runs-on: ubuntu-latest + strategy: + max-parallel: 2 steps: - name: Coveralls Finished env: @@ -63,4 +65,7 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} + - name: Check example notebook + run: + pytest test_notebooks/notebook_tests.py diff --git a/test_notebooks/notebook_tests.py b/test_notebooks/notebook_tests.py index c04db645bb..6e9ffd8cf8 100644 --- a/test_notebooks/notebook_tests.py +++ b/test_notebooks/notebook_tests.py @@ -1,30 +1,25 @@ - - from nbconvert.preprocessors import CellExecutionError from nbconvert.preprocessors import ExecutePreprocessor import nbformat import subprocess import os import pytest -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) - TEST_DIR = os.path.dirname(os.path.abspath(__file__)) -PARENT_DIR = os.path.join(TEST_DIR, os.pardir, '..') +PARENT_DIR = os.path.join(TEST_DIR, os.pardir, "..") + +def process_notebook(notebook_filename, html_directory="notebook-html"): + """Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs).""" -def process_notebook(notebook_filename, html_directory='notebook-html'): - '''Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs). - ''' with open(notebook_filename) as f: nb = nbformat.read(f, as_version=4) - ep = ExecutePreprocessor( - timeout=600, kernel_name='python3', allow_errors=True) + ep = ExecutePreprocessor(timeout=600, kernel_name="python3", allow_errors=True) try: # Check that the notebook runs - ep.preprocess(nb, {'metadata': {'path': ''}}) + ep.preprocess(nb, {"metadata": {"path": ""}}) except CellExecutionError: raise @@ -33,13 +28,12 @@ def process_notebook(notebook_filename, html_directory='notebook-html'): def test_all_notebooks(remove_fail_test=True): - '''Runs `process_notebook` on all notebooks in the git repository. - ''' + """ + Runs `process_notebook` on all notebooks in the git repository. + """ + # Get all files included in the git repository - git_files = (subprocess - .check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True) - .decode('utf-8') - .splitlines()) + git_files = subprocess.check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True).decode("utf-8").splitlines() # Get just the notebooks from the git files notebooks = [fn for fn in git_files if fn.endswith(".ipynb")] @@ -53,5 +47,5 @@ def test_all_notebooks(remove_fail_test=True): return -if __name__ == '__main__': +if __name__ == "__main__": test_all_notebooks() From bd4755902ad6352dc6ab9215b1151f8b44d900b1 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Mon, 8 Feb 2021 19:30:59 -0800 Subject: [PATCH 16/25] fix drafter --- .github/workflows/release-drafter.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 5f37c5c2c3..5b3f0acc03 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -5,6 +5,7 @@ on: # branches to consider in the event; optional, defaults to all branches: - mainline + - WHY-2304_notebook_tests jobs: update_release_draft: @@ -12,5 +13,8 @@ jobs: steps: # Drafts your next Release notes as Pull Requests are merged into "mainline" - uses: release-drafter/release-drafter@v5 + #with: + # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml + # config-name: my-config.yml env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 725c581148a5b39438a577a6433d44488a7d37ec Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 18:48:04 -0800 Subject: [PATCH 17/25] remove space --- .github/workflows/release-drafter.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 5b3f0acc03..918f16e851 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -13,8 +13,5 @@ jobs: steps: # Drafts your next Release notes as Pull Requests are merged into "mainline" - uses: release-drafter/release-drafter@v5 - #with: - # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml - # config-name: my-config.yml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 9763fe2e4760cc296174e6d66c0fc4677a18f221 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:06:23 -0800 Subject: [PATCH 18/25] test notebook after test --- .github/workflows/continuous-integration.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1f445af94f..c9712287ea 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -43,6 +43,10 @@ jobs: - name: Test with tox run: | make test-all + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python >= 3.8}} + run: | + pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel if: ${{matrix.os == 'ubuntu-latest'}} env: @@ -65,7 +69,4 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} - - name: Check example notebook - run: - pytest test_notebooks/notebook_tests.py From ea48c24811cc5905061553088c745b9919d75b6e Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:26:57 -0800 Subject: [PATCH 19/25] fix logic in notebook test --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c9712287ea..2d4d50d4bf 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' & matrix.python >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From 2d779515f812f69ac3b945d75c7c6b6e026ad09f Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:27:36 -0800 Subject: [PATCH 20/25] fix matrix python variable name --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2d4d50d4bf..dc1a0c7d32 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' & matrix.python >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' & matrix.python-version >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From 9d0700eb0a2ab37a8a7207ef5751e4d5767792b7 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:36:06 -0800 Subject: [PATCH 21/25] fix logical --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index dc1a0c7d32..07c7b17eda 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,7 +44,7 @@ jobs: run: | make test-all - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' & matrix.python-version >= 3.8}} + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} run: | pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel From 42ff82688278a48ac33d252c24632146cfdfb354 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 19:58:02 -0800 Subject: [PATCH 22/25] push notebook test after coverage computation --- .github/workflows/continuous-integration.yml | 8 ++++---- requirements-test.txt | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 07c7b17eda..9bfa9870b7 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -43,10 +43,6 @@ jobs: - name: Test with tox run: | make test-all - - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} - run: | - pytest test_notebooks/notebook_tests.py - name: Coveralls Parallel if: ${{matrix.os == 'ubuntu-latest'}} env: @@ -56,6 +52,10 @@ jobs: flag-name: run-${{ matrix.os }}-${{matrix.python-version}} parallel: true github-token : ${{ secrets.GITHUB_TOKEN}} + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} + run: | + pytest test_notebooks/notebook_tests.py finish: needs: test runs-on: ubuntu-latest diff --git a/requirements-test.txt b/requirements-test.txt index c2a2a3724b..467b6a7532 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -31,3 +31,4 @@ xlrd==2.0.1 openpyxl==3.0.6 smart-open==4.1.2 tqdm==4.54.0 +nbconvert==6.0.7 \ No newline at end of file From f3c8c5ea3554317cb8dd168be2c3d8d9fe5a47ca Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 20:13:09 -0800 Subject: [PATCH 23/25] install pytest and reqs for notebook --- .github/workflows/continuous-integration.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9bfa9870b7..32a97284d6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -52,10 +52,7 @@ jobs: flag-name: run-${{ matrix.os }}-${{matrix.python-version}} parallel: true github-token : ${{ secrets.GITHUB_TOKEN}} - - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} - run: | - pytest test_notebooks/notebook_tests.py + finish: needs: test runs-on: ubuntu-latest @@ -69,4 +66,14 @@ jobs: with: parallel-finished: true github-token : ${{ secrets.GITHUB_TOKEN }} + - name: Set up Python 3.8 for notebook + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Test with notebook + if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} + run: | + python -m pip install --upgrade pip + pip install -r requirements-test.txt + pytest test_notebooks/notebook_tests.py From b8354a5382fa6b93e9f223458338a02940c0218c Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Tue, 9 Feb 2021 21:04:42 -0800 Subject: [PATCH 24/25] remove unused matrix --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 32a97284d6..946cd6545e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -71,7 +71,6 @@ jobs: with: python-version: 3.8 - name: Test with notebook - if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version >= 3.8}} run: | python -m pip install --upgrade pip pip install -r requirements-test.txt From 13bf24ac69ed3c3a642e653873d1ca53dca870dc Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Wed, 10 Feb 2021 10:10:39 -0800 Subject: [PATCH 25/25] remove pip install --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 946cd6545e..4564890ee1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -72,7 +72,6 @@ jobs: python-version: 3.8 - name: Test with notebook run: | - python -m pip install --upgrade pip pip install -r requirements-test.txt pytest test_notebooks/notebook_tests.py