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 compare_value(self, lhs: ValueWrapper, rhs: ValueWrapper): """ lhs and rhs represent response data and expected data respectively """ if lhs.is_null(): return rhs.is_null() and lhs.as_null() == rhs.as_null() if lhs.is_empty(): return rhs.is_empty() if lhs.is_bool(): return rhs.is_bool() and lhs.as_bool() == rhs.as_bool() if lhs.is_int(): return rhs.is_int() and lhs.as_int() == rhs.as_int() if lhs.is_double(): return (rhs.is_double() and math.fabs(lhs.as_double() - rhs.as_double()) < 1.0E-8) if lhs.is_string(): return rhs.is_string() and lhs.as_string() == rhs.as_string() if lhs.is_date(): return (rhs.is_date() and lhs.as_date() == rhs.as_date()) or ( rhs.is_string() and str(lhs.as_date()) == rhs.as_string()) if lhs.is_time(): return (rhs.is_time() and lhs.as_time() == rhs.as_time()) or ( rhs.is_string() and str(lhs.as_time()) == rhs.as_string()) if lhs.is_datetime(): return ((rhs.is_datetime() and lhs.as_datetime() == rhs.as_datetime()) or (rhs.is_string() and str(lhs.as_datetime()) == rhs.as_string())) if lhs.is_list(): return rhs.is_list() and self.compare_list(lhs.as_list(), rhs.as_list()) if lhs.is_set(): return rhs.is_set() and self._compare_list( lhs.as_set(), rhs.as_set(), self.compare_value) if lhs.is_map(): return rhs.is_map() and self.compare_map(lhs.as_map(), rhs.as_map()) if lhs.is_vertex(): return rhs.is_vertex() and self.compare_node( lhs.as_node(), rhs.as_node()) if lhs.is_edge(): return rhs.is_edge() and self.compare_edge(lhs.as_relationship(), rhs.as_relationship()) if lhs.is_path(): return rhs.is_path() and self.compare_path(lhs.as_path(), rhs.as_path()) return False
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)