Пример #1
0
 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 == {}
Пример #2
0
 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 == {}
Пример #3
0
 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 == {}
Пример #4
0
 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 == {}
Пример #5
0
 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 == {}
Пример #6
0
 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 == {}
Пример #7
0
 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 == {}
Пример #8
0
 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 == {}
Пример #9
0
 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 == {}
Пример #10
0
 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"]),
     }
Пример #11
0
 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 == {}
Пример #12
0
 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 == {}
Пример #13
0
 def test_can_parse_node(self):
     nodes, rels, entries = parse('(A)')
     assert nodes == {"A": geoff.AbstractNode("A", {})}
     assert rels == []
     assert entries == {}