Skip to content

test: add basic pytest skeleton#27

Open
NobleCoder69 wants to merge 7 commits into
ga4gh:mainfrom
NobleCoder69:add-unit-tests
Open

test: add basic pytest skeleton#27
NobleCoder69 wants to merge 7 commits into
ga4gh:mainfrom
NobleCoder69:add-unit-tests

Conversation

@NobleCoder69
Copy link
Copy Markdown

@NobleCoder69 NobleCoder69 commented Mar 11, 2026

Adds initial pytest setup and basic test skeleton.

This provides the foundation for writing unit tests for core modules.
Closes #26

- 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
Copilot AI review requested due to automatic review settings March 11, 2026 20:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.toml and 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.

Comment thread examples/DEMO.md
Comment on lines +82 to +85
- \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
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- \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

Copilot uses AI. Check for mistakes.
Comment thread CODE_QUALITY.md
Comment on lines +11 to +19
- Run: \lack src/\

### Ruff
**Purpose:** Fast Python linter
- Checks PEP 8 compliance
- Catches common errors
- Fixes issues automatically
- Run: \uff check --fix src/\

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +55
- 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.'
})
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_basic.py
@@ -0,0 +1,2 @@
def test_project_runs():
assert True
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
assert True
import importlib
module = importlib.import_module("importlib")
assert module is importlib

Copilot uses AI. Check for mistakes.
Comment thread examples/run_demo.py
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 "#!".

Suggested change
#!/usr/bin/env python3
#!/usr/bin/env python3

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +52
- 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 }}'
})
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +40
- 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.'
})
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +72
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
\\\
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines +34 to +35


Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread examples/DEMO.md
@@ -0,0 +1,88 @@
# GA4GH-RegBot End-to-End Demo
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# GA4GH-RegBot End-to-End Demo
# GA4GH-RegBot End-to-End Demo

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: Add unit tests skeleton for core modules

2 participants