Before creating ANY git commit, you MUST:
-
Run unit tests to ensure code changes don't break existing functionality:
pytest tests/
-
Run pre-commit hooks on all staged files:
pre-commit run --all-files
-
If tests fail:
- Review the test failures and error messages
- Fix the code to make tests pass
- Re-run tests to verify all tests pass
- DO NOT proceed with commit until all tests pass
-
If pre-commit fails:
- Review the linting errors and warnings
- Fix all issues automatically where possible (pre-commit often auto-fixes)
- Stage the auto-fixed files
- Re-run pre-commit to verify all issues are resolved
- Repeat until pre-commit passes successfully
-
Only after BOTH tests and pre-commit pass, proceed with the git commit
-
NEVER:
- Commit without running tests first
- Commit without running pre-commit first
- Use
--no-verifyto skip pre-commit hooks - Ignore test failures, linting errors, or warnings
- Skip tests with
-kor-mflags to avoid failing tests
This project uses the following linting and formatting tools via pre-commit:
- black: Python code formatter
- ruff: Fast Python linter (with auto-fix enabled)
- pyupgrade: Automatically upgrades Python syntax for newer versions (Python 3.10+)
- pre-commit-hooks: trailing whitespace, end-of-file fixer, YAML/JSON validation, etc.
When making code changes, you MUST:
-
Run existing tests to ensure no regressions:
pytest tests/
-
Write new tests for new functionality:
- Add test functions to appropriate test files in
tests/directory - Follow existing test patterns (see
tests/test_*.pyfiles) - Test edge cases, error conditions, and expected behavior
- Ensure new tests pass before committing
- Add test functions to appropriate test files in
-
Update tests when modifying existing functionality:
- Update affected test cases to reflect new behavior
- Ensure all tests still pass after changes
-
Test file organization:
tests/test_config.py- Configuration testingtests/test_io.py- I/O functionality testingtests/test_radclss.py- Core radclss functionalitytests/test_vis.py- Visualization testing
# 1. Make your code changes
# ... edit files ...
# 2. Run tests to verify nothing breaks
pytest tests/
# 3. If you added new functionality, write tests for it
# ... create/update test files ...
# 4. Run tests again to ensure new tests pass
pytest tests/
# 5. Stage your changes
git add file1.py file2.py tests/test_new_feature.py
# 6. Run pre-commit
pre-commit run --all-files
# 7. If pre-commit made fixes, stage them
git add -u
# 8. Re-run to verify
pre-commit run --all-files
# 9. Once tests and pre-commit pass, commit
git commit -m "Your commit message"If pytest or pre-commit is not installed, install them first:
# Install pytest for running tests
pip install pytest
# Install pre-commit for linting hooks
pip install pre-commit
pre-commit install# Run all tests
pytest tests/
# Run a specific test file
pytest tests/test_config.py
# Run a specific test function
pytest tests/test_config.py::test_function_name
# Run tests with verbose output
pytest tests/ -v
# Run tests and show print statements
pytest tests/ -s