summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAric Hagberg <aric.hagberg+github@gmail.com>2016-04-22 09:40:10 -0600
committerAric Hagberg <aric.hagberg+github@gmail.com>2016-04-22 09:40:10 -0600
commit545120b643d7d1bdbe54a02fa3d45d917d140b1b (patch)
tree6cceec382279b5869f1ece5162b6ed347a5de100
parent1e8f38e47ac594b1d31a8fc2d4ec87295de5ddfc (diff)
parent26aceb4e2538d97e2f4ffbc70c17ddc8d34d781d (diff)
downloadnetworkx-545120b643d7d1bdbe54a02fa3d45d917d140b1b.tar.gz
Merge pull request #2100 from dschult/notfound
Remove conflicts from #1894 (Update Exception Classes)
-rw-r--r--networkx/algorithms/simple_paths.py14
-rw-r--r--networkx/algorithms/tests/test_simple_paths.py15
-rw-r--r--networkx/exception.py3
3 files changed, 17 insertions, 15 deletions
diff --git a/networkx/algorithms/simple_paths.py b/networkx/algorithms/simple_paths.py
index 7625662e..f68f3082 100644
--- a/networkx/algorithms/simple_paths.py
+++ b/networkx/algorithms/simple_paths.py
@@ -147,9 +147,9 @@ def all_simple_paths(G, source, target, cutoff=None):
all_shortest_paths, shortest_path
"""
if source not in G:
- raise nx.NetworkXError('source node %s not in graph'%source)
+ raise nx.NodeNotFound('source node %s not in graph'%source)
if target not in G:
- raise nx.NetworkXError('target node %s not in graph'%target)
+ raise nx.NodeNotFound('target node %s not in graph'%target)
if cutoff is None:
cutoff = len(G)-1
if G.is_multigraph():
@@ -286,10 +286,10 @@ def shortest_simple_paths(G, source, target, weight=None):
"""
if source not in G:
- raise nx.NetworkXError('source node %s not in graph' % source)
+ raise nx.NodeNotFound('source node %s not in graph' % source)
if target not in G:
- raise nx.NetworkXError('target node %s not in graph' % target)
+ raise nx.NodeNotFound('target node %s not in graph' % target)
if weight is None:
length_func = len
@@ -365,7 +365,7 @@ def _bidirectional_shortest_path(G, source, target,
"""Return the shortest path between source and target ignoring
nodes and edges in the containers ignore_nodes and ignore_edges.
- This is a custom modification of the standard bidirectional shortest
+ This is a custom modification of the standard bidirectional shortest
path implementation at networkx.algorithms.unweighted
Parameters
@@ -385,7 +385,7 @@ def _bidirectional_shortest_path(G, source, target,
edges to ignore, optional
weight : None
- This function accepts a weight argument for convinience of
+ This function accepts a weight argument for convinience of
shortest_simple_paths function. It will be ignored.
Returns
@@ -524,7 +524,7 @@ def _bidirectional_dijkstra(G, source, target, weight='weight',
"""Dijkstra's algorithm for shortest paths using bidirectional search.
This function returns the shortest path between source and target
- ignoring nodes and edges in the containers ignore_nodes and
+ ignoring nodes and edges in the containers ignore_nodes and
ignore_edges.
This is a custom modification of the standard Dijkstra bidirectional
diff --git a/networkx/algorithms/tests/test_simple_paths.py b/networkx/algorithms/tests/test_simple_paths.py
index 6f4e215a..4b3de57c 100644
--- a/networkx/algorithms/tests/test_simple_paths.py
+++ b/networkx/algorithms/tests/test_simple_paths.py
@@ -140,13 +140,13 @@ def test_cutoff_zero():
paths = nx.all_simple_paths(nx.MultiGraph(G),0,3,cutoff=0)
assert_equal(list(list(p) for p in paths),[])
-@raises(nx.NetworkXError)
+@raises(nx.NodeNotFound)
def test_source_missing():
G = nx.Graph()
nx.add_path(G, [1, 2, 3])
paths = list(nx.all_simple_paths(nx.MultiGraph(G),0,3))
-@raises(nx.NetworkXError)
+@raises(nx.NodeNotFound)
def test_target_missing():
G = nx.Graph()
nx.add_path(G, [1, 2, 3])
@@ -212,14 +212,14 @@ def test_weight_name():
paths = list(nx.shortest_simple_paths(G, 0, 3, weight='foo'))
solution = [[0, 6, 5, 4, 3], [0, 1, 2, 3]]
assert_equal(paths, solution)
-
-@raises(nx.NetworkXError)
+
+@raises(nx.NodeNotFound)
def test_ssp_source_missing():
G = nx.Graph()
nx.add_path(G, [1, 2, 3])
paths = list(nx.shortest_simple_paths(G, 0, 3))
-@raises(nx.NetworkXError)
+@raises(nx.NodeNotFound)
def test_ssp_target_missing():
G = nx.Graph()
nx.add_path(G, [1, 2, 3])
@@ -272,7 +272,7 @@ def test_bidirectional_shortest_path_restricted():
nx.NetworkXNoPath,
_bidirectional_shortest_path,
directed_cycle,
- 0, 3,
+ 0, 3,
ignore_edges=[(1, 2)],
)
@@ -298,7 +298,7 @@ def test_bidirectional_dijksta_restricted():
XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12],
[2, 3, 1], [3, 4, 5],
[4, 5, 1], [5, 0, 10]])
- validate_length_path(XG, 's', 'v', 9,
+ validate_length_path(XG, 's', 'v', 9,
*_bidirectional_dijkstra(XG, 's', 'v'))
validate_length_path(XG, 's', 'v', 10,
*_bidirectional_dijkstra(XG, 's', 'v', ignore_nodes=['u']))
@@ -332,4 +332,3 @@ def test_bidirectional_dijkstra_no_path():
nx.add_path(G, [1, 2, 3])
nx.add_path(G, [4, 5, 6])
path = _bidirectional_dijkstra(G, 1, 6)
-
diff --git a/networkx/exception.py b/networkx/exception.py
index c8e1e2d8..7d088024 100644
--- a/networkx/exception.py
+++ b/networkx/exception.py
@@ -52,3 +52,6 @@ class NetworkXUnbounded(NetworkXAlgorithmError):
class NetworkXNotImplemented(NetworkXException):
"""Exception raised by algorithms not implemented for a type of graph."""
+
+class NodeNotFound(NetworkXException):
+ """Exception raised if requested node is not present in the graph"""