Skip to content

Commit 502dc03

Browse files
committed
Add simple tests for row_annotations.
1 parent 56ade41 commit 502dc03

7 files changed

Lines changed: 3861 additions & 11 deletions

File tree

stlearn/add.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from .adds.add_deconvolution import add_deconvolution
2-
from .adds.image import image
3-
from .adds.labels import labels
42
from .adds.add_loupe_clusters import add_loupe_clusters
5-
from .adds.lr import lr
63
from .adds.add_mask import add_mask, apply_mask
7-
from .adds.positions import positions
84
from .adds.annotation import annotation
5+
from .adds.image import image
6+
from .adds.labels import labels
7+
from .adds.lr import lr
98
from .adds.parsing import parsing
9+
from .adds.positions import positions
1010

1111
__all__ = [
1212
"image",

tests/adds/test_row_annotations.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
"""Tests for ClusterPlot."""
4+
5+
import unittest
6+
7+
from stlearn.adds import row_annotations
8+
from tests.utils import read_test_data, test_data_path
9+
10+
11+
class TestRowAnnotations(unittest.TestCase):
12+
"""Tests for row annotations."""
13+
14+
@classmethod
15+
def setUpClass(cls):
16+
cls._base_adata = read_test_data()
17+
cls.annotations_path = (
18+
f"{test_data_path()}/" + "v1_human_breast_cancer_block_a_section_1.csv"
19+
)
20+
21+
22+
def setUp(self):
23+
"""Set up test data with known clusters."""
24+
self.adata = self.__class__._base_adata.copy()
25+
26+
27+
def test_add_row_annotations(self):
28+
row_annotations.row_annotations(self.adata, self.__class__.annotations_path, "ID")
29+
30+
assert "annot_type" in self.adata.obs.columns
31+
assert "fine_annot_type" in self.adata.obs.columns
32+
33+
# Check annotated the same number
34+
annotated = self.adata.obs["annot_type"].dropna()
35+
fine_annotated = self.adata.obs["fine_annot_type"].dropna()
36+
assert len(fine_annotated) == len(annotated)
37+
38+
39+
def test_add_row_annotations_with_missing_column(self):
40+
with self.assertRaises(ValueError):
41+
row_annotations.row_annotations(
42+
self.adata,
43+
self.__class__.annotations_path,
44+
join_column="nonexistent_column",
45+
)

tests/pl/test_cluster_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import pandas as pd
1111

1212
from stlearn.pl.classes import ClusterPlot
13-
1413
from tests.utils import read_test_data
1514

15+
1616
class TestClusterPlot(unittest.TestCase):
1717
"""Tests for ClusterPlot."""
1818

tests/spatial/test_psts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import numpy as np
88

99
import stlearn as st
10-
1110
from tests.utils import read_test_data
1211

12+
1313
class TestPSTS(unittest.TestCase):
1414
"""Tests for `stlearn` package."""
1515

tests/spatial/test_sme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import scanpy as sc
1010

1111
import stlearn as st
12-
1312
from tests.utils import read_test_data
1413

14+
1515
class TestSME(unittest.TestCase):
1616
"""Tests for `stlearn` package."""
1717

0 commit comments

Comments
 (0)