Skip to content
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

incorporate pytest in github workflows #23

Merged
merged 26 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ab599e9
tests
geoffwoollard Jun 20, 2024
0483e90
python version
geoffwoollard Jun 20, 2024
481b13f
should fail
geoffwoollard Jun 20, 2024
22f7d45
unit test. should pass in about 1 min
geoffwoollard Jun 20, 2024
f11da61
test data
geoffwoollard Jun 20, 2024
4e1573c
unit test
geoffwoollard Jun 20, 2024
1beb216
path to test config
geoffwoollard Jun 20, 2024
75c68be
wget from osf, test. full data
geoffwoollard Jun 20, 2024
07f241e
testing data
geoffwoollard Jun 20, 2024
76c5017
empty file for directory
geoffwoollard Jun 20, 2024
caa0a1a
name of test
geoffwoollard Jun 20, 2024
b13489e
remove file. can mkdir in github workflow runner
geoffwoollard Jun 20, 2024
f4e2670
paths to osf files and pip caching
geoffwoollard Jun 20, 2024
c567e34
mkdir: cannot create directory ‘data/dataset_2_submissions’: No such …
geoffwoollard Jun 20, 2024
e13b5de
local pytest passing. osf paths updated.
geoffwoollard Jun 20, 2024
841fa6c
omegaconf dependency
geoffwoollard Jun 20, 2024
eddb780
test submission with 8 volumes
geoffwoollard Jun 21, 2024
8c3e1b4
path
geoffwoollard Jun 21, 2024
f664c6e
paths
geoffwoollard Jun 21, 2024
d04ab4e
order of tests
geoffwoollard Jun 21, 2024
a854d21
script for getting osf data
geoffwoollard Jun 21, 2024
893c007
script to download
geoffwoollard Jun 21, 2024
d4af336
cache data
geoffwoollard Jun 21, 2024
a1dfa52
cache data
geoffwoollard Jun 21, 2024
efa716f
cache data
geoffwoollard Jun 21, 2024
b57150b
Adding omegaconf to "dev" dependencies to allow running the tests loc…
DavidHerreros Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# GHA workflow for running tests.
#
# Largely taken from
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# Please check the link for more detailed instructions

name: Run tests

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache dependencies and test data
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache/pip
tests/data
data
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml', '**/tests/scripts/fetch_test_data.sh') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install pytest omegaconf

- name: Get test data from OSF
if: steps.cache.outputs.cache-hit != 'true'
run: |
sh tests/scripts/fetch_test_data.sh

- name: Test with pytest
run: |
pytest tests/test_map_to_map.py
pytest tests/test_distribution_to_distribution.py
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ dev = [
"pytest",
"mypy",
"pre-commit",
"ruff"
"ruff",
"omegaconf"
]

[project.urls]
Expand Down
12 changes: 12 additions & 0 deletions tests/config_files/test_config_distribution_to_distribution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
input_fname: tests/results/test_map_to_map_distance_matrix_submission_0.pkl
metrics:
- l2
gt_metadata_fname: tests/data/test_metadata_10.csv
n_replicates: 3
n_pool_microstate: 2
replicate_fraction: 0.9
cvxpy_solver: ECOS
optimal_q_kl:
n_iter: 100000
break_atol: 0.0001
output_fname: results/test_distribution_to_distribution_submission_0.pkl
23 changes: 23 additions & 0 deletions tests/config_files/test_config_map_to_map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
data:
n_pix: 224
psize: 2.146
submission:
fname: tests/data/dataset_2_submissions/test_submission_0_n8.pt
volume_key: volumes
metadata_key: populations
label_key: id
ground_truth:
volumes: tests/data/test_maps_gt_flat_10.pt
metadata: tests/data/test_metadata_10.csv
mask:
do: true
volume: data/mask_dilated_wide_224x224.mrc
analysis:
metrics:
- l2
chunk_size_submission: 80
chunk_size_gt: 190
normalize:
do: true
method: median_zscore
output: tests/results/test_map_to_map_distance_matrix_submission_0.pkl
Binary file added tests/data/test_maps_gt_flat_2.pt
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/data/test_metadata_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
index,volumes,populations_count,pc1,populations
3238,13396.mrc,1,-231.62100638454024,2.9636654614427123e-05
3789,30099.mrc,2,243.32448171011487,5.927330922885425e-05
5 changes: 5 additions & 0 deletions tests/scripts/fetch_test_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mkdir -p data/dataset_2_submissions tests/data/dataset_2_submissions tests/results
wget https://files.osf.io/v1/resources/8h6fz/providers/dropbox/dataset_2_submissions/test_submission_0_n8.pt?download=true -O tests/data/dataset_2_submissions/test_submission_0_n8.pt
wget https://files.osf.io/v1/resources/8h6fz/providers/dropbox/Ground_truth/test_maps_gt_flat_10.pt?download=true -O tests/data/test_maps_gt_flat_10.pt
wget https://files.osf.io/v1/resources/8h6fz/providers/dropbox/Ground_truth/test_metadata_10.csv?download=true -O tests/data/test_metadata_10.csv
wget https://files.osf.io/v1/resources/8h6fz/providers/dropbox/Ground_truth/mask_dilated_wide_224x224.mrc?download=true -O data/mask_dilated_wide_224x224.mrc
7 changes: 7 additions & 0 deletions tests/test_distribution_to_distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from omegaconf import OmegaConf
from cryo_challenge._commands import run_distribution2distribution_pipeline


def test_run_distribution2distribution_pipeline():
args = OmegaConf.create({'config': 'tests/config_files/test_config_distribution_to_distribution.yaml'})
run_distribution2distribution_pipeline.main(args)
7 changes: 7 additions & 0 deletions tests/test_map_to_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from omegaconf import OmegaConf
from cryo_challenge._commands import run_map2map_pipeline


def test_run_map2map_pipeline():
args = OmegaConf.create({'config': 'tests/config_files/test_config_map_to_map.yaml'})
run_map2map_pipeline.main(args)
Loading