def p_list(p): ''' list : '[' list_items ']' | '[' ']' ''' l = NList() if len(p) == 4: l.values = p[2] else: l.values = [] p[0] = Value(lVal=l)
def test_as_list(self): value = ttypes.Value() str_val1 = ttypes.Value() str_val1.set_sVal(b"word") str_val2 = ttypes.Value() str_val2.set_sVal(b"car") val_list = NList() val_list.values = [str_val1, str_val2] value.set_lVal(val_list) value_wrapper = ValueWrapper(value) assert value_wrapper.is_list() list_val = value_wrapper.as_list() assert isinstance(list_val, list) expect_result = [ValueWrapper(ttypes.Value(sVal=b"word")), ValueWrapper(ttypes.Value(sVal=b"car"))] assert list_val == expect_result
def get_data_set(cls): data_set = ttypes.DataSet() data_set.column_names = [ b"col1_empty", b"col2_null", b"col3_bool", b"col4_int", b"col5_double", b"col6_string", b"col7_list", b"col8_set", b"col9_map", b"col10_time", b"col11_date", b"col12_datetime", b"col13_vertex", b"col14_edge", b"col15_path" ] row = ttypes.Row() row.values = [] value1 = ttypes.Value() row.values.append(value1) value2 = ttypes.Value() value2.set_nVal(NullType.BAD_DATA) row.values.append(value2) value3 = ttypes.Value() value3.set_bVal(False) row.values.append(value3) value4 = ttypes.Value() value4.set_iVal(100) row.values.append(value4) value5 = ttypes.Value() value5.set_fVal(10.01) row.values.append(value5) value6 = ttypes.Value() value6.set_sVal(b"hello world") row.values.append(value6) value7 = ttypes.Value() str_val1 = ttypes.Value() str_val1.set_sVal(b"word") str_val2 = ttypes.Value() str_val2.set_sVal(b"car") list_val = NList() list_val.values = [str_val1, str_val2] value7.set_lVal(list_val) row.values.append(value7) value8 = ttypes.Value() set_val = NSet() set_val.values = set() set_val.values.add(str_val1) set_val.values.add(str_val2) value8.set_uVal(set_val) row.values.append(value8) value9 = ttypes.Value() map = NMap() map.kvs = {b"a": str_val1, b"b": str_val2} value9.set_mVal(map) row.values.append(value9) value10 = ttypes.Value() value10.set_tVal(Time(10, 10, 10, 10000)) row.values.append(value10) value11 = ttypes.Value() value11.set_dVal(date(2020, 10, 1)) row.values.append(value11) value12 = ttypes.Value() value12.set_dtVal(DateTime(2020, 10, 1, 10, 10, 10, 10000)) row.values.append(value12) value13 = ttypes.Value() value13.set_vVal(cls.get_vertex_value(b"Tom")) row.values.append(value13) value14 = ttypes.Value() value14.set_eVal(cls.get_edge_value(b"Tom", b"Lily")) row.values.append(value14) value15 = ttypes.Value() value15.set_pVal(cls.get_path_value(b"Tom", 3)) row.values.append(value15) data_set.rows = [] data_set.rows.append(row) data_set.rows.append(row) return data_set
def get_result_set(self): resp = graphTtype.ExecutionResponse() resp.error_code = graphTtype.ErrorCode.E_BAD_PERMISSION resp.error_msg = b"Permission" resp.comment = b"Permission" resp.space_name = b"test" resp.latency_in_us = 100 data_set = ttypes.DataSet() data_set.column_names = [ b"col1_empty", b"col2_null", b"col3_bool", b"col4_int", b"col5_double", b"col6_string", b"col7_list", b"col8_set", b"col9_map", b"col10_time", b"col11_date", b"col12_datetime", b"col13_vertex", b"col14_edge", b"col15_path" ] row = ttypes.Row() row.values = [] value1 = ttypes.Value() row.values.append(value1) value2 = ttypes.Value() value2.set_nVal(NullType.BAD_DATA) row.values.append(value2) value3 = ttypes.Value() value3.set_bVal(False) row.values.append(value3) value4 = ttypes.Value() value4.set_iVal(100) row.values.append(value4) value5 = ttypes.Value() value5.set_fVal(10.01) row.values.append(value5) value6 = ttypes.Value() value6.set_sVal(b"hello world") row.values.append(value6) value7 = ttypes.Value() str_val1 = ttypes.Value() str_val1.set_sVal(b"word") str_val2 = ttypes.Value() str_val2.set_sVal(b"car") list_val = NList() list_val.values = [str_val1, str_val2] value7.set_lVal(list_val) row.values.append(value7) value8 = ttypes.Value() set_val = NSet() set_val.values = set() set_val.values.add(str_val1) set_val.values.add(str_val2) value8.set_uVal(set_val) row.values.append(value8) value9 = ttypes.Value() map = NMap() map.kvs = {b"a": str_val1, b"b": str_val2} value9.set_mVal(map) row.values.append(value9) value10 = ttypes.Value() value10.set_tVal(Time(10, 10, 10, 10000)) row.values.append(value10) value11 = ttypes.Value() value11.set_dVal(date(2020, 10, 1)) row.values.append(value11) value12 = ttypes.Value() value12.set_dtVal(DateTime(2020, 10, 1, 10, 10, 10, 10000)) row.values.append(value12) value13 = ttypes.Value() value13.set_vVal(self.get_vertex_value(b"Tom")) row.values.append(value13) value14 = ttypes.Value() value14.set_eVal(self.get_edge_value(b"Tom", b"Lily")) row.values.append(value14) value15 = ttypes.Value() value15.set_pVal(self.get_path_value(b"Tom", 3)) row.values.append(value15) data_set.rows = [] data_set.rows.append(row) resp.data = data_set return ResultSet(resp)
expected['123'] = Value(iVal=123) expected['-123'] = Value(iVal=-123) expected['3.14'] = Value(fVal=3.14) expected['-3.14'] = Value(fVal=-3.14) expected['true'] = Value(bVal=True) expected['True'] = Value(bVal=True) expected['false'] = Value(bVal=False) expected['fAlse'] = Value(bVal=False) expected["'string'"] = Value(sVal="string") expected['"string"'] = Value(sVal='string') expected['''"string'string'"'''] = Value(sVal="string'string'") expected['''/^[_a-z][-_a-z0-9]*$/'''] = re.compile(r'^[_a-z][-_a-z0-9]*$') expected['''/\\//'''] = re.compile(r'/') expected['''hash("hello")'''] = 2762169579135187400 expected['''hash("World")'''] = -295471233978816215 expected['[]'] = Value(lVal=NList([])) expected['[{}]'] = Value(lVal=NList([Value(mVal=NMap({}))])) expected['[1,2,3]'] = Value(lVal=NList([ Value(iVal=1), Value(iVal=2), Value(iVal=3), ])) expected['{1,2,3}'] = Value( uVal=NSet(set([ Value(iVal=1), Value(iVal=2), Value(iVal=3), ]))) expected['{}'] = Value(mVal=NMap({})) expected['{k1:1,"k2":true}'] = Value(mVal=NMap({ 'k1': Value(iVal=1),
def list2Nlist(list): nlist = NList() nlist.values = [] for item in list: nlist.values.append(value(item)) return nlist