def test_base_type(self): resp = self.session.execute('FETCH PROP ON person "Bob" YIELD person.name, person.age, person.grade,' 'person.friends, person.book_num, person.birthday, ' 'person.start_school, person.morning, ' 'person.property, person.is_girl, person.child_name, ' 'person.expend, person.first_out_city, person.hobby') assert resp.is_succeeded(), resp.error_msg() assert '' == resp.error_msg() assert resp.latency() > 0 assert '' == resp.comment() assert ErrorCode.SUCCEEDED == resp.error_code() assert 'test_data' == resp.space_name() assert not resp.is_empty() assert 1 == resp.row_size() names = ['person.name', 'person.age', 'person.grade', 'person.friends', 'person.book_num', 'person.birthday', 'person.start_school', 'person.morning', 'person.property', 'person.is_girl', 'person.child_name', 'person.expend', 'person.first_out_city', 'person.hobby'] assert names == resp.keys() assert 'Bob' == resp.row_values(0)[0].as_string() assert 10 == resp.row_values(0)[1].as_int() assert 3 == resp.row_values(0)[2].as_int() assert 10 == resp.row_values(0)[3].as_int() assert 100 == resp.row_values(0)[4].as_int() return_data_time_val = resp.row_values(0)[5].as_datetime() assert return_data_time_val == \ DateTimeWrapper(DateTime(2010, 9, 10, 2, 8, 2, 0)) assert '2010-09-10T10:08:02.000000' == return_data_time_val.get_local_datetime_str() assert 'utc datetime: 2010-09-10T02:08:02.000000, timezone_offset: 28800' == str( return_data_time_val) assert DateWrapper(Date(2017, 9, 10)) == resp.row_values(0)[ 6].as_date() expected_time_val = TimeWrapper(Time(23, 10, 0, 0)) return_time_val = resp.row_values(0)[7].as_time() assert expected_time_val == return_time_val assert '07:10:00.000000' == return_time_val.get_local_time_str() assert 'utc time: 23:10:00.000000, timezone_offset: 28800' == str( return_time_val) assert 1000.0 == resp.row_values(0)[8].as_double() assert False == resp.row_values(0)[9].as_bool() assert 'Hello Worl' == resp.row_values(0)[10].as_string() assert 100.0 == resp.row_values(0)[11].as_double() assert 1111 == resp.row_values(0)[12].as_int() assert Null(Null.__NULL__) == resp.row_values(0)[13].as_null()
def test_as_time(self): time = Time() time.hour = 10 time.minute = 20 time.sec = 10 time.microsec = 100 value = ttypes.Value(tVal=time) value_wrapper = ValueWrapper(value) assert value_wrapper.is_time() time_val = value_wrapper.as_time() time_val.set_timezone_offset(28800) assert isinstance(time_val, TimeWrapper) assert time_val.get_hour() == 10 assert time_val.get_minute() == 20 assert time_val.get_sec() == 10 assert time_val.get_microsec() == 100 assert 'utc time: 10:20:10.000100, timezone_offset: 28800' == str( time_val) assert '18:20:10.000100' == time_val.get_local_time_str() new_time = copy.deepcopy(time) new_time.hour = 18 assert new_time == time_val.get_local_time() new_time_2 = copy.deepcopy(time) new_time_2.hour = 12 assert new_time_2 == time_val.get_local_time_by_timezone_offset(7200)
def time_convert_with_timezone(n_time: Time, timezone_offset: int): native_date_time = datetime(1, 1, 1, n_time.hour, n_time.minute, n_time.sec, n_time.microsec, pytz.timezone("utc")) local_date_time = native_date_time.astimezone( timezone(timedelta(seconds=timezone_offset))) local_time = Time() local_time.hour = local_date_time.hour local_time.minute = local_date_time.minute local_time.sec = local_date_time.second local_time.microsec = local_date_time.microsecond return local_time
def test_base_type(self): resp = self.session.execute( 'FETCH PROP ON person "Bob" YIELD person.name, person.age, person.grade,' 'person.friends, person.book_num, person.birthday, person.start_school, person.morning, ' 'person.property, person.is_girl, person.child_name, person.expend, person.first_out_city, person.hobby' ) assert resp.is_succeeded(), resp.error_msg() assert '' == resp.error_msg() assert resp.latency() > 0 assert '' == resp.comment() assert ttypes.ErrorCode.SUCCEEDED == resp.error_code() assert 'test_data' == resp.space_name() assert not resp.is_empty() assert 1 == resp.row_size() names = [ 'VertexID', 'person.name', 'person.age', 'person.grade', 'person.friends', 'person.book_num', 'person.birthday', 'person.start_school', 'person.morning', 'person.property', 'person.is_girl', 'person.child_name', 'person.expend', 'person.first_out_city', 'person.hobby' ] assert names == resp.keys() assert 'Bob' == resp.row_values(0)[0].as_string() assert 'Bob' == resp.row_values(0)[1].as_string() assert 10 == resp.row_values(0)[2].as_int() assert 3 == resp.row_values(0)[3].as_int() assert 10 == resp.row_values(0)[4].as_int() assert 100 == resp.row_values(0)[5].as_int() assert resp.row_values(0)[6].as_datetime() == \ DateTimeWrapper(DateTime(2010, 9, 10, 10, 8, 2, 0)) assert DateWrapper(Date(2017, 9, 10)) == resp.row_values(0)[7].as_date() assert TimeWrapper(Time(7, 10, 0, 0)) == resp.row_values(0)[8].as_time() assert 1000.0 == resp.row_values(0)[9].as_double() assert False == resp.row_values(0)[10].as_bool() assert 'Hello Worl' == resp.row_values(0)[11].as_string() assert 100.0 == resp.row_values(0)[12].as_double() assert 1111 == resp.row_values(0)[13].as_int() assert Null(Null.__NULL__) == resp.row_values(0)[14].as_null()
def test_as_time(self): time = Time() time.hour = 10 time.minute = 20 time.sec = 10 time.microsec = 100 value = ttypes.Value(tVal=time) value_wrapper = ValueWrapper(value) assert value_wrapper.is_time() time_val = value_wrapper.as_time() assert isinstance(time_val, TimeWrapper) assert time_val.get_hour() == 10 assert time_val.get_minute() == 20 assert time_val.get_sec() == 10 assert time_val.get_microsec() == 100 assert '10:20:10.000100' == str(time_val)
def time_convert_with_timezone(n_time: Time, timezone_offset: int): """the function to convert utc date_time to local date_time :param n_time: the utc time :param timezone_offset: the timezone offset :return: the time with the timezone """ native_date_time = datetime(1, 1, 1, n_time.hour, n_time.minute, n_time.sec, n_time.microsec, pytz.timezone("utc")) local_date_time = native_date_time.astimezone( timezone(timedelta(seconds=timezone_offset))) local_time = Time() local_time.hour = local_date_time.hour local_time.minute = local_date_time.minute local_time.sec = local_date_time.second local_time.microsec = local_date_time.microsecond return local_time
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)