Skip to content

Commit

Permalink
Add check for Group constructor uri type and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kounelisagis committed Apr 3, 2024
1 parent 292c811 commit b33c836
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tiledb/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np

import tiledb
import tiledb.cc as lt

from .ctx import Config, Ctx, CtxMixin, default_ctx
Expand Down Expand Up @@ -264,6 +265,11 @@ def __init__(
config: Config = None,
ctx: Optional[Ctx] = None,
):
if uri is not None and tiledb.object_type(uri) != "group":
raise ValueError(
f"uri '{uri}' is not a valid TileDB Group path, uri is of type {tiledb.object_type(uri)}"
)

if mode not in Group._mode_to_query_type:
raise ValueError(f"invalid mode {mode}")
query_type = Group._mode_to_query_type[mode]
Expand Down
17 changes: 14 additions & 3 deletions tiledb/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_group_members(self):

grp = tiledb.Group(grp_path, "w")
assert os.path.basename(grp.uri) == os.path.basename(grp_path)
array_path = self.path("test_group_members")
array_path = self.path("test_group_members_array")
domain = tiledb.Domain(tiledb.Dim(domain=(1, 8), tile=2))
a1 = tiledb.Attr("val", dtype="f8")
schema = tiledb.ArraySchema(domain=domain, attrs=(a1,))
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_group_members(self):
assert grp[1].name is None

assert "test_group_members GROUP" in repr(grp)
assert "|-- test_group_members ARRAY" in repr(grp)
assert "|-- test_group_members_array ARRAY" in repr(grp)
assert "|-- test_group_0 GROUP" in repr(grp)

grp.close()
Expand Down Expand Up @@ -342,8 +342,19 @@ def test_set_config(self):
with tiledb.Group(group_uri, config=cfg) as G:
assert len(G) == sz

def test_invalid_object_type(self):
path = self.path()
schema = tiledb.ArraySchema(
domain=tiledb.Domain(tiledb.Dim("id", dtype="ascii")),
attrs=(tiledb.Attr("value", dtype=np.int64),),
sparse=True,
)
tiledb.Array.create(path, schema)
with self.assertRaises(ValueError):
tiledb.Group(uri=path, mode="w")

def test_group_does_not_exist(self):
with self.assertRaises(tiledb.TileDBError):
with self.assertRaises(ValueError):
tiledb.Group("does-not-exist")


Expand Down

0 comments on commit b33c836

Please sign in to comment.