Пример #1
0
def test_node_equality():
    g = Graph()
    node_1 = Node(g, 1234)
    node_2 = Node(g, 1234)
    node_3 = Node(g, 5678)
    assert node_1 == node_2
    assert node_1 != node_3
    assert node_1 != "this is not a node"
Пример #2
0
def test_can_create_node():
    g = Graph()
    gh = Graph.Hydrator(g)
    alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
    assert isinstance(alice, Node)
    assert alice.labels == {"Person"}
    assert set(alice.keys()) == {"name", "age"}
    assert set(alice.values()) == {"Alice", 33}
    assert set(alice.items()) == {("name", "Alice"), ("age", 33)}
    assert alice.get("name") == "Alice"
    assert alice.get("age") == 33
    assert len(alice) == 2
    assert alice["name"] == "Alice"
    assert alice["age"] == 33
    assert "name" in alice
    assert "age" in alice
    assert set(iter(alice)) == {"name", "age"}
Пример #3
0
def test_can_create_path():
    g = Graph()
    gh = Graph.Hydrator(g)
    alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
    bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
    carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
    alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id, "KNOWS",
                                              {"since": 1999})
    carol_dislikes_bob = gh.hydrate_relationship(2, carol.id, bob.id,
                                                 "DISLIKES", {})
    path = Path(alice, alice_knows_bob, carol_dislikes_bob)
    assert isinstance(path, Path)
    assert path.start_node == alice
    assert path.end_node == carol
    assert path.nodes == (alice, bob, carol)
    assert path.relationships == (alice_knows_bob, carol_dislikes_bob)
    assert list(path) == [alice_knows_bob, carol_dislikes_bob]
 def test_can_create_path(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
     alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id, "KNOWS",
                                               {"since": 1999})
     carol_dislikes_bob = gh.hydrate_relationship(2, carol.id, bob.id,
                                                  "DISLIKES", {})
     path = Path(alice, alice_knows_bob, carol_dislikes_bob)
     self.assertEqual(path.start_node, alice)
     self.assertEqual(path.end_node, carol)
     self.assertEqual(path.nodes, (alice, bob, carol))
     self.assertEqual(path.relationships,
                      (alice_knows_bob, carol_dislikes_bob))
     self.assertEqual(list(path), [alice_knows_bob, carol_dislikes_bob])
     self.assertTrue(repr(path))
Пример #5
0
 def __init__(self):
     super(DataHydrator, self).__init__()
     self.graph = Graph()
     self.graph_hydrator = Graph.Hydrator(self.graph)
     self.hydration_functions = {
         b"N": self.graph_hydrator.hydrate_node,
         b"R": self.graph_hydrator.hydrate_relationship,
         b"r": self.graph_hydrator.hydrate_unbound_relationship,
         b"P": self.graph_hydrator.hydrate_path,
         b"X": hydrate_point,
         b"Y": hydrate_point,
         b"D": hydrate_date,
         b"T": hydrate_time,         # time zone offset
         b"t": hydrate_time,         # no time zone
         b"F": hydrate_datetime,     # time zone offset
         b"f": hydrate_datetime,     # time zone name
         b"d": hydrate_datetime,     # no time zone
         b"E": hydrate_duration,
     }
Пример #6
0
def test_can_hydrate_path():
    g = Graph()
    gh = Graph.Hydrator(g)
    alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
    bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
    carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
    r = [
        gh.hydrate_unbound_relationship(1, "KNOWS", {"since": 1999}),
        gh.hydrate_unbound_relationship(2, "DISLIKES", {})
    ]
    path = gh.hydrate_path([alice, bob, carol], r, [1, 1, -2, 2])
    assert path.start_node == alice
    assert path.end_node == carol
    assert path.nodes == (alice, bob, carol)
    expected_alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id,
                                                       "KNOWS",
                                                       {"since": 1999})
    expected_carol_dislikes_bob = gh.hydrate_relationship(
        2, carol.id, bob.id, "DISLIKES", {})
    assert path.relationships == (expected_alice_knows_bob,
                                  expected_carol_dislikes_bob)
    assert list(path) == [
        expected_alice_knows_bob, expected_carol_dislikes_bob
    ]