File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ):
You can’t perform that action at this time.
0 commit comments