-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): add GitHub Action for Python tests, fix EarlyStopping logic…
…, and add unit tests (#27) This PR introduces several key changes: 1. A GitHub Actions workflow for continuous integration, running tests across multiple Python versions. 2. Fixes to the `EarlyStopping` class logic, changing `best_score` to `best_val_loss` to improve clarity and correctness. 3. A new test suite for the `EarlyStopping` class to ensure its correct behavior after the logic fix. ### Changes: - **Added Python application tests**: - A new workflow named "Python Application Tests" runs on GitHub Actions. - Tests are executed across multiple Python versions (`3.9`, `3.10`, `3.11`, `3.12`). - The workflow is triggered on pushes and pull requests to the `main` branch. - Pip dependencies are cached to optimize performance. - **Fixed EarlyStopping logic**: - The variable `best_score` was renamed to `best_val_loss` for clarity, improving the code's readability and matching the purpose of the variable. - Logic for early stopping was updated to properly handle edge cases for delta and stopping conditions based on validation loss behavior. - **Added Unit Tests for `EarlyStopping`**: - The file `test_early_stopping.py` contains a thorough set of tests covering: - Initialization and attribute checks. - Behavior when validation loss improves. - Handling when validation loss does not improve. - Proper functionality of patience and delta parameters. - Edge cases for early stopping triggers and verbose output. ### Why this change is important: - Automates testing across different Python versions to ensure compatibility and reliability. - Fixes logic issues in the `EarlyStopping` class, making it more robust and clear. - Ensures the `EarlyStopping` class functions as expected through the added unit tests. - Improves development velocity by automatically running tests on every push and pull request.
- Loading branch information
Showing
8 changed files
with
500 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Python Application Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: ['3.9', '3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
# Step 1: Checkout the repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Set up Python | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'pip' | ||
|
||
# Step 3: Install dependencies | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
# Step 4: Install pytest (if not in requirements.txt) | ||
- name: Install pytest | ||
run: pip install pytest | ||
|
||
# Step 5: Run tests | ||
- name: Run tests | ||
run: pytest |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# requirements-dev.txt | ||
-r requirements.txt | ||
pytest | ||
pytest-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# requirements.txt | ||
matplotlib | ||
numpy | ||
torchvision |
Empty file.
Oops, something went wrong.