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

Fix/unit tests #1159

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 21 additions & 5 deletions tests/core/test_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import hypothesis.strategies as st
import pytest
from hypothesis import given
from hypothesis import given, settings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -112,8 +112,23 @@ def test_different_obs_id_length(


class TestCleanup(TestBase):
@given(adata=get_adata(max_obs=5, max_vars=5), inplace=st.booleans())
def test_cleanup_all(self, adata: AnnData, inplace: bool):
@pytest.mark.parametrize("dataset", ["pancreas", "dentategyrus"])
@pytest.mark.parametrize("n_obs", [50, 100])
@pytest.mark.parametrize("layer", [None, "unspliced", "spliced"])
@pytest.mark.parametrize("dense", [True, False])
@pytest.mark.parametrize("inplace", [True, False])
def test_cleanup_all(
self, adata, dataset: str, n_obs: int, layer: bool, dense: bool, inplace: bool
):
adata = adata(dataset=dataset, n_obs=n_obs, raw=False, preprocessed=True)
adata.layers["dummy_layer"] = csr_matrix(np.eye(adata.n_obs, adata.n_vars))
adata.uns["dummy_entry"] = {"key": csr_matrix(np.eye(5, 7))}

if dense:
if layer is None:
adata.X = adata.X.A
else:
adata.layers[layer] = adata.layers[layer].A
returned_adata = cleanup(adata=adata, clean="all", inplace=inplace)

if not inplace:
Expand All @@ -122,12 +137,13 @@ def test_cleanup_all(self, adata: AnnData, inplace: bool):
else:
assert returned_adata is None

assert len(adata.layers) == 0
assert len(adata.uns) == 0
assert list(adata.layers.keys()) == ["Ms", "Mu", "spliced", "unspliced"]
assert list(adata.uns.keys()) == ["neighbors"]
assert len(adata.obs.columns) == 0
assert len(adata.var.columns) == 0

@given(adata=get_adata(max_obs=5, max_vars=5), inplace=st.booleans())
@settings(max_examples=10, deadline=1000)
def test_cleanup_default_clean_w_random_adata(self, adata: AnnData, inplace: bool):
n_obs_cols = len(adata.obs.columns)
n_var_cols = len(adata.var.columns)
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def dentategyrus_adata(tmpdir_factory):


@pytest.mark.skipif(
sys.version_info[:2] != (3, 8) or sys.platform != "linux",
sys.version_info[:2] != (3, 10) or sys.platform != "linux",
reason="Limit number of downloads to speed up testing.",
)
class TestDataSets:
Expand Down
Loading