Skip to content

Commit

Permalink
Add enumeration repr test
Browse files Browse the repository at this point in the history
  • Loading branch information
kounelisagis committed Mar 26, 2024
1 parent 6121a6a commit d24d4ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tiledb/enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(
:type ordered: bool
:param values: A Numpy array of values for this enumeration
:type values: np.array
:param dtype: The Numpy data type for this enumeration
:type dtype: np.dtype
:param ctx: A TileDB context
:type ctx: tiledb.Ctx
"""
Expand Down
24 changes: 24 additions & 0 deletions tiledb/tests/test_enumeration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import numpy as np
import pytest
from numpy.testing import assert_array_equal
Expand Down Expand Up @@ -37,6 +39,28 @@ def test_attribute_enumeration(self):
attr.enum = "enum"
assert attr.enum == "enum"

def test_enumeration_repr(self):
"""Doesn't check exact string, just makes sure each component is matched, in case order is changed in the future."""
enmr = tiledb.Enumeration("e", False, [1, 2, 3])
# Get its string representation
repr_str = repr(enmr)

# Define patterns to match each component in the representation
patterns = {
"Enumeration": r"Enumeration",
"name": r"name='e'",
# use regex because it is depending on platform
"dtype": r"dtype=int\d+",
"dtype_name": r"dtype_name='int\d+'",
"cell_val_num": r"cell_val_num=1",
"ordered": r"ordered=False",
"values": r"values=\[1, 2, 3\]",
}

# Check that each pattern is found in the representation string
for key, pattern in patterns.items():
assert re.search(pattern, repr_str), f"{key} not found or incorrect in repr"

def test_array_schema_enumeration(self):
uri = self.path("test_array_schema_enumeration")
dom = tiledb.Domain(tiledb.Dim(domain=(1, 8), tile=1))
Expand Down

0 comments on commit d24d4ef

Please sign in to comment.