def test__when__relations__given__nothing__then__relations(self): graph = Graph() node = graph.create_node() relation_a = graph.create_node().create_relation_to(node) relation_b = node.create_relation_to(graph.create_node()) assert_that(node.relations).contains_only(relation_a, relation_b)
def test__when__other__given__head__then__tail(self): graph = Graph() tail = graph.create_node() head = graph.create_node() relation = tail.create_relation_to(head) other = relation.other(head) assert_that(other).is_equal_to(tail)
def test__when__delete__given____then__graph_none_ident_released(self): graph = Graph() ident = graph.next_ident() node = graph.create_node() node.delete() assert_that(node.graph).is_none() assert_that(graph.next_ident()).is_equal_to(ident)
def test__when__add_types__given__types__then__types(self): graph = Graph() tail = graph.create_node() head = graph.create_node() relation = tail.create_relation_to(head) relation.add_types('type1', 'type2', 'type1') assert_that(relation.types).contains_only('type1', 'type2')
def test__when__init__given__nothing__then__properties_are_set(self): graph = Graph() ident = graph.next_ident() node = graph.create_node() assert_that(node.graph).is_equal_to(graph) assert_that(node.ident).is_equal_to(ident) assert_that(node.labels).is_empty()
def test__when__remove_labels__given__labels_and_outlier__then__remaining_labels( self): graph = Graph() node = graph.create_node() node.add_labels('label1', 'label2') node.remove_labels('label2', 'label3') assert_that(node.labels).contains_only('label1')
def test__when__delete__given__relations__then__exception(self): graph = Graph() node = graph.create_node() node.create_relation_to(graph.create_node()) assert_that(node.delete) \ .raises(Exception) \ .when_called_with() \ .is_equal_to('Node not empty')
def test__when__delete__given____then__graph_none_ident_released(self): graph = Graph() tail = graph.create_node() head = graph.create_node() ident = graph.next_ident() relation = tail.create_relation_to(head) relation.delete() assert_that(relation.graph).is_none() assert_that(graph.next_ident()).is_equal_to(ident)
def test__when__other__given__other_node__then__exception(self): graph = Graph() tail = graph.create_node() head = graph.create_node() other = graph.create_node() r = tail.create_relation_to(head) assert_that(r.other) \ .raises(ValueError) \ .when_called_with(other) \ .is_equal_to("'node' is invalid: <%s>" % other)
def test__when__init__given__node__then__properties_are_set(self): graph = Graph() tail = graph.create_node() head = graph.create_node() ident = graph.next_ident() relation = tail.create_relation_to(head) assert_that(relation.graph).is_equal_to(graph) assert_that(relation.ident).is_equal_to(ident) assert_that(relation.tail).is_equal_to(tail) assert_that(relation.head).is_equal_to(head) assert_that(relation.types).is_empty()
def test__when__init__given__graph_and_ident__then__properties_are_set( self): graph = Graph() entity = Entity(graph, 5) assert_that(entity.graph).is_equal_to(graph) assert_that(entity.ident).is_equal_to(5)
def test_return_value_0(self): graph = Graph() kb = Builder().load_from_str('RULE RETURN "Coot-coot!" AS msg').build() session = kb.get_session(graph) session.fire_all() session.close() assert_that(session).is_not_none() assert_that(session._graph).is_none()
def test_insert_0(self): graph = Graph() kb = Builder().load_from_str('RULE RETURN True').build() session = kb.get_session(graph) assert_that(session.insert) \ .raises(ValueError) \ .when_called_with(None) \ .is_equal_to('This entity is invalid')
def _payload(pos: int = 0) -> Payload: if not TestCondition.payload: g = Graph() n1 = g.create_node() n1.add_labels('main', 'person') n1.set_property('first name', 'Wiley') n1.set_property('middle names', 'E.') n1.set_property('last name', 'Coyote') n2 = g.create_node() n2.add_labels('company') n2.set_property('name', 'ACME') r = n1.create_relation_to(n2) r.add_types('works_at') r.set_property('current', True) TestCondition.payload = [n1, r, n2] return TestCondition.payload[:pos] if pos else TestCondition.payload
def test_create_labels_0(self): graph = Graph() kb = Builder().load_from_str( "RULE CREATE ($n:main:person{name: 'Stefano'}) RETURN labels($n) AS classes" ).build() session = kb.get_session(graph) session.fire_all() session.close() assert_that(session).is_not_none()
def test__when__init__given__node_from_other_graph__then__exception(self): graph_1 = Graph() node_1 = graph_1.create_node() graph_2 = Graph() node_2 = graph_2.create_node() assert_that(node_1.create_relation_to) \ .raises(ValueError) \ .when_called_with(node_2) \ .is_equal_to("'node' is invalid: <%s>" % node_2)
from grapple.graph import Graph if __name__ == '__main__': g = Graph() n1 = g.create_node() n2 = g.create_node() r = n1.create_relation_to(n2) r.add_types('starts_at') r.set_property('modified', True) n = n2 for r in n.find_relations(): if r.tail == r.other(n): print(n, '<' + str(r), r.other(n)) elif r.head == r.other(n): print(n, str(r) + '>', r.other(n)) else: print(n, r, r.other(n))
def test__when__add_labels__given__labels__then__labels(self): graph = Graph() node = graph.create_node() node.add_labels('label1', 'label2', 'label1') assert_that(node.labels).contains_only('label1', 'label2')