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 6c815f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ jobs:
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
- name: Get changed files - all
id: changed-files-all
uses: tj-actions/changed-files@v44
Expand All @@ -40,10 +28,21 @@ 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 }}"
31 changes: 31 additions & 0 deletions tests/test_notebooks,py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from testbook import testbook
import sys

TIMEOUT: int = 60

def test_notebooks():
if sys.environ.get("SHOULD_TEST_ALL_FILES", "") == "true":
notebooks_to_test = get_all_notebooks()
else:
if sys.environ.get("HAS_ANY_IPYNB_CHANGED", "") == "true":
notebooks_to_test = sys.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 6c815f5

Please sign in to comment.