File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -328,12 +328,18 @@ def tuple_get(string, count=None):
328
328
"""
329
329
if not string :
330
330
return None
331
+
331
332
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
+
333
337
string = string [1 :- 1 ]
334
338
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
+
337
343
return res
338
344
339
345
Original file line number Diff line number Diff line change @@ -213,10 +213,10 @@ def test_tuple(self):
213
213
self .assertEqual (typ .tuple_get ("(39.12; 67.19)" ), ["39.12" , "67.19" ])
214
214
215
215
# Test fail on missing parenthesis.
216
- with self .assertRaises (AssertionError ):
216
+ with self .assertRaises (ValueError ):
217
217
_ = typ .tuple_get ("fail" )
218
218
# Test fail on mismatching element count and count number.
219
- with self .assertRaises (AssertionError ):
219
+ with self .assertRaises (ValueError ):
220
220
_ = typ .tuple_get ("(1; 2; 3)" , 2 )
221
221
222
222
def test_dtype_none (self ):
You can’t perform that action at this time.
0 commit comments