Skip to content

Commit

Permalink
Merge pull request #23 from flatironinstitute/tests
Browse files Browse the repository at this point in the history
incorporate pytest in github workflows
  • Loading branch information
geoffwoollard authored Jun 24, 2024
2 parents b9d953f + b57150b commit bd57d28
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 1 deletion.
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)

0 comments on commit bd57d28

Please sign in to comment.