summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavya Agarwal <82928853+navyagarwal@users.noreply.github.com>2023-03-17 22:32:41 +0530
committerGitHub <noreply@github.com>2023-03-17 10:02:41 -0700
commit6db531a21313019c427103e57b5b67ae314c9976 (patch)
tree7b21e373decfe709cab63f623f20ae662077d86f
parentb17c43c8495f58a6b02abffa1471026a1650ab93 (diff)
downloadnetworkx-6db531a21313019c427103e57b5b67ae314c9976.tar.gz
Improve test coverage for edgelist.py (#6507)
* Add tests for parse_edgelist * Fix to ensure that right TypeError is hit
-rw-r--r--networkx/algorithms/bipartite/tests/test_edgelist.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/networkx/algorithms/bipartite/tests/test_edgelist.py b/networkx/algorithms/bipartite/tests/test_edgelist.py
index 9cf0c438..b388465e 100644
--- a/networkx/algorithms/bipartite/tests/test_edgelist.py
+++ b/networkx/algorithms/bipartite/tests/test_edgelist.py
@@ -190,3 +190,40 @@ class TestEdgelist:
G = nx.path_graph(4)
bytesIO = io.BytesIO()
bipartite.write_edgelist(G, bytesIO)
+
+ def test_parse_edgelist(self):
+ """Tests for conditions specific to
+ parse_edge_list method"""
+
+ # ignore strings of length less than 2
+ lines = ["1 2", "2 3", "3 1", "4", " "]
+ G = bipartite.parse_edgelist(lines, nodetype=int)
+ assert list(G.nodes) == [1, 2, 3]
+
+ # Exception raised when node is not convertible
+ # to specified data type
+ with pytest.raises(TypeError, match=".*Failed to convert nodes"):
+ lines = ["a b", "b c", "c a"]
+ G = bipartite.parse_edgelist(lines, nodetype=int)
+
+ # Exception raised when format of data is not
+ # convertible to dictionary object
+ with pytest.raises(TypeError, match=".*Failed to convert edge data"):
+ lines = ["1 2 3", "2 3 4", "3 1 2"]
+ G = bipartite.parse_edgelist(lines, nodetype=int)
+
+ # Exception raised when edge data and data
+ # keys are not of same length
+ with pytest.raises(IndexError):
+ lines = ["1 2 3 4", "2 3 4"]
+ G = bipartite.parse_edgelist(
+ lines, nodetype=int, data=[("weight", int), ("key", int)]
+ )
+
+ # Exception raised when edge data is not
+ # convertible to specified data type
+ with pytest.raises(TypeError, match=".*Failed to convert key data"):
+ lines = ["1 2 3 a", "2 3 4 b"]
+ G = bipartite.parse_edgelist(
+ lines, nodetype=int, data=[("weight", int), ("key", int)]
+ )