Mercurial > repos > shellac > sam_consensus_v3
diff env/lib/python3.9/site-packages/networkx/readwrite/tests/test_yaml.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.9/site-packages/networkx/readwrite/tests/test_yaml.py Mon Mar 22 18:12:50 2021 +0000 @@ -0,0 +1,50 @@ +""" + Unit tests for yaml. +""" + +import os +import tempfile +import pytest + +yaml = pytest.importorskip("yaml") + +import networkx as nx +from networkx.testing import assert_edges_equal, assert_nodes_equal + + +class TestYaml: + @classmethod + def setup_class(cls): + cls.build_graphs() + + @classmethod + def build_graphs(cls): + cls.G = nx.Graph(name="test") + e = [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f"), ("a", "f")] + cls.G.add_edges_from(e) + cls.G.add_node("g") + + cls.DG = nx.DiGraph(cls.G) + + cls.MG = nx.MultiGraph() + cls.MG.add_weighted_edges_from([(1, 2, 5), (1, 2, 5), (1, 2, 1), (3, 3, 42)]) + + def assert_equal(self, G, data=False): + (fd, fname) = tempfile.mkstemp() + nx.write_yaml(G, fname) + Gin = nx.read_yaml(fname) + + assert_nodes_equal(list(G), list(Gin)) + assert_edges_equal(G.edges(data=data), Gin.edges(data=data)) + + os.close(fd) + os.unlink(fname) + + def testUndirected(self): + self.assert_equal(self.G, data=False) + + def testDirected(self): + self.assert_equal(self.DG, data=False) + + def testMultiGraph(self): + self.assert_equal(self.MG, data=True)