Skip to content

Commit 7063a70

Browse files
committed
Cleanded up code that creates comparable test objects
1 parent 7a4bdc0 commit 7063a70

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

test/tck/tck_util.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,30 @@ def get_path(string_path):
241241
return path, string_path
242242

243243

244+
def record_value_to_comparable(val, func=None, rel=False):
245+
def get_val(v):
246+
if func is not None:
247+
return Value(func(v)[0])
248+
else:
249+
return Value(v)
250+
251+
if val == 'null':
252+
return Value(None)
253+
if isinstance(val, compat.string) and val[0] == '[':
254+
if not rel or (rel and val[1] == '['):
255+
val = val[1:-1].split(", ")
256+
if isinstance(val,list):
257+
return tuple([get_val(v) for v in val])
258+
else:
259+
return get_val(val)
260+
244261
def result_to_set(result, func=None, rel=False):
245-
s = set([])
246-
for row in result:
247-
l = []
248-
for i,_ in enumerate(row):
249-
cell = row[i]
250-
if cell == 'null':
251-
cell = None
252-
if isinstance(cell, compat.string) and cell[0] == '[':
253-
if rel and cell[1] != '[':
254-
cell = [cell]
255-
else:
256-
cell = cell[1:-1].split(", ")
257-
if not isinstance(cell,list):
258-
cell = [cell]
259-
if func is not None:
260-
cell = [Value(func(val)[0]) for val in cell]
261-
else:
262-
cell = [Value(val) for val in cell]
263-
l.append(tuple(cell))
264-
s.add(tuple(l))
265-
return s
262+
records = set([])
263+
for record in result:
264+
for i,_ in enumerate(record):
265+
cell = record_value_to_comparable(record[i], func, rel)
266+
records.add(cell)
267+
return records
266268

267269

268270
def text_path_to_set(table):

0 commit comments

Comments
 (0)