Skip to content

Commit

Permalink
test testbook
Browse files Browse the repository at this point in the history
  • Loading branch information
classiqdor committed May 7, 2024
1 parent 6c3eaee commit e51775b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ jobs:
- name: 'Install dependencies'
run: |
python -m pip install -U -r requirements.txt
python -m pip install -U pytest
- name: Get changed files
id: changed-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only HEAD^ HEAD | xargs)" >> $GITHUB_OUTPUT
fi
- name: List changed files
run: |
for file in ${{ steps.changed-files.outputs.changed_files }}; do
echo "$file was changed"
done
python -m pip install -U pytest testbook
- name: Get changed files - all
id: changed-files-all
Expand All @@ -40,10 +28,23 @@ jobs:
files: |
**.ipynb
- name: Set environment variables
run: |
if [ "${{ github.event_name }}" == 'pull_request' ]; then
echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV
echo "HAS_ANY_FILE_CHANGED=${{ steps.changed-files-all.outputs.any_changed }}" >> $GITHUB_ENV
echo "LIST_OF_FILE_CHANGED=${{ steps.changed-files-all.outputs.all_changed_files }}" >> $GITHUB_ENV
echo "HAS_ANY_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.any_changed }}" >> $GITHUB_ENV
echo "LIST_OF_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.all_changed_files }}" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" == 'workflow_dispatch' ]; then
echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV
echo "HAS_ANY_FILE_CHANGED=None" >> $GITHUB_ENV
echo "LIST_OF_FILE_CHANGED=None" >> $GITHUB_ENV
echo "HAS_ANY_IPYNB_CHANGED=None" >> $GITHUB_ENV
echo "LIST_OF_IPYNB_CHANGED=None" >> $GITHUB_ENV
fi
- name: 'Run tests'
run: python -m pytest tests
env:
HAS_ANY_FILE_CHANGED: "${{ steps.changed-files-all.outputs.any_changed }}"
LIST_OF_FILE_CHANGED: "${{ steps.changed-files-all.outputs.all_changed_files }}"
HAS_ANY_IPYNB_CHANGED: "${{ steps.changed-files-ipynb.outputs.any_changed }}"
LIST_OF_IPYNB_CHANGED: "${{ steps.changed-files-ipynb.outputs.all_changed_files }}"
JUPYTER_PLATFORM_DIRS: "1"
33 changes: 33 additions & 0 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from testbook import testbook
import os

TIMEOUT: int = 60


def test_notebooks():
if os.environ.get("SHOULD_TEST_ALL_FILES", "") == "true":
notebooks_to_test = get_all_notebooks()
else:
if os.environ.get("HAS_ANY_IPYNB_CHANGED", "") == "true":
notebooks_to_test = os.environ.get("LIST_OF_IPYNB_CHANGED", "").split()
else:
return

# for notebook_path in notebooks_to_test:
# with testbook(
# notebook_path,
# execute=True,
# timeout=TIMEOUT,
# allow_errors=False,
# ) as tb:
# pass # we simply wish it to run without errors

print(notebooks_to_test)
assert False


def get_all_notebooks():
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".ipynb"):
yield os.path.join(root, file)

0 comments on commit e51775b

Please sign in to comment.