Skip to content

Commit 4af3bc0

Browse files
committed
[odml/dtypes] Raise ValueError in tuple_get
Closes #354 Also updates the corresponding test.
1 parent 8bec9a2 commit 4af3bc0

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

odml/dtypes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,18 @@ def tuple_get(string, count=None):
328328
"""
329329
if not string:
330330
return None
331+
331332
string = string.strip()
332-
assert string.startswith("(") and string.endswith(")")
333+
if not (string.startswith("(") and string.endswith(")")):
334+
msg = "Tuple value misses brackets: '%s'" % string
335+
raise ValueError(msg)
336+
333337
string = string[1:-1]
334338
res = [x.strip() for x in string.split(";")]
335-
if count is not None: # be strict
336-
assert len(res) == count
339+
if count is not None and not len(res) == count:
340+
msg = "%s-tuple value does not match required item length" % count
341+
raise ValueError(msg)
342+
337343
return res
338344

339345

test/test_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ def test_tuple(self):
213213
self.assertEqual(typ.tuple_get("(39.12; 67.19)"), ["39.12", "67.19"])
214214

215215
# Test fail on missing parenthesis.
216-
with self.assertRaises(AssertionError):
216+
with self.assertRaises(ValueError):
217217
_ = typ.tuple_get("fail")
218218
# Test fail on mismatching element count and count number.
219-
with self.assertRaises(AssertionError):
219+
with self.assertRaises(ValueError):
220220
_ = typ.tuple_get("(1; 2; 3)", 2)
221221

222222
def test_dtype_none(self):

0 commit comments

Comments
 (0)