Skip to content

Commit de49955

Browse files
committed
Issue #24 Updated GraphEdgeError to produce a readable output, added test
1 parent 6320095 commit de49955

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/dalpy/graphs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ def __init__(self, vertex_name):
119119
Args:
120120
vertex_name: The string name of the `Vertex` this `GraphVertexError` is being raised in association with.
121121
"""
122-
super().__init__(f'graph does not have vertex with name {vertex_name}')
122+
super().__init__(f'graph does not have vertex with name "{vertex_name}"')
123123

124124

125125
class GraphEdgeError(Exception):
126126
"""This class is used by `Graph` to raise errors regarding invalid edges."""
127127

128-
def __init__(self, source_name, dest_name):
128+
def __init__(self, source, dest):
129129
"""Initializes a `GraphEdgeError` that will be raised associated with a particular `Vertex`.
130130
131131
Args:
@@ -135,7 +135,7 @@ def __init__(self, source_name, dest_name):
135135
in association with.
136136
"""
137137
super().__init__(
138-
f'graph does not have an edge from a vertex with name {source_name} to a vertex with name {dest_name}')
138+
f'graph does not have an edge from a vertex with name "{source.get_name()}" to a vertex with name "{dest.get_name()}"')
139139

140140

141141
class Graph:

tests/graph_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ def test_unweighted_edge(self):
131131
g.add_edge(a, b)
132132
self.assertIsNone(g.weight(a, b))
133133

134+
def test_GraphEdgeError(self):
135+
g = Graph()
136+
a = Vertex('a')
137+
b = Vertex('b')
138+
g.add_vertex(a)
139+
g.add_vertex(b)
140+
try:
141+
g.weight(b, a)
142+
except GraphEdgeError as e:
143+
self.assertEqual(e.args[0], "graph does not have an edge from a vertex with name \"b\" to a vertex with name \"a\"")
144+
145+
134146

135147
if __name__ == '__main__':
136148
unittest.main()

0 commit comments

Comments
 (0)