From 5c3be0024e14b03fdbc52ddb06de6ad57459ee25 Mon Sep 17 00:00:00 2001 From: jkobject Date: Thu, 5 Sep 2024 17:11:12 +0200 Subject: [PATCH] better tests --- tests/test_base.py | 76 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index d2f46f5..4eeaf26 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -13,25 +13,27 @@ from scdataloader import Preprocessor from torch.utils.data import DataLoader +import pytest def test_base(): assert NAME == "scdataloader" - - print("populating ontology...") - start_time = time.time() - utils.populate_my_ontology( - organisms=["NCBITaxon:10090", "NCBITaxon:9606"], - sex=["PATO:0000384", "PATO:0000383"], - # celltypes=None, - # ethnicities=None, - # assays=None, - # tissues=None, - # diseases=None, - # dev_stages=None, - ) - end_time = time.time() - print(f"ontology populated in {end_time - start_time:.2f} seconds") +adata = sc.read_h5ad(os.path.join(os.path.dirname(__file__), "test.h5ad")) + try: + print("populating ontology...") + start_time = time.time() + utils.populate_my_ontology( + organisms=["NCBITaxon:10090", "NCBITaxon:9606"], + sex=["PATO:0000384", "PATO:0000383"], + # celltypes=None, + # ethnicities=None, + # assays=None, + # tissues=None, + # diseases=None, + # dev_stages=None, + ) + end_time = time.time() + print(f"ontology populated in {end_time - start_time:.2f} seconds") # cx_dataset = ( # ln.Collection.using(instance="laminlabs/cellxgene") # .filter(name="cellxgene-census", version="2023-12-15") @@ -52,26 +54,24 @@ def test_base(): # print(i) # break # assert True, "Datamodule test passed" - - adata = sc.read_h5ad(os.path.join(os.path.dirname(__file__), "test.h5ad")) - preprocessor = Preprocessor(do_postp=False) - adata = preprocessor(adata) - - adataset = SimpleAnnDataset(adata, obs_to_output=["organism_ontology_term_id"]) - col = Collator( - organisms=["NCBITaxon:9606"], - max_len=1000, - how="random expr", - ) - dataloader = DataLoader( - adataset, - collate_fn=col, - batch_size=4, - num_workers=1, - shuffle=False, - ) - print("dataloader created") - for batch in dataloader: - print(batch) - break - assert True, "SimpleAnnDataset test passed" + preprocessor = Preprocessor(do_postp=False) + adata = preprocessor(adata) + adataset = SimpleAnnDataset(adata, obs_to_output=["organism_ontology_term_id"]) + col = Collator( + organisms=["NCBITaxon:9606"], + max_len=1000, + how="random expr", + ) + dataloader = DataLoader( + adataset, + collate_fn=col, + batch_size=4, + num_workers=1, + shuffle=False, + ) + print("dataloader created") + for batch in dataloader: + print(batch) + break + except Exception as e: + pytest.fail(f"An exception occurred: {str(e)}")