Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Nov 25, 2024
1 parent dd18110 commit 85f4a5d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apis/python/tests/test_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import time
from unittest import mock
import importlib
import typeguard

import pytest

Expand Down Expand Up @@ -122,3 +124,38 @@ def test_malformed_concurrency_config_value():
tiledbsoma.IntIndexer(np.arange(100, dtype=np.int64), context=ctx).get_indexer(
np.array([0, 1])
)

@pytest.mark.skipif(
importlib.util.find_spec("tiledb") is not None, reason="TileDB-Py is installed"
)
def test_tiledb_ctx_without_tiledb():
# Test that tiledb_ctx errors out as expected without tiledb-py

with pytest.raises(ModuleNotFoundError):
tiledbsoma.SOMATileDBContext(tiledb_ctx="junk")

sctx = tiledbsoma.SOMATileDBContext()
with pytest.raises(ModuleNotFoundError):
sctx.tiledb_ctx

with pytest.raises(ModuleNotFoundError):
sctx.replace(tiledb_ctx="junk")

@pytest.mark.skipif(
importlib.util.find_spec("tiledb") is None, reason="TileDB-Py is not installed"
)
def test_tiledb_ctx_with_tiledb():
# If tiledb-py is installed, test that tiledb_ctx works to handle tiledb.Ctx
import tiledb

# Default
sctx = tiledbsoma.SOMATileDBContext(tiledb_ctx=tiledb.Ctx())
assert sctx.tiledb_ctx.config() == tiledb.Ctx().config()

# Pass config
sctx = tiledbsoma.SOMATileDBContext(tiledb_ctx=tiledb.Ctx({"foo": "bar"}))
assert sctx.tiledb_ctx.config()["foo"] == "bar"

# Replace config
sctx = sctx.replace(tiledb_ctx=tiledb.Ctx({"foo": "baz"}))
assert sctx.tiledb_ctx.config()["foo"] == "baz"

0 comments on commit 85f4a5d

Please sign in to comment.