def cmp_dataset( request, graph_spaces, result, order: bool, strict: bool, contains=CmpType.EQUAL, first_n_records=-1, hashed_columns=[], ): rs = graph_spaces['result_set'] ngql = graph_spaces['ngql'] check_resp(rs, ngql) space_desc = graph_spaces.get('space_desc', None) vid_fn = murmurhash2 if space_desc and space_desc.is_int_vid() else None ds = dataset( table(result, lambda x: normalize_outline_scenario(request, x)), graph_spaces.get("variables", {}), ) ds = hash_columns(ds, hashed_columns) dscmp = DataSetComparator(strict=strict, order=order, contains=contains, first_n_records=first_n_records, decode_type=rs._decode_type, vid_fn=vid_fn) def dsp(ds): printer = DataSetPrinter(rs._decode_type, vid_fn=vid_fn) return printer.ds_to_string(ds) def rowp(ds, i): if i is None or i < 0: return "" if i != -2 else "Invalid column names" assert i < len(ds.rows), f"{i} out of range {len(ds.rows)}" row = ds.rows[i].values printer = DataSetPrinter(rs._decode_type, vid_fn=vid_fn) ss = printer.list_to_string(row, delimiter='|') return f'{i}: |' + ss + '|' if rs._data_set_wrapper is None: assert not ds.column_names and not ds.rows, f"Expected result must be empty table: ||" rds = rs._data_set_wrapper._data_set res, i = dscmp(rds, ds) if not res: scen = request.function.__scenario__ feature = scen.feature.rel_filename location = f"{feature}:{line_number(scen._steps, result)}" msg = [ f"Fail to exec: {ngql}", f"Response: {dsp(rds)}", f"Expected: {dsp(ds)}", f"NotFoundRow: {rowp(ds, i)}", f"Location: {location}", f"Space: {str(space_desc)}", f"vid_fn: {vid_fn}", ] assert res, "\n".join(msg) return rds
def cmp_dataset(graph_spaces, result, order: bool, strict: bool, included=False) -> None: rs = graph_spaces['result_set'] ngql = graph_spaces['ngql'] check_resp(rs, ngql) space_desc = graph_spaces.get('space_desc', None) vid_fn = None if space_desc is not None: vid_fn = murmurhash2 if space_desc.vid_type == 'int' else None ds = dataset(table(result), graph_spaces.get("variables", {})) dscmp = DataSetComparator(strict=strict, order=order, included=included, decode_type=rs._decode_type, vid_fn=vid_fn) def dsp(ds): printer = DataSetPrinter(rs._decode_type) return printer.ds_to_string(ds) def rowp(ds, i): if i is None or i < 0: return "" assert i < len(ds.rows), f"{i} out of range {len(ds.rows)}" row = ds.rows[i].values printer = DataSetPrinter(rs._decode_type) ss = printer.list_to_string(row, delimiter='|') return f'{i}: |' + ss + '|' if rs._data_set_wrapper is None: assert not ds.column_names and not ds.rows, f"Expected result must be empty table: ||" rds = rs._data_set_wrapper._data_set res, i = dscmp(rds, ds) assert res, f"Fail to exec: {ngql}\nResponse: {dsp(rds)}\nExpected: {dsp(ds)}\nNotFoundRow: {rowp(ds, i)}"