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_node(self): value = ttypes.Value() value.set_vVal(self.get_vertex_value(b'Tom')) value_wrapper = ValueWrapper(value) assert value_wrapper.is_vertex() node = value_wrapper.as_node() assert isinstance(node, Node)
def test_as_node(self): value = ttypes.Value() value.set_vVal(self.get_vertex_value(b'Tom')) value_wrapper = ValueWrapper(value) assert value_wrapper.is_vertex() node = value_wrapper.as_node() assert isinstance(node, Node) assert node.get_id().as_string() == 'Tom' assert node.has_tag('tag1') assert node.prop_names('tag1').sort() == [ 'prop0', 'prop1', 'prop2', 'prop3', 'prop4' ].sort() expect_values = [(v.as_int()) for v in node.prop_values('tag1')] assert expect_values == [0, 1, 2, 3, 4] assert node.tags() == ['tag0', 'tag1', 'tag2'] assert list(node.properties('tag1').keys()).sort() == [ 'prop0', 'prop1', 'prop2', 'prop3', 'prop4' ].sort() expect_values = [(v.as_int()) for v in node.properties('tag1').values()] assert expect_values == [0, 1, 2, 3, 4]