Skip to content

Commit

Permalink
add pytest to cover pcacs
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecomitani committed Nov 11, 2024
1 parent 8a4d512 commit 203f3b6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_efaar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import numpy as np
import pandas as pd
from anndata import AnnData
Expand Down Expand Up @@ -63,3 +64,30 @@ def test_filter_cell_profiler_features():
filtered_features, _ = efaar.filter_cell_profiler_features(features, metadata)
assert not filtered_features.empty
assert "Image_Granularity_12_ER" not in filtered_features.columns


@pytest.mark.parametrize(
"metadata, expected_shape, expect_error",
[
(
pd.DataFrame({"perturbation": ["control", "control", "treatment", "treatment"], "batch": [1, 1, 1, 1]}),
(4, 2),
False,
),
(
pd.DataFrame({"perturbation": ["treatment", "treatment", "treatment", "treatment"], "batch": [1, 1, 1, 1]}),
None,
True,
),
],
)
def test_pca_centerscale_on_controls(metadata, expected_shape, expect_error):
embeddings = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
pert_col = "perturbation"
control_key = "control"
if expect_error:
with pytest.raises(ValueError, match=f"No control samples found for {control_key}"):
efaar.pca_centerscale_on_controls(embeddings, metadata, pert_col, control_key, None)
else:
result = efaar.pca_centerscale_on_controls(embeddings, metadata, pert_col, control_key, None)
assert result.shape == expected_shape

0 comments on commit 203f3b6

Please sign in to comment.