Fix parsing error of test data

Fix parsing error that contains special character.
The previous implementation replaced the `:` char with `\n`,
and split on `\n`. Test data containing strings with `\n`
were split as well. Fixes #2193.
The split function caused strings containing `\:` to add
another escape char, resulting in `\\:`. This caused the
tests with the `\:` in the string data to fail.
The fix doesn't replace with `\n`, but splits all `:` that
are not preceded with `\`. After that, removes the preceding `\` char.
This commit is contained in:
Ron Eldor 2018-11-18 17:05:05 +02:00
parent 556d7d9e3b
commit 111ba0e949

View File

@ -75,11 +75,10 @@ class TestDataParser(object):
:param split_char: Split character :param split_char: Split character
:return: List of splits :return: List of splits
""" """
split_colon_fn = lambda x: re.sub(r'\\' + split_char, split_char, x)
if len(split_char) > 1: if len(split_char) > 1:
raise ValueError('Expected split character. Found string!') raise ValueError('Expected split character. Found string!')
out = re.sub(r'(\\.)|' + split_char, out = map(split_colon_fn, re.split(r'(?<!\\)' + split_char, inp_str))
lambda m: m.group(1) or '\n', inp_str,
len(inp_str)).split('\n')
out = [x for x in out if x] out = [x for x in out if x]
return out return out
@ -112,8 +111,8 @@ class TestDataParser(object):
args = parts[1:] args = parts[1:]
args_count = len(args) args_count = len(args)
if args_count % 2 != 0: if args_count % 2 != 0:
raise TestDataParserError("Number of test arguments should " err_str_fmt = "Number of test arguments({}) should be even: {}"
"be even: %s" % line) raise TestDataParserError(err_str_fmt.format(args_count, line))
grouped_args = [(args[i * 2], args[(i * 2) + 1]) grouped_args = [(args[i * 2], args[(i * 2) + 1])
for i in range(len(args)/2)] for i in range(len(args)/2)]
self.tests.append((name, function_name, dependencies, self.tests.append((name, function_name, dependencies,