def test_path_hashing(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_1 = Path(alice, alice_knows_bob, carol_dislikes_bob) path_2 = Path(alice, alice_knows_bob, carol_dislikes_bob) self.assertEqual(hash(path_1), hash(path_2))
def test_path_equality(): 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_1 = Path(alice, alice_knows_bob, carol_dislikes_bob) path_2 = Path(alice, alice_knows_bob, carol_dislikes_bob) assert path_1 == path_2 assert path_1 != "this is not a path"
def test_path_repr(): g = Graph() gh = Graph.Hydrator(g) alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice"}) bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob"}) carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol"}) 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 repr( path ) == "<Path start=<Node id=1 labels=frozenset({'Person'}) properties={'name': 'Alice'}> end=<Node id=3 labels=frozenset({'Person'}) properties={'name': 'Carol'}> size=2>"
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))