|
2 | 2 |
|
3 | 3 | """Tests for `stlearn` package.""" |
4 | 4 |
|
| 5 | +import shutil |
5 | 6 | import unittest |
| 7 | +from pathlib import Path |
6 | 8 |
|
7 | 9 | import scanpy as sc |
8 | 10 |
|
9 | 11 | import stlearn as st |
10 | 12 |
|
11 | 13 | from .utils import read_test_data |
12 | 14 |
|
13 | | -global adata |
14 | | -adata = read_test_data() |
15 | | - |
16 | 15 |
|
17 | 16 | class TestSME(unittest.TestCase): |
18 | 17 | """Tests for `stlearn` package.""" |
19 | 18 |
|
20 | | - def test_SME(self): |
21 | | - sc.pp.pca(adata) |
22 | | - st.pp.tiling(adata, "./tiling") |
23 | | - st.pp.extract_feature(adata) |
24 | | - import shutil |
| 19 | + def setUp(self): |
| 20 | + self.adata = read_test_data() |
| 21 | + self.tiling_dir = "./tiling" |
25 | 22 |
|
26 | | - shutil.rmtree("./tiling") |
27 | | - data_SME = adata.copy() |
| 23 | + def tearDown(self): |
| 24 | + if Path(self.tiling_dir).exists(): |
| 25 | + shutil.rmtree(self.tiling_dir) |
| 26 | + |
| 27 | + def test_SME(self): |
| 28 | + sc.pp.pca(self.adata) |
| 29 | + st.pp.tiling(self.adata, self.tiling_dir) |
| 30 | + st.pp.extract_feature(self.adata) |
| 31 | + self.assertIn("X_tile_feature", self.adata.obsm) |
| 32 | + self.assertIn("X_morphology", self.adata.obsm) |
| 33 | + self.assertEqual(self.adata.obsm["X_pca"].shape, (316, 50)) |
| 34 | + self.assertEqual(self.adata.obsm["X_tile_feature"].shape, (316, 2048)) |
| 35 | + self.assertEqual(self.adata.obsm["X_morphology"].shape, (316, 50)) |
| 36 | + data_SME = self.adata.copy() |
28 | 37 | # apply stSME to normalise log transformed data |
29 | 38 | st.spatial.SME.SME_normalize(data_SME, use_data="raw") |
0 commit comments