Skip to content

Commit 7877f11

Browse files
authored
Merge pull request #26 from wwxiao09/Enhancement/dalpy_to_string-for-vertices-24
Enhancement/dalpy to string for vertices 24
2 parents 6320095 + e9c9466 commit 7877f11

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

docs/graphs.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,18 @@ <h2 id="raises">Raises</h2>
190190
</dd>
191191
<dt id="dalpy.graphs.GraphEdgeError"><code class="flex name class">
192192
<span>class <span class="ident">GraphEdgeError</span></span>
193-
<span>(</span><span>source_name, dest_name)</span>
193+
<span>(</span><span>source, dest)</span>
194194
</code></dt>
195195
<dd>
196196
<div class="desc"><p>This class is used by <code><a title="dalpy.graphs.Graph" href="#dalpy.graphs.Graph">Graph</a></code> to raise errors regarding invalid edges.</p>
197197
<p>Initializes a <code><a title="dalpy.graphs.GraphEdgeError" href="#dalpy.graphs.GraphEdgeError">GraphEdgeError</a></code> that will be raised associated with a particular <code><a title="dalpy.graphs.Vertex" href="#dalpy.graphs.Vertex">Vertex</a></code>.</p>
198198
<h2 id="args">Args</h2>
199199
<dl>
200-
<dt><strong><code>source_name</code></strong></dt>
201-
<dd>The string name of the source <code><a title="dalpy.graphs.Vertex" href="#dalpy.graphs.Vertex">Vertex</a></code> of the edge this <code><a title="dalpy.graphs.GraphVertexError" href="#dalpy.graphs.GraphVertexError">GraphVertexError</a></code> is being raised in
200+
<dt><strong><code>source</code></strong></dt>
201+
<dd>The source <code><a title="dalpy.graphs.Vertex" href="#dalpy.graphs.Vertex">Vertex</a></code> of the edge this <code><a title="dalpy.graphs.GraphVertexError" href="#dalpy.graphs.GraphVertexError">GraphVertexError</a></code> is being raised in
202202
association with.</dd>
203-
<dt><strong><code>dest_name</code></strong></dt>
204-
<dd>The string name of the destination <code><a title="dalpy.graphs.Vertex" href="#dalpy.graphs.Vertex">Vertex</a></code> of the edge this <code><a title="dalpy.graphs.GraphVertexError" href="#dalpy.graphs.GraphVertexError">GraphVertexError</a></code> is being raised
203+
<dt><strong><code>dest</code></strong></dt>
204+
<dd>The destination <code><a title="dalpy.graphs.Vertex" href="#dalpy.graphs.Vertex">Vertex</a></code> of the edge this <code><a title="dalpy.graphs.GraphVertexError" href="#dalpy.graphs.GraphVertexError">GraphVertexError</a></code> is being raised
205205
in association with.</dd>
206206
</dl></div>
207207
<h3>Ancestors</h3>

src/dalpy/graphs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ 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:
132-
source_name: The string name of the source `Vertex` of the edge this `GraphVertexError` is being raised in
132+
source: The source `Vertex` of the edge this `GraphVertexError` is being raised in
133133
association with.
134-
dest_name: The string name of the destination `Vertex` of the edge this `GraphVertexError` is being raised
134+
dest: The destination `Vertex` of the edge this `GraphVertexError` is being raised
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)