Skip to content

Commit 64e8e5e

Browse files
[python] Increase unit-test coverage for various metadata value-types (#3972)
* Add more unicode sequences * Improve error messaging * Fix macos build issue * Use `bool_` instead of `bool` * Update apis/python/src/tiledbsoma/_tdb_handles.py Co-authored-by: John Kerl <kerl.john.r@gmail.com> --------- Co-authored-by: John Kerl <kerl.john.r@gmail.com>
1 parent 8fce365 commit 64e8e5e

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

apis/python/src/tiledbsoma/_tdb_handles.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,14 @@ def _write(self) -> None:
868868
self._mods.clear()
869869

870870
if errors:
871+
details = []
872+
for error in errors:
873+
details.append(repr(error))
874+
875+
error_msg_details = "\n".join(details)
876+
871877
raise SOMAError(
872-
f"[MetadataWrapper][_write] {len(errors)} errors occured while writing metadata to disk."
878+
f"[MetadataWrapper][_write] {len(errors)} error(s) occured while writing metadata to disk. Details: \n {error_msg_details}"
873879
)
874880

875881
def __repr__(self) -> str:

apis/python/tests/test_metadata.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ def non_soma_metadata(obj) -> Dict[str, Any]:
187187
0,
188188
1.00000001,
189189
-3.1415,
190+
np.float64(-3.1415),
190191
"",
191192
"\x00",
192193
"\U00000000", # get's casted to \x00
193194
"\x10abc",
194195
"\U00081a63×\x84\x94𘪩a\U000a4f44Î\x10m",
196+
"😀",
197+
"¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿",
198+
"␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎ ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␡ ␢ ␣ ␤",
195199
np.str_("foo"),
196200
"a string",
197201
math.nan,
@@ -226,7 +230,22 @@ def test_metadata_marshalling_OK(soma_object, test_value):
226230

227231
@pytest.mark.parametrize(
228232
"bad_value",
229-
[["a", "b", "c"], {"a": False}, [1, 2, 3], np.arange(10)],
233+
[
234+
["a", "b", "c"],
235+
{"a": False},
236+
[1, 2, 3],
237+
np.arange(10),
238+
np.bool_(True),
239+
np.int8(10),
240+
np.int16(10),
241+
np.int32(10),
242+
np.int64(10),
243+
np.uint8(10),
244+
np.uint16(10),
245+
np.uint32(10),
246+
np.uint64(10),
247+
np.float32(10),
248+
],
230249
)
231250
def test_metadata_marshalling_FAIL(soma_object, bad_value):
232251
"""Verify that unsupported metadata types raise an error immediately."""
@@ -239,7 +258,15 @@ def test_metadata_marshalling_FAIL(soma_object, bad_value):
239258

240259
@pytest.mark.parametrize(
241260
"good_key",
242-
["", "\x10abc", "\U00081a63×\x84\x94𘪩a\U000a4f44Î\x10m", "a string"],
261+
[
262+
"",
263+
"\x10abc",
264+
"\U00081a63×\x84\x94𘪩a\U000a4f44Î\x10m",
265+
"a string",
266+
"😀",
267+
"¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿",
268+
"␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎ ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␡ ␢ ␣ ␤",
269+
],
243270
)
244271
def test_metadata_good_key(soma_object, good_key):
245272
"""Verify that unsupported metadata types raise an error immediately."""
@@ -249,7 +276,14 @@ def test_metadata_good_key(soma_object, good_key):
249276

250277
@pytest.mark.parametrize(
251278
"bad_key",
252-
["\x00", "AA\x00BB", "AA\U00000000BB"],
279+
[
280+
"\x00",
281+
"AA\x00BB",
282+
"AA\U00000000BB",
283+
"😀\U00000000",
284+
"¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯\x00 ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿",
285+
"␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎\x00 ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␡ ␢ ␣ ␤",
286+
],
253287
)
254288
def test_metadata_bad_key(soma_object, bad_key):
255289
"""Verify that unsupported metadata types raise an error immediately."""
@@ -270,6 +304,9 @@ def test_metadata_bad_key(soma_object, bad_key):
270304
b"\xc2",
271305
b"\x00",
272306
np.bytes_("foo"),
307+
"😀\U00000000",
308+
"¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯\x00 ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿",
309+
"␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎\x00 ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␡ ␢ ␣ ␤",
273310
],
274311
)
275312
def test_metadata_bad_string_value(soma_object, bad_value):

0 commit comments

Comments
 (0)