Skip to content

Commit 336fcfa

Browse files
committed
test examples only if changes were made
1 parent 9d7d930 commit 336fcfa

File tree

4 files changed

+58
-155
lines changed

4 files changed

+58
-155
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ jobs:
8787
run: |
8888
python -m pytest src/hyperactive -p no:warnings
8989
90-
- name: Test additional tests
91-
run: |
92-
python -m pytest test -p no:warnings
93-
9490
test-all-extras:
9591
name: test-all-extras
9692
strategy:
@@ -125,10 +121,6 @@ jobs:
125121
run: |
126122
python -m pytest src/hyperactive -p no:warnings
127123
128-
- name: Test additional tests
129-
run: |
130-
python -m pytest test -p no:warnings
131-
132124
test-sklearn-versions:
133125
name: test-sklearn-${{ matrix.sklearn-version }}-python-${{ matrix.python-version }}
134126
runs-on: ubuntu-latest
@@ -158,3 +150,54 @@ jobs:
158150
- name: Run sklearn integration tests for ${{ matrix.sklearn-version }}
159151
run: |
160152
python -m pytest -x -p no:warnings src/hyperactive/integrations/sklearn/
153+
154+
test-examples:
155+
name: test-examples
156+
runs-on: ubuntu-latest
157+
timeout-minutes: 15
158+
159+
steps:
160+
- uses: actions/checkout@v4
161+
with:
162+
fetch-depth: 0
163+
164+
- name: Set up Python 3.11
165+
uses: actions/setup-python@v5
166+
with:
167+
python-version: "3.11"
168+
169+
- name: Check for example changes
170+
id: check-examples
171+
run: |
172+
if [ "${{ github.event_name }}" == "push" ]; then
173+
# For pushes, compare with previous commit
174+
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep "^examples/" || true)
175+
else
176+
# For pull requests, compare with base branch
177+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep "^examples/" || true)
178+
fi
179+
180+
if [ -n "$CHANGED_FILES" ]; then
181+
echo "examples_changed=true" >> $GITHUB_OUTPUT
182+
echo "Examples changed:"
183+
echo "$CHANGED_FILES"
184+
else
185+
echo "examples_changed=false" >> $GITHUB_OUTPUT
186+
echo "No example files changed"
187+
fi
188+
189+
- name: Install dependencies
190+
if: steps.check-examples.outputs.examples_changed == 'true'
191+
run: |
192+
python -m pip install --upgrade pip
193+
python -m pip install build
194+
make install-all-extras-for-test
195+
196+
- name: Show dependencies
197+
if: steps.check-examples.outputs.examples_changed == 'true'
198+
run: python -m pip list
199+
200+
- name: Test examples
201+
if: steps.check-examples.outputs.examples_changed == 'true'
202+
run: |
203+
python -m pytest examples/ -v -p no:warnings

examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test package for Hyperactive library functionality."""
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
def get_hyperactive_root():
2222
"""Get the root directory of the Hyperactive project."""
23-
# Start from the test file directory and go up to find the root
24-
current = Path(__file__).parent
25-
while current.name != "Hyperactive" and current.parent != current:
26-
current = current.parent
23+
# Since test file is now in examples/, go up one level to find the root
24+
current = Path(__file__).parent.parent
2725
return current
2826

2927

@@ -39,8 +37,10 @@ def find_all_python_examples():
3937

4038
# Find all .py files recursively in examples directory
4139
for py_file in examples_dir.rglob("*.py"):
42-
# Skip __pycache__ and other non-example files
43-
if "__pycache__" not in str(py_file) and ".pytest_cache" not in str(py_file):
40+
# Skip __pycache__, test files, and other non-example files
41+
if ("__pycache__" not in str(py_file) and
42+
".pytest_cache" not in str(py_file) and
43+
not py_file.name.startswith("test_")):
4444
python_files.append(py_file)
4545

4646
return sorted(python_files)

tests/test_examples_quick.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)