-
Notifications
You must be signed in to change notification settings - Fork 1
Add comprehensive test suite and coverage utilities #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
58dcc3f
23b4355
592742e
fc727a7
c9589e8
efe4e8d
91519f6
e889ad9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Coverage.py configuration file | ||
| # https://coverage.readthedocs.io/en/latest/config.html | ||
|
|
||
| [run] | ||
| # The source code directories to measure | ||
| source = cellmap_flow | ||
|
|
||
| # Files to omit from coverage | ||
| omit = | ||
| */tests/*, | ||
| */test_*, | ||
| */__pycache__/*, | ||
| */.*, | ||
| */venv/*, | ||
| */virtualenv/*, | ||
| */site-packages/*, | ||
| setup.py, | ||
| conftest.py, | ||
| */migrations/*, | ||
| */node_modules/*, | ||
|
|
||
| # Enable branch coverage | ||
| branch = True | ||
|
|
||
| # Disable parallel mode to avoid file conflicts | ||
| parallel = False | ||
|
|
||
| # Specify data file location | ||
| data_file = .coverage | ||
|
|
||
| [report] | ||
| # Regexes for lines to exclude from consideration | ||
| exclude_lines = | ||
| # Have to re-enable the standard pragma | ||
| pragma: no cover | ||
|
|
||
| # Don't complain about missing debug-only code: | ||
| def __repr__ | ||
| if self\.debug | ||
|
|
||
| # Don't complain if tests don't hit defensive assertion code: | ||
| raise AssertionError | ||
| raise NotImplementedError | ||
|
|
||
| # Don't complain if non-runnable code isn't run: | ||
| if 0: | ||
| if __name__ == .__main__.: | ||
| if TYPE_CHECKING: | ||
|
|
||
| # Don't complain about abstract methods | ||
| @(abc\.)?abstractmethod | ||
|
|
||
| # Ignore warnings about missing files | ||
| ignore_errors = True | ||
|
|
||
| # Show line numbers of missing statements | ||
| show_missing = True | ||
|
|
||
| # Set precision for percentage display | ||
| precision = 2 | ||
|
|
||
| # Sort by name for consistent output | ||
| sort = Name | ||
|
|
||
| [html] | ||
| # Directory for HTML coverage report | ||
| directory = htmlcov | ||
|
|
||
| # Title for HTML report | ||
| title = cellmap-flow Coverage Report | ||
|
|
||
| # Show contexts for each covered line | ||
| show_contexts = True | ||
|
|
||
| [xml] | ||
| # Output file for XML report (for CI/CD systems) | ||
| output = coverage.xml | ||
|
|
||
| [json] | ||
| # Output file for JSON report | ||
| output = coverage.json | ||
|
|
||
| # Show contexts in JSON report | ||
| show_contexts = True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| name: Tests and Coverage | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, develop ] | ||
| pull_request: | ||
| branches: [ main, develop ] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: [3.11, 3.12] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Cache pip packages | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.cache/pip | ||
| key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pip- | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[test]" | ||
|
|
||
| - name: Run tests with coverage | ||
| run: | | ||
| python -m pytest tests/ \ | ||
| --cov=cellmap_flow \ | ||
| --cov-report=xml \ | ||
| --cov-report=term-missing \ | ||
| --cov-branch \ | ||
| -v | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v3 | ||
| with: | ||
| file: ./coverage.xml | ||
| flags: unittests | ||
| name: codecov-umbrella | ||
| fail_ci_if_error: false | ||
|
|
||
| coverage-report: | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'pull_request' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: 3.11 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[test]" | ||
| pip install coverage-badge | ||
|
|
||
| - name: Run coverage | ||
| run: | | ||
| python -m pytest tests/ \ | ||
| --cov=cellmap_flow \ | ||
| --cov-report=json \ | ||
| --cov-report=html \ | ||
| --cov-branch | ||
|
|
||
| - name: Generate coverage badge | ||
| run: | | ||
| coverage-badge -o coverage.svg | ||
|
|
||
| - name: Upload coverage reports as artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-reports | ||
| path: | | ||
| htmlcov/ | ||
| coverage.svg | ||
| coverage.json | ||
| retention-days: 30 | ||
|
|
||
| coverage-comment: | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'pull_request' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: 3.11 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[test]" | ||
|
|
||
| - name: Run coverage | ||
| run: | | ||
| python -m pytest tests/ \ | ||
| --cov=cellmap_flow \ | ||
| --cov-report=json | ||
|
|
||
| - name: Coverage comment | ||
| uses: py-cov-action/python-coverage-comment-action@v3 | ||
| with: | ||
| GITHUB_TOKEN: ${{ github.token }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,4 +162,4 @@ cython_debug/ | |
| #.idea/ | ||
|
|
||
| # Misc | ||
| .vscode/ | ||
| .vscode/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Simple Makefile for cellmap-flow project | ||
|
|
||
| .PHONY: test test-cov clean install install-dev | ||
|
|
||
| test: | ||
| python -m pytest tests/ -v | ||
|
|
||
| test-cov: | ||
| python tests/coverage_utils.py | ||
|
|
||
| clean: | ||
| python tests/coverage_utils.py --clean | ||
| rm -rf .pytest_cache __pycache__ htmlcov | ||
|
|
||
| install: | ||
| pip install -e . | ||
|
|
||
| install-dev: | ||
| pip install -e ".[dev]" |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,19 +27,11 @@ | |||||||||||||
| import time | ||||||||||||||
|
|
||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||
| # Explicitly set template and static folder paths for package installation | ||||||||||||||
| template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates") | ||||||||||||||
| static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static") | ||||||||||||||
| app = Flask(__name__, template_folder=template_dir, static_folder=static_dir) | ||||||||||||||
| app = Flask(__name__) | ||||||||||||||
| CORS(app) | ||||||||||||||
| NEUROGLANCER_URL = None | ||||||||||||||
| INFERENCE_SERVER = None | ||||||||||||||
| CUSTOM_CODE_FOLDER = os.path.expanduser( | ||||||||||||||
| os.environ.get( | ||||||||||||||
| "CUSTOM_CODE_FOLDER", | ||||||||||||||
| "~/Desktop/cellmap/cellmap-flow/example/example_norm", | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| CustomCodeFolder = "/Users/zouinkhim/Desktop/cellmap/cellmap-flow/example/example_norm" | ||||||||||||||
|
||||||||||||||
| CustomCodeFolder = "/Users/zouinkhim/Desktop/cellmap/cellmap-flow/example/example_norm" | |
| CustomCodeFolder = os.getenv( | |
| "CUSTOM_CODE_FOLDER", "/path/to/default/example_norm" | |
| ) |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded absolute path contains a username which could expose sensitive information and will not work in different environments. This should use environment variables or relative paths.
| CustomCodeFolder = "/Users/zouinkhim/Desktop/cellmap/cellmap-flow/example/example_norm" | |
| CustomCodeFolder = os.getenv("CUSTOM_CODE_FOLDER", "./example/example_norm") |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -122,7 +122,7 @@ def _get_config(self): | |||||
| config.output_channels = len( | ||||||
| config.channels | ||||||
| ) # 0:all_mem,1:organelle,2:mito,3:er,4:nucleus,5:pm,6:vs,7:ld | ||||||
|
||||||
| ) # 0:all_mem,1:organelle,2:mito,3:er,4:nucleus,5:pm,6:vs,7:ld | |
| ) # config.channels: 0:all_mem,1:organelle,2:mito,3:er,4:nucleus,5:pm,6:vs,7:ld |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hardcoded path should not be committed to production code. It contains a specific user's home directory path that won't work for other users or deployment environments.