# HG changeset patch
# User Robert L. Miller
# Date 1299797410 28800
# Node ID c25879359da3984b4d46a9a6cacf7300758a59bc
# Parent 59bc745f1cf1b081c82889fdf101f4e52213a189
#10900 - last four doctests to bring sage/graphs coverage back up to 100%
diff -r 59bc745f1cf1 -r c25879359da3 sage/graphs/base/dense_graph.pyx
--- a/sage/graphs/base/dense_graph.pyx Thu Mar 10 14:00:26 2011 +0800
+++ b/sage/graphs/base/dense_graph.pyx Thu Mar 10 14:50:10 2011 -0800
@@ -213,6 +213,25 @@
bitset_free(self.active_vertices)
def __reduce__(self):
+ """
+ Return a tuple used for pickling this graph.
+
+ TESTS::
+
+ sage: from sage.graphs.base.dense_graph import DenseGraph
+ sage: D = DenseGraph(nverts = 10, extra_vertices = 10)
+ sage: D.add_arc(0,1)
+ sage: D.has_arc(0,1)
+ 1
+ sage: D.has_arc(1,2)
+ 0
+ sage: LD = loads(dumps(D))
+ sage: LD.has_arc(0,1)
+ 1
+ sage: LD.has_arc(1,2)
+ 0
+
+ """
from sage.graphs.all import DiGraph
D = DiGraph(implementation='c_graph', sparse=False)
D._backend._cg = self
diff -r 59bc745f1cf1 -r c25879359da3 sage/graphs/base/graph_backends.py
--- a/sage/graphs/base/graph_backends.py Thu Mar 10 14:00:26 2011 +0800
+++ b/sage/graphs/base/graph_backends.py Thu Mar 10 14:50:10 2011 -0800
@@ -473,8 +473,12 @@
"""
Class for unpickling old networkx.XGraph formats
- DOCTEST:
- sage: import sage.graphs.base.graph_backends
+ DOCTEST::
+
+ sage: from sage.graphs.base.graph_backends import NetworkXGraphDeprecated as NXGD
+ sage: X = NXGD()
+ doctest:...
+
"""
def __init__(self):
@@ -490,13 +494,13 @@
"""
import warnings
from sage.misc.misc import deprecation
- warnings.warn("Your graph object is saved in an old format since networkx\
- was updated to 1.0.1. You can re-save your graph by typing\
- graph.save(filename) to make this warning go away.",
- DeprecationWarning, stacklevel=2)
- deprecation("Your graph object is saved in an old format since networkx\
- was updated to 1.0.1. You can re-save your graph by typing\
- graph.save(filename) to make this warning go away.")
+ warnings.warn("Your graph object is saved in an old format since networkx "+
+ "was updated to 1.0.1. You can re-save your graph by typing "+
+ "graph.save(filename) to make this warning go away.",
+ DeprecationWarning, stacklevel=2)
+ deprecation("Your graph object is saved in an old format since networkx "+
+ "was updated to 1.0.1. You can re-save your graph by typing "+
+ "graph.save(filename) to make this warning go away.")
def mutate(self):
"""
@@ -506,6 +510,20 @@
- The networkx.Graph or networkx.MultiGraph corresponding to the
unpickled data.
+
+ EXAMPLES::
+
+ sage: from sage.graphs.base.graph_backends import NetworkXGraphDeprecated as NXGD
+ sage: X = NXGD()
+ doctest:...
+ sage: X.adj = {1:{2:7}, 2:{1:7}, 3:{2:[4,5,6,7]}, 2:{3:[4,5,6,7]}}
+ sage: X.multiedges = True
+ sage: G = X.mutate()
+ sage: G.edges()
+ [(1, 2), (2, 3)]
+ sage: G.edges(data=True)
+ [(1, 2, {'weight': 7}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})]
+
"""
import networkx
new_adj = {}
@@ -519,7 +537,7 @@
for weight in weights:
new_adj[node1][node2][weight] = {}
except TypeError:
- new_adj[node1][node2]['weight'] = weight
+ new_adj[node1][node2]['weight'] = weights
if self.multiedges:
G = networkx.MultiGraph(new_adj)
@@ -549,13 +567,13 @@
"""
import warnings
from sage.misc.misc import deprecation
- warnings.warn("Your digraph object is saved in an old format since networkx\
- was updated to 1.0.1. You can re-save your digraph by typing\
- digraph.save(filename) to make this warning go away.",
- DeprecationWarning, stacklevel=2)
- deprecation("Your digraph object is saved in an old format since networkx\
- was updated to 1.0.1. You can re-save your digraph by typing\
- digraph.save(filename) to make this warning go away.")
+ warnings.warn("Your digraph object is saved in an old format since networkx "+
+ "was updated to 1.0.1. You can re-save your digraph by typing "+
+ "digraph.save(filename) to make this warning go away.",
+ DeprecationWarning, stacklevel=2)
+ deprecation("Your digraph object is saved in an old format since networkx "+
+ "was updated to 1.0.1. You can re-save your digraph by typing "+
+ "digraph.save(filename) to make this warning go away.")
def mutate(self):
"""
@@ -565,6 +583,20 @@
- The networkx.DiGraph or networkx.MultiDiGraph corresponding to the
unpickled data.
+
+ EXAMPLES::
+
+ sage: from sage.graphs.base.graph_backends import NetworkXDiGraphDeprecated as NXDGD
+ sage: X = NXDGD()
+ doctest:...
+ sage: X.adj = {1:{2:7}, 2:{1:[7,8], 3:[4,5,6,7]}}
+ sage: X.multiedges = True
+ sage: G = X.mutate()
+ sage: G.edges()
+ [(1, 2), (2, 1), (2, 3)]
+ sage: G.edges(data=True)
+ [(1, 2, {'weight': 7}), (2, 1, {8: {}, 7: {}}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})]
+
"""
import networkx
new_adj = {}
@@ -578,7 +610,7 @@
for weight in weights:
new_adj[node1][node2][weight] = {}
except TypeError:
- new_adj[node1][node2]['weight'] = weight
+ new_adj[node1][node2]['weight'] = weights
if self.multiedges:
G = networkx.MultiDiGraph(new_adj)
diff -r 59bc745f1cf1 -r c25879359da3 sage/graphs/base/sparse_graph.pyx
--- a/sage/graphs/base/sparse_graph.pyx Thu Mar 10 14:00:26 2011 +0800
+++ b/sage/graphs/base/sparse_graph.pyx Thu Mar 10 14:50:10 2011 -0800
@@ -355,6 +355,25 @@
bitset_free(self.active_vertices)
def __reduce__(self):
+ """
+ Return a tuple used for pickling this graph.
+
+ TESTS::
+
+ sage: from sage.graphs.base.sparse_graph import SparseGraph
+ sage: S = SparseGraph(nverts = 10, expected_degree = 3, extra_vertices = 10)
+ sage: S.add_arc(0,1)
+ sage: S.all_arcs(0,1)
+ [0]
+ sage: S.all_arcs(1,2)
+ []
+ sage: LS = loads(dumps(S))
+ sage: LS.all_arcs(0,1)
+ [0]
+ sage: LS.all_arcs(1,2)
+ []
+
+ """
from sage.graphs.all import DiGraph
D = DiGraph(implementation='c_graph', sparse=True)
D._backend._cg = self