def test_can_parse_comment_with_other_elements(self): nodes, rels, entries = parse('(A) /* this is a comment */ (B)') assert nodes == { "A": geoff.AbstractNode("A", {}), "B": geoff.AbstractNode("B", {}), } assert rels == [] assert entries == {}
def test_can_parse_relationship(self): nodes, rels, entries = parse('(A)-[:KNOWS]->(B) {"since": 1999}') assert nodes == { "A": geoff.AbstractNode("A", {}), "B": geoff.AbstractNode("B", {}), } assert rels == [ geoff.AbstractRelationship(nodes["A"], "KNOWS", {"since": 1999}, nodes["B"]), ] assert entries == {}
def test_can_parse_node_plus_reverse_path(self): nodes, rels, entries = parse('(A)<-[:KNOWS]-(B)') assert nodes == { "A": geoff.AbstractNode("A", {}), "B": geoff.AbstractNode("B", {}), } assert len(rels) == 1 assert isinstance(rels[0], geoff.AbstractRelationship) assert rels[0].start_node == nodes["B"] assert rels[0].type == "KNOWS" assert rels[0].end_node == nodes["A"] assert rels[0].properties == {} assert entries == {}
def test_can_parse_one_liner_graph(self): nodes, rels, entries = parse( '(A {"name": "Alice"})-[:KNOWS]->(B {"name": "Bob"})') assert nodes == { "A": geoff.AbstractNode("A", {"name": "Alice"}), "B": geoff.AbstractNode("B", {"name": "Bob"}), } assert len(rels) == 1 assert isinstance(rels[0], geoff.AbstractRelationship) assert rels[0].start_node == nodes["A"] assert rels[0].type == "KNOWS" assert rels[0].end_node == nodes["B"] assert rels[0].properties == {} assert entries == {}
def test_can_parse_node(self): nodes, rels, entries = parse('(A) {"name": "Alice"}') assert nodes == { "A": geoff.AbstractNode("A", {"name": "Alice"}), } assert rels == [] assert entries == {}
def test_can_parse_anonymous_node_with_non_json_data(self): nodes, rels, entries = parse('({name: "Alice"})') assert len(nodes) == 1 for key, value in nodes.items(): assert value == geoff.AbstractNode(None, {"name": "Alice"}) assert rels == [] assert entries == {}
def test_can_parse_anonymous_node(self): nodes, rels, entries = parse('()') assert len(nodes) == 1 for key, value in nodes.items(): assert value == geoff.AbstractNode(None, {}) assert rels == [] assert entries == {}
def test_can_parse_node_with_many_data_types(self): nodes, rels, entries = parse( '(A {"name":"Alice","age":34,"awesome":true,"lazy":false,' '"children":null,"fib":[1,1,2,3,5,8,13,21],"empty":[],' '"rainbow":["red","orange","yellow","green","blue","indigo","violet"]})' ) assert nodes == { "A": geoff.AbstractNode( "A", { "name": "Alice", "age": 34, "awesome": True, "lazy": False, "children": None, "fib": [1, 1, 2, 3, 5, 8, 13, 21], "empty": [], "rainbow": [ "red", "orange", "yellow", "green", "blue", "indigo", "violet" ], }) } assert rels == [] assert entries == {}
def test_can_parse_longer_path(self): nodes, rels, entries = parse('(A)-[:KNOWS]->' '(B)-[:KNOWS]->' '(C)<-[:KNOWS]-' '(D)') assert nodes == { "A": geoff.AbstractNode("A", {}), "B": geoff.AbstractNode("B", {}), "C": geoff.AbstractNode("C", {}), "D": geoff.AbstractNode("D", {}), } assert rels == [ geoff.AbstractRelationship(nodes["A"], "KNOWS", {}, nodes["B"]), geoff.AbstractRelationship(nodes["B"], "KNOWS", {}, nodes["C"]), geoff.AbstractRelationship(nodes["D"], "KNOWS", {}, nodes["C"]), ] assert entries == {}
def test_can_parse_index_entry(self): nodes, rels, entries = parse( '(A)<=|People| {"email": "*****@*****.**"}') assert nodes == { "A": geoff.AbstractNode("A", {}), } assert rels == [] assert entries == { ('People', 'email', '*****@*****.**', 'A'): geoff.AbstractIndexEntry("People", "email", "*****@*****.**", nodes["A"]), }
def test_can_parse_longer_path_and_data(self): nodes, rels, entries = parse( '(A {"name":"Alice","age":34})-[:KNOWS {since:1999}]->' '(B {"name":"Bob"})-[:KNOWS {friends:true}]->' '(C {"name":"Carol"})<-[:KNOWS]-' '(D {"name":"Dave"})') assert nodes == { "A": geoff.AbstractNode("A", { "name": "Alice", "age": 34 }), "B": geoff.AbstractNode("B", {"name": "Bob"}), "C": geoff.AbstractNode("C", {"name": "Carol"}), "D": geoff.AbstractNode("D", {"name": "Dave"}), } assert rels == [ geoff.AbstractRelationship(nodes["A"], "KNOWS", {"since": 1999}, nodes["B"]), geoff.AbstractRelationship(nodes["B"], "KNOWS", {"friends": True}, nodes["C"]), geoff.AbstractRelationship(nodes["D"], "KNOWS", {}, nodes["C"]), ] assert entries == {}
def test_can_parse_node_with_non_json_data(self): nodes, rels, entries = parse('(A {name: "Alice"})') assert nodes == {"A": geoff.AbstractNode("A", {"name": "Alice"})} assert rels == [] assert entries == {}
def test_can_parse_node(self): nodes, rels, entries = parse('(A)') assert nodes == {"A": geoff.AbstractNode("A", {})} assert rels == [] assert entries == {}