def test_can_concatenate_path_and_relationship(self): result = TraversableGraph(alice, alice_knows_bob, bob) + carol_dislikes_bob assert result == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
def test_can_concatenate_path_and_path(self): result = TraversableGraph(alice, alice_knows_bob, bob) + TraversableGraph( bob, carol_dislikes_bob, carol) assert result == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
def test_can_concatenate_reversed_relationship_and_reversed_relationship( self): bob_knows_alice = Relationship(bob, "KNOWS", alice) result = bob_knows_alice + carol_dislikes_bob assert result == TraversableGraph(alice, bob_knows_alice, bob, carol_dislikes_bob, carol)
def test_can_concatenate_path_and_node(self): result = TraversableGraph(alice, alice_knows_bob, bob) + bob assert result == TraversableGraph(alice, alice_knows_bob, bob)
def test_can_concatenate_relationship_and_node(self): bob_knows_alice = Relationship(bob, "KNOWS", alice) result = bob_knows_alice + bob assert result == TraversableGraph(alice, bob_knows_alice, bob)
def test_can_concatenate_reversed_relationship_and_node(self): result = alice_knows_bob + bob assert result == TraversableGraph(alice, alice_knows_bob, bob)
def test_can_concatenate_node_and_path(self): path = TraversableGraph(alice, alice_knows_bob, bob) result = alice + path assert result == path
def test_can_concatenate_node_and_reversed_path(self): result = alice + TraversableGraph(bob, alice_knows_bob, alice) assert result == TraversableGraph(alice, alice_knows_bob, bob)
def test_can_concatenate_node_and_node(self): result = alice + alice assert result == TraversableGraph(alice)
def test_slicing(self): sequence = (alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) graph = TraversableGraph(*sequence) assert graph[0] == alice_knows_bob assert graph[1] == carol_dislikes_bob assert graph[2] == carol_married_to_dave assert graph[3] == dave_works_for_dave assert graph[0:0] == TraversableGraph(alice) assert graph[0:1] == TraversableGraph(alice, alice_knows_bob, bob) assert graph[0:2] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert graph[0:3] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[0:4] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[0:5] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[0:] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[:1] == TraversableGraph(alice, alice_knows_bob, bob) assert graph[1:1] == TraversableGraph(bob) assert graph[1:2] == TraversableGraph(bob, carol_dislikes_bob, carol) assert graph[1:3] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[1:4] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:5] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[:2] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert graph[2:2] == TraversableGraph(carol) assert graph[2:3] == TraversableGraph(carol, carol_married_to_dave, dave) assert graph[2:4] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[2:5] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[2:] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:-1] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[-3:-1] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave)
def test_inequality(self): other_graph = TraversableGraph(alice, alice_likes_carol, carol, carol_dislikes_bob, bob) assert self.graph != other_graph assert hash(self.graph) != hash(other_graph)
def test_equality(self): other_graph = TraversableGraph(*self.sequence) assert self.graph == other_graph assert hash(self.graph) == hash(other_graph)
class TraversableGraphTestCase(TestCase): sequence = (alice, alice_knows_bob, bob, carol_dislikes_bob, carol) graph = TraversableGraph(*sequence) def test_equality(self): other_graph = TraversableGraph(*self.sequence) assert self.graph == other_graph assert hash(self.graph) == hash(other_graph) def test_inequality(self): other_graph = TraversableGraph(alice, alice_likes_carol, carol, carol_dislikes_bob, bob) assert self.graph != other_graph assert hash(self.graph) != hash(other_graph) def test_inequality_with_other_types(self): assert self.graph != "this is not a graph" def test_iteration(self): assert tuple(iter(self.graph)) == (alice_knows_bob, carol_dislikes_bob) def test_slicing(self): sequence = (alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) graph = TraversableGraph(*sequence) assert graph[0] == alice_knows_bob assert graph[1] == carol_dislikes_bob assert graph[2] == carol_married_to_dave assert graph[3] == dave_works_for_dave assert graph[0:0] == TraversableGraph(alice) assert graph[0:1] == TraversableGraph(alice, alice_knows_bob, bob) assert graph[0:2] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert graph[0:3] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[0:4] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[0:5] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[0:] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[:1] == TraversableGraph(alice, alice_knows_bob, bob) assert graph[1:1] == TraversableGraph(bob) assert graph[1:2] == TraversableGraph(bob, carol_dislikes_bob, carol) assert graph[1:3] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[1:4] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:5] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[:2] == TraversableGraph(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert graph[2:2] == TraversableGraph(carol) assert graph[2:3] == TraversableGraph(carol, carol_married_to_dave, dave) assert graph[2:4] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[2:5] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[2:] == TraversableGraph(carol, carol_married_to_dave, dave, dave_works_for_dave, dave) assert graph[1:-1] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave) assert graph[-3:-1] == TraversableGraph(bob, carol_dislikes_bob, carol, carol_married_to_dave, dave)