Skip to content

Commit

Permalink
Update TestCleanObsNames (#600)
Browse files Browse the repository at this point in the history
Check that `inplace` argument is working correctly.
  • Loading branch information
WeilerP authored Aug 2, 2021
1 parent 5cc161f commit 2b40a6b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tests/core/test_anndata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional
from typing import Dict, List, Optional

import hypothesis.strategies as st
import pytest
Expand Down Expand Up @@ -43,11 +43,20 @@ class TestCleanObsNames:
),
],
)
def test_equal_obs_id_length(self, obs_names, obs_names_cleaned):
@pytest.mark.parametrize("inplace", (True, False))
def test_equal_obs_id_length(
self, obs_names: List[str], obs_names_cleaned: List[str], inplace: bool
):
adata = AnnData(np.eye(3))
adata.obs_names = obs_names

clean_obs_names(adata)
_adata = clean_obs_names(adata, inplace=inplace)

if inplace:
assert _adata is None
else:
assert isinstance(_adata, AnnData)
adata = _adata

assert (adata.obs_names == obs_names_cleaned).all()
assert "sample_batch" in adata.obs
Expand All @@ -62,11 +71,20 @@ def test_equal_obs_id_length(self, obs_names, obs_names_cleaned):
)
],
)
def test_different_obs_id_length(self, obs_names, obs_names_cleaned):
@pytest.mark.parametrize("inplace", (True, False))
def test_different_obs_id_length(
self, obs_names: List[str], obs_names_cleaned: List[str], inplace: bool
):
adata = AnnData(np.eye(3))
adata.obs_names = obs_names

clean_obs_names(adata)
_adata = clean_obs_names(adata, inplace=inplace)

if inplace:
assert _adata is None
else:
assert isinstance(_adata, AnnData)
adata = _adata

assert (adata.obs_names == obs_names_cleaned).all()
assert "sample_batch" in adata.obs
Expand Down

0 comments on commit 2b40a6b

Please sign in to comment.