simplify tests

This commit is contained in:
Alok Saldanha
2025-11-08 10:58:03 -05:00
parent 1d1d8b4e59
commit c8056991b0
3 changed files with 5 additions and 55 deletions

View File

@@ -8,24 +8,16 @@ from unittest.mock import MagicMock, Mock, patch
from cellxgene_gateway.items.item import ItemType
from cellxgene_gateway.items.s3.s3item import S3Item
from cellxgene_gateway.items.s3.s3item_source import S3ItemSource
from cellxgene_gateway.gateway import app
class TestScanDirectory(unittest.TestCase):
def setUp(self):
self._tmpdir = tempfile.mkdtemp()
self._cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
os.environ["CELLXGENE_DATA"] = self._tmpdir
from cellxgene_gateway.gateway import app
self.app = app
def tearDown(self):
if self._cellxgene_data:
os.environ["CELLXGENE_DATA"] = self._cellxgene_data
else:
del os.environ["CELLXGENE_DATA"]
shutil.rmtree(self._tmpdir)
pass
@patch("s3fs.S3FileSystem")
def test_GIVEN_invalid_bucket_THEN_throws_error(self, s3func):

View File

@@ -10,6 +10,7 @@ from cellxgene_gateway.cache_key import CacheKey
from cellxgene_gateway.items.item import ItemType
from cellxgene_gateway.items.file.fileitem import FileItem
from cellxgene_gateway.items.file.fileitem_source import FileItemSource
from cellxgene_gateway.gateway import app
key = CacheKey(
FileItem("/czi/", name="pbmc3k.h5ad", type=ItemType.h5ad),
@@ -19,12 +20,6 @@ key = CacheKey(
class TestRenderEntry(unittest.TestCase):
def setUp(self):
self._tmpdir = tempfile.mkdtemp()
self._cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
os.environ["CELLXGENE_DATA"] = self._tmpdir
from cellxgene_gateway.gateway import app
self.app = app
self.app_context = self.app.test_request_context()
self.app_context.push()
@@ -32,12 +27,7 @@ class TestRenderEntry(unittest.TestCase):
def tearDown(self):
self.app_context.pop()
if self._cellxgene_data:
os.environ["CELLXGENE_DATA"] = self._cellxgene_data
else:
del os.environ["CELLXGENE_DATA"]
shutil.rmtree(self._tmpdir)
def test_GIVEN_key_and_port_THEN_returns_loading_CacheEntry(self):
entry = CacheEntry.for_key("some-key", 1)
self.assertEqual(entry.status, CacheEntryStatus.loading)

View File

@@ -13,6 +13,7 @@ from cellxgene_gateway.filecrawl import (
from cellxgene_gateway.items.file.fileitem import FileItem
from cellxgene_gateway.items.file.fileitem_source import FileItemSource
from cellxgene_gateway.items.item import ItemTree, ItemType
from cellxgene_gateway.gateway import app
source = FileItemSource("/tmp")
@@ -29,23 +30,12 @@ def make_entry(subpath="somepath", annotations=None):
class TestRenderEntry(unittest.TestCase):
def setUp(self):
self._tmpdir = tempfile.mkdtemp()
self._cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
os.environ["CELLXGENE_DATA"] = self._tmpdir
from cellxgene_gateway.gateway import app
self.app = app
self.app_context = self.app.test_request_context()
self.app_context.push()
def tearDown(self):
self.app_context.pop()
if self._cellxgene_data:
os.environ["CELLXGENE_DATA"] = self._cellxgene_data
else:
del os.environ["CELLXGENE_DATA"]
shutil.rmtree(self._tmpdir)
def test_GIVEN_path_both_slash_THEN_view_has_single_slash(self):
entry = make_entry(subpath="/somepath/")
@@ -71,23 +61,12 @@ class TestRenderEntry(unittest.TestCase):
class TestRenderAnnotation(unittest.TestCase):
def setUp(self):
self._tmpdir = tempfile.mkdtemp()
self._cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
os.environ["CELLXGENE_DATA"] = self._tmpdir
from cellxgene_gateway.gateway import app
self.app = app
self.app_context = self.app.test_request_context()
self.app_context.push()
def tearDown(self):
self.app_context.pop()
if self._cellxgene_data:
os.environ["CELLXGENE_DATA"] = self._cellxgene_data
else:
del os.environ["CELLXGENE_DATA"]
shutil.rmtree(self._tmpdir)
@patch("cellxgene_gateway.filecrawl.enable_annotations", new=True)
def test_GIVEN_no_annotation_THEN_new_alone(self):
@@ -145,23 +124,12 @@ class TestRenderItemSource(unittest.TestCase):
class TestRenderItemTree(unittest.TestCase):
def setUp(self):
self._tmpdir = tempfile.mkdtemp()
self._cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
os.environ["CELLXGENE_DATA"] = self._tmpdir
from cellxgene_gateway.gateway import app
self.app = app
self.app_context = self.app.test_request_context()
self.app_context.push()
def tearDown(self):
self.app_context.pop()
if self._cellxgene_data:
os.environ["CELLXGENE_DATA"] = self._cellxgene_data
else:
del os.environ["CELLXGENE_DATA"]
shutil.rmtree(self._tmpdir)
@patch("cellxgene_gateway.items.file.fileitem_source.FileItemSource")
def test_GIVEN_deep_nested_dirs_THEN_includes_dirs_in_output(self, item_source):