diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..277ad1a --- /dev/null +++ b/.github/workflows/testing.yml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index cf03973..85e73d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,8 @@ dev = [ "pytest", "mypy", "pre-commit", - "ruff" + "ruff", + "omegaconf" ] [project.urls] diff --git a/tests/config_files/test_config_distribution_to_distribution.yaml b/tests/config_files/test_config_distribution_to_distribution.yaml new file mode 100644 index 0000000..9359e58 --- /dev/null +++ b/tests/config_files/test_config_distribution_to_distribution.yaml @@ -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 \ No newline at end of file diff --git a/tests/config_files/test_config_map_to_map.yaml b/tests/config_files/test_config_map_to_map.yaml new file mode 100644 index 0000000..eed5fb0 --- /dev/null +++ b/tests/config_files/test_config_map_to_map.yaml @@ -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 \ No newline at end of file diff --git a/tests/data/test_maps_gt_flat_2.pt b/tests/data/test_maps_gt_flat_2.pt new file mode 100644 index 0000000..dc3293c Binary files /dev/null and b/tests/data/test_maps_gt_flat_2.pt differ diff --git a/tests/data/test_metadata_2.csv b/tests/data/test_metadata_2.csv new file mode 100644 index 0000000..b564400 --- /dev/null +++ b/tests/data/test_metadata_2.csv @@ -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 diff --git a/tests/scripts/fetch_test_data.sh b/tests/scripts/fetch_test_data.sh new file mode 100644 index 0000000..740d895 --- /dev/null +++ b/tests/scripts/fetch_test_data.sh @@ -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 \ No newline at end of file diff --git a/tests/test_distribution_to_distribution.py b/tests/test_distribution_to_distribution.py new file mode 100644 index 0000000..d9c340b --- /dev/null +++ b/tests/test_distribution_to_distribution.py @@ -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) \ No newline at end of file diff --git a/tests/test_map_to_map.py b/tests/test_map_to_map.py new file mode 100644 index 0000000..c782a8c --- /dev/null +++ b/tests/test_map_to_map.py @@ -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) \ No newline at end of file