Bug fix - parse_array fails on int arrays

This commit is contained in:
Itai Shirav 2016-09-15 12:03:41 +03:00
parent 66f8e8a4ae
commit 685e3dffe9
2 changed files with 17 additions and 2 deletions

View File

@ -73,8 +73,8 @@ def parse_array(array_string):
else:
# Start of non-quoted value, find its end
match = re.search(r",|\]", array_string)
values.append(array_string[1 : match.start() + 1])
array_string = array_string[match.end():]
values.append(array_string[0 : match.start()])
array_string = array_string[match.end() - 1:]
def import_submodules(package_name):

View File

@ -46,6 +46,21 @@ class ArrayFieldsTest(unittest.TestCase):
with self.assertRaises(ValueError):
instance.arr_int = value
def test_parse_array(self):
from infi.clickhouse_orm.utils import parse_array, unescape
self.assertEquals(parse_array("[]"), [])
self.assertEquals(parse_array("[1, 2, 395, -44]"), ["1", "2", "395", "-44"])
self.assertEquals(parse_array("['big','mouse','','!']"), ["big", "mouse", "", "!"])
self.assertEquals(parse_array(unescape("['\\r\\n\\0\\t\\b']")), ["\r\n\0\t\b"])
for s in ("",
"[",
"]",
"[1, 2",
"3, 4]",
"['aaa', 'aaa]"):
with self.assertRaises(ValueError):
parse_array(s)
class ModelWithArrays(Model):