test: add basic pytest skeleton#27
Conversation
- Create examples/ directory with 3 sample GA4GH policy documents - Add examples/DEMO.md with step-by-step instructions - Create examples/run_demo.py script demonstrating full pipeline - Demo processes 12 chunks and shows 3 sample compliance queries - Fixes ga4gh#20
types-all includes types-pkg-resources which no longer exists on PyPI. Since we're using --ignore-missing-imports, we don't need it anyway.
- Create .env.example with all required and optional variables - Create ENV_SETUP.md with comprehensive setup instructions - Add security best practices and common issues - Fixes ga4gh#23
- Add lint.yml: Run pre-commit hooks on every PR - Add tests.yml: Run pytest on multiple Python versions (3.8-3.12) - Add format.yml: Auto-fix code quality issues and commit - Add .github/workflows/README.md with workflow documentation - Automated testing and linting on every PR - Auto-fixes with PR comments - Coverage reporting with Codecov - Fixes ga4gh#24
There was a problem hiding this comment.
Pull request overview
This PR lays the groundwork for Python testing and code quality automation, and adds an end-to-end demo (script + sample documents) plus supporting documentation.
Changes:
- Add an initial pytest test file and GitHub Actions workflows for tests/lint/auto-format.
- Introduce Black/isort/Ruff/mypy configuration via
pyproject.tomland pre-commit. - Add an examples demo script, sample policy text files, and multiple documentation files.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_basic.py |
Adds initial pytest skeleton. |
src/main.py |
Minor formatting tweaks (blank lines / trailing comma). |
pyproject.toml |
Adds tool configuration for Black/isort/Ruff/mypy. |
examples/run_demo.py |
Adds an end-to-end demo script that reads sample docs and prints sample “query outputs”. |
examples/data/sample_consent_policy.txt |
Adds sample consent policy excerpt for the demo. |
examples/data/sample_privacy_policy.txt |
Adds sample privacy/security excerpt for the demo. |
examples/data/sample_genomic_framework.txt |
Adds sample genomic framework excerpt for the demo. |
examples/DEMO.md |
Adds demo instructions and expected output. |
README.md |
Documents code quality tooling and how to run checks. |
ENV_SETUP.md |
Adds environment setup instructions and .env guidance. |
CODE_QUALITY.md |
Adds code quality tool explanations and usage instructions. |
.pre-commit-config.yaml |
Adds pre-commit hooks for formatting, linting, type-checking, and hygiene checks. |
.gitignore |
Adds Python/tooling ignores and .env exclusion. |
.github/workflows/tests.yml |
Adds pytest + coverage workflow (matrix over Python versions) and Codecov upload. |
.github/workflows/lint.yml |
Adds pre-commit-based lint workflow. |
.github/workflows/format.yml |
Adds an auto-fix workflow intended to push formatting fixes back to the PR branch. |
.github/workflows/README.md |
Documents the added GitHub Actions workflows. |
.env.example |
Adds example environment variable template for local setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - \sample_consent_policy.txt\ - GA4GH Consent Policy excerpts | ||
| - \sample_privacy_policy.txt\ - GA4GH Privacy Policy excerpts | ||
| - \sample_genomic_framework.txt\ - Framework for Responsible Sharing excerpts | ||
| - \un_demo.py\ - Demo script |
There was a problem hiding this comment.
The file list contains corrupted escaping/control characters (e.g., "
un_demo.py") and uses backslashes around filenames, which makes the rendered path incorrect. Update this section to use normal inline code formatting (e.g., run_demo.py) and ensure there are no stray control characters in the filename.
| - \sample_consent_policy.txt\ - GA4GH Consent Policy excerpts | |
| - \sample_privacy_policy.txt\ - GA4GH Privacy Policy excerpts | |
| - \sample_genomic_framework.txt\ - Framework for Responsible Sharing excerpts | |
| - \un_demo.py\ - Demo script | |
| - `sample_consent_policy.txt` - GA4GH Consent Policy excerpts | |
| - `sample_privacy_policy.txt` - GA4GH Privacy Policy excerpts | |
| - `sample_genomic_framework.txt` - Framework for Responsible Sharing excerpts | |
| - `run_demo.py` - Demo script |
| - Run: \lack src/\ | ||
|
|
||
| ### Ruff | ||
| **Purpose:** Fast Python linter | ||
| - Checks PEP 8 compliance | ||
| - Catches common errors | ||
| - Fixes issues automatically | ||
| - Run: \uff check --fix src/\ | ||
|
|
There was a problem hiding this comment.
Several command examples contain stray control characters / escaping (e.g., "\b" in "\� lack" and a carriage-return-like character in "
uff"), which makes the documented commands incorrect and hard to copy. Replace these with plain inline code (e.g., black src/, ruff check --fix src/) and remove the control characters.
| - name: Run pre-commit with auto-fix | ||
| id: pre-commit | ||
| continue-on-error: true | ||
| run: pre-commit run --all-files | ||
|
|
||
| - name: Commit auto-fixes if changes made | ||
| if: steps.pre-commit.outcome == 'failure' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| if git diff --exit-code > /dev/null; then | ||
| echo "No changes to commit" | ||
| else | ||
| git add -A | ||
| git commit -m "chore: auto-fix code quality issues [skip ci]" | ||
| git push | ||
| fi | ||
|
|
||
| - name: Comment on PR with fixes | ||
| if: steps.pre-commit.outcome == 'failure' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: '✨ Auto-fixes applied! Black formatting, imports sorted, and lint issues fixed. Please review and pull the changes.' | ||
| }) |
There was a problem hiding this comment.
This workflow runs the full pre-commit suite (including non-auto-fixable hooks like mypy). When pre-commit fails for reasons that can't be auto-fixed, the job can still post the "Auto-fixes applied" PR comment even though no fixes were committed. Consider running only auto-fixable hooks here (black/isort/ruff) and/or only commenting when a diff was actually committed, with a different message for non-fixable failures.
| @@ -0,0 +1,2 @@ | |||
| def test_project_runs(): | |||
| assert True | |||
There was a problem hiding this comment.
This test currently doesn't validate anything (it will always pass). If the goal is a minimal smoke test, consider asserting that core modules import successfully and/or that constructing the main entrypoint (e.g., RegBot) works without raising.
| assert True | |
| import importlib | |
| module = importlib.import_module("importlib") | |
| assert module is importlib |
| @@ -0,0 +1,110 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
This file starts with a UTF-8 BOM character before the shebang. On Unix-like systems that prevents the kernel from recognizing the #! line, so running the script directly (./run_demo.py) may fail. Remove the BOM so the first bytes of the file are "#!".
| #!/usr/bin/env python3 | |
| #!/usr/bin/env python3 |
| - name: Comment on PR with test results | ||
| if: always() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const testStatus = '${{ job.status }}' === 'success' ? '✅ Tests passed' : '❌ Tests failed'; | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: testStatus + ' on Python ${{ matrix.python-version }}' | ||
| }) |
There was a problem hiding this comment.
This workflow comments using context.issue.number, but the workflow also runs on push events where context.issue is not set. That will cause the github-script step to fail (and potentially fail the job). Gate the comment step to pull_request events and/or use github.event.pull_request.number. Also, because this job is a matrix, this step will post one comment per Python version per run, which can spam PRs; consider aggregating results into a single comment.
| - name: Comment on PR if linting fails | ||
| if: failure() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: '⚠️ Linting failed. Please run \pre-commit run --all-files\ locally and push fixes.' | ||
| }) |
There was a problem hiding this comment.
This workflow can run on push events, but the failure-comment step uses context.issue.number (only available for PR events). On pushes this step will fail and may mask the real lint result. Restrict this step to pull_request events and/or use github.event.pull_request.number. Also, the message body includes literal backslashes around the command; consider using backticks for readability.
| To test workflows locally before pushing: | ||
|
|
||
| \\\ash | ||
| # Install act (runs GitHub Actions locally) | ||
| choco install act-cli # Windows | ||
| brew install act # Mac | ||
| apt-get install act # Linux | ||
|
|
||
| # Run a specific workflow | ||
| act -j lint | ||
|
|
||
| # Run all workflows | ||
| act | ||
| \\\ |
There was a problem hiding this comment.
The code examples use literal backslashes (e.g., \\bash ... \) instead of proper markdown fenced code blocks, which renders incorrectly. Replace these with standard triple-backtick fences (bash ... ), and remove the UTF-8 BOM at the start of the file if present.
|
|
||
|
|
There was a problem hiding this comment.
The fenced code block opened with bash is never closed, so the rest of the README renders as code (including the Roadmap section). Add a closing after the last pre-commit command and before the next section header.
| @@ -0,0 +1,88 @@ | |||
| # GA4GH-RegBot End-to-End Demo | |||
There was a problem hiding this comment.
This markdown file contains a UTF-8 BOM at the start (hidden character before the first '#'). Please remove it to avoid rendering/tooling issues and keep text files consistent.
| # GA4GH-RegBot End-to-End Demo | |
| # GA4GH-RegBot End-to-End Demo |
Adds initial pytest setup and basic test skeleton.
This provides the foundation for writing unit tests for core modules.
Closes #26