From db5bedc618d7ddf46e71505f864c1bae00f48a9f Mon Sep 17 00:00:00 2001 From: abhamra Date: Wed, 4 Oct 2023 13:01:42 -0400 Subject: [PATCH 01/13] First pass at testing infrastructure + graph.rs file changes --- src/graph.rs | 27 +++++++++++++ tests/rustworkx_tests/digraph/test_clear.py | 41 ++++++++++++++++++++ tests/rustworkx_tests/graph/test_clear.py | 43 +++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 tests/rustworkx_tests/digraph/test_clear.py create mode 100644 tests/rustworkx_tests/graph/test_clear.py diff --git a/src/graph.rs b/src/graph.rs index 1d97404c5..d87b801c7 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -368,6 +368,33 @@ impl PyGraph { false } + /// Remove all nodes and edges + #[pyo3(text_signature = "(self)")] + pub fn clear(&mut self) { + self.graph.node_count = 0; + self.graph.edge_count = 0; + self.graph.free_node = NodeIndex::end(); + self.graph.free_edge = EdgeIndex::end(); + self.graph.g.clear(); + } + + /// Remove all edges + #[pyo3(text_signature = "(self)")] + pub fn clear_edges(&mut self) { + self.graph.edge_count = 0; + self.graph.free_edge = EdgeIndex::end(); + self.graph.g.edges.clear(); + // clear edges without touching underlying free list + for node in &mut self.graph.g.nodes { + if node.weight.is_some() { + node.next = [EdgeIndex::end(), EdgeIndex::end()]; + } + } + } + + // TODO: Idea -> Basically change num_nodes function to return + // self.graph.node_count (without function parens) and see what happens + /// Return the number of nodes in the graph #[pyo3(text_signature = "(self)")] pub fn num_nodes(&self) -> usize { diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py new file mode 100644 index 000000000..4dad15f7e --- /dev/null +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -0,0 +1,41 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +import rustworkx + + +class TestClear(unittest.TestCase): + def test_clear(self): + dag = rustworkx.PyDAG() + node_a = dag.add_node("a") + node_b = dag.add_child(node_a, "b", {"a": 1}) + node_c = dag.add_child(node_a, "c", {"a": 2}) + dag.clear() # clear nodes and edges + self.assertEqual(dag.num_nodes(), 0) + self.assertEqual(dag.num_edges(), 0) + self.assertEqual(dag.nodes(), []) + self.assertEqual(dag.edges(), []) + + + def test_clear_edges(self): + dag = rustworkx.PyDAG() + node_a = dag.add_node("a") + node_b = dag.add_child(node_a, "b", {"a": 1}) + node_c = dag.add_child(node_a, "c", {"a": 2}) + res = dag.adj_direction(node_a, False) + self.assertEqual(graph.num_nodes(), 3) + self.assertEqual(graph.num_edges(), 0) + self.assertEqual(graph.nodes(), ["a", "b", "c"]) + self.assertEqual(graph.edges(), []) + diff --git a/tests/rustworkx_tests/graph/test_clear.py b/tests/rustworkx_tests/graph/test_clear.py new file mode 100644 index 000000000..f0ba541d6 --- /dev/null +++ b/tests/rustworkx_tests/graph/test_clear.py @@ -0,0 +1,43 @@ +# Licensed under the Apache License, Version 3.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +import rustworkx + + +class TestClear(unittest.TestCase): + def test_clear(self): + graph = rustworkx.PyGraph() + node_a = graph.add_node("a") + node_b = graph.add_node("b") + graph.add_edge(node_a, node_b, {"a": 1}) + node_c = graph.add_node("c") + graph.add_edge(node_a, node_c, {"a": 2}) + graph.clear() + self.assertEqual(graph.num_nodes(), 0) + self.assertEqual(graph.num_edges(), 0) + self.assertEqual(graph.nodes(), []) + self.assertEqual(graph.edges(), []) + + def test_clear_edges(self): + graph = rustworkx.PyGraph() + node_a = graph.add_node("a") + node_b = graph.add_node("b") + graph.add_edge(node_a, node_b, {"e1", 1}) + node_c = graph.add_node("c") + graph.add_edge(node_a, node_c, {"e2", 2}) + graph.clear_edges() + self.assertEqual(graph.num_edges(), 0) + self.assertEqual(graph.edges(), []) + self.assertEqual(graph.num_nodes(), 3) + self.assertEqual(graph.nodes(), ["a", "b", "c"]) From 080c7507c7e740fe86a579ebb94b90bf3466ca8b Mon Sep 17 00:00:00 2001 From: abhamra Date: Wed, 4 Oct 2023 15:27:50 -0400 Subject: [PATCH 02/13] Fixed clear, clear_edges for graph.rs and digraph.rs, added tests, added documentation --- ...ear_edges-for-graphs-041b166aa541639c.yaml | 15 ++++++++++++++ src/digraph.rs | 13 ++++++++++++ src/graph.rs | 20 +++---------------- tests/rustworkx_tests/digraph/test_clear.py | 10 +++++----- 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml diff --git a/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml b/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml new file mode 100644 index 000000000..a84786349 --- /dev/null +++ b/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml @@ -0,0 +1,15 @@ +--- +prelude: > + This is a commit to add the clear and clear_edges functions from StableGraph + to PyGraph and PyDAG. + +features: + - | + Added a new function, :func:`clear` that clears all nodes and edges + from the :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` object and + sets the `node_removed` flag to `true`. + + - | + Added a new function, :func:`clear_edges` that clears all edges from the + :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` object. Note + that all nodes remain unchanged. diff --git a/src/digraph.rs b/src/digraph.rs index 0fe27c4c3..604e8fbfd 100644 --- a/src/digraph.rs +++ b/src/digraph.rs @@ -492,6 +492,19 @@ impl PyDiGraph { } false } + + /// Clear all nodes and edges + #[pyo3(text_signature = "(self)")] + pub fn clear(&mut self) { + self.graph.clear(); + self.node_removed = true; + } + + #[pyo3(text_signature = "(self)")] + pub fn clear_edges(&mut self) { + self.graph.clear_edges(); + } + /// Return the number of nodes in the graph #[pyo3(text_signature = "(self)")] pub fn num_nodes(&self) -> usize { diff --git a/src/graph.rs b/src/graph.rs index d87b801c7..ae8b7c271 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -371,30 +371,16 @@ impl PyGraph { /// Remove all nodes and edges #[pyo3(text_signature = "(self)")] pub fn clear(&mut self) { - self.graph.node_count = 0; - self.graph.edge_count = 0; - self.graph.free_node = NodeIndex::end(); - self.graph.free_edge = EdgeIndex::end(); - self.graph.g.clear(); + self.graph.clear(); + self.node_removed = true; } /// Remove all edges #[pyo3(text_signature = "(self)")] pub fn clear_edges(&mut self) { - self.graph.edge_count = 0; - self.graph.free_edge = EdgeIndex::end(); - self.graph.g.edges.clear(); - // clear edges without touching underlying free list - for node in &mut self.graph.g.nodes { - if node.weight.is_some() { - node.next = [EdgeIndex::end(), EdgeIndex::end()]; - } - } + self.graph.clear_edges(); } - // TODO: Idea -> Basically change num_nodes function to return - // self.graph.node_count (without function parens) and see what happens - /// Return the number of nodes in the graph #[pyo3(text_signature = "(self)")] pub fn num_nodes(&self) -> usize { diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 4dad15f7e..aa8217588 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -33,9 +33,9 @@ def test_clear_edges(self): node_a = dag.add_node("a") node_b = dag.add_child(node_a, "b", {"a": 1}) node_c = dag.add_child(node_a, "c", {"a": 2}) - res = dag.adj_direction(node_a, False) - self.assertEqual(graph.num_nodes(), 3) - self.assertEqual(graph.num_edges(), 0) - self.assertEqual(graph.nodes(), ["a", "b", "c"]) - self.assertEqual(graph.edges(), []) + dag.clear_edges(); + self.assertEqual(dag.num_nodes(), 3) + self.assertEqual(dag.num_edges(), 0) + self.assertEqual(dag.nodes(), ["a", "b", "c"]) + self.assertEqual(dag.edges(), []) From e060bd71291fe60a71ba773830d0695829a73fff Mon Sep 17 00:00:00 2001 From: abhamra Date: Wed, 4 Oct 2023 15:35:46 -0400 Subject: [PATCH 03/13] fix for docstring for clear_edges in digraph --- src/digraph.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/digraph.rs b/src/digraph.rs index 604e8fbfd..bf5395084 100644 --- a/src/digraph.rs +++ b/src/digraph.rs @@ -500,6 +500,7 @@ impl PyDiGraph { self.node_removed = true; } + /// Clears all edges, leaves nodes intact #[pyo3(text_signature = "(self)")] pub fn clear_edges(&mut self) { self.graph.clear_edges(); From 8441cb0abe66a30543b420159bac34e3434b7112 Mon Sep 17 00:00:00 2001 From: abhamra Date: Wed, 4 Oct 2023 15:39:23 -0400 Subject: [PATCH 04/13] docstring fix for graph.rs --- src/graph.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index ae8b7c271..58d463813 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -368,14 +368,14 @@ impl PyGraph { false } - /// Remove all nodes and edges + /// Clears all nodes and edges #[pyo3(text_signature = "(self)")] pub fn clear(&mut self) { self.graph.clear(); self.node_removed = true; } - /// Remove all edges + /// Clears all edges, leaves nodes intact #[pyo3(text_signature = "(self)")] pub fn clear_edges(&mut self) { self.graph.clear_edges(); From a6e5ae5d91f518a394aa6d656d6d408ffe35681e Mon Sep 17 00:00:00 2001 From: abhamra Date: Wed, 4 Oct 2023 18:28:04 -0400 Subject: [PATCH 05/13] Minor fixes for codestyle for python lint --- tests/rustworkx_tests/digraph/test_clear.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index aa8217588..48620abd5 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -21,7 +21,7 @@ def test_clear(self): node_a = dag.add_node("a") node_b = dag.add_child(node_a, "b", {"a": 1}) node_c = dag.add_child(node_a, "c", {"a": 2}) - dag.clear() # clear nodes and edges + dag.clear() self.assertEqual(dag.num_nodes(), 0) self.assertEqual(dag.num_edges(), 0) self.assertEqual(dag.nodes(), []) @@ -33,7 +33,7 @@ def test_clear_edges(self): node_a = dag.add_node("a") node_b = dag.add_child(node_a, "b", {"a": 1}) node_c = dag.add_child(node_a, "c", {"a": 2}) - dag.clear_edges(); + dag.clear_edges() self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 0) self.assertEqual(dag.nodes(), ["a", "b", "c"]) From 292f8ff901b38eb7a85ac88a3a511332f5b4e1b5 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 11:29:29 -0400 Subject: [PATCH 06/13] Added new tests to show reuse after using clear, clear_edges, updated docs --- ...ear_edges-for-graphs-041b166aa541639c.yaml | 13 +++---- tests/rustworkx_tests/digraph/test_clear.py | 29 +++++++++++++++- tests/rustworkx_tests/graph/test_clear.py | 34 +++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml b/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml index a84786349..ef6931f54 100644 --- a/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml +++ b/releasenotes/notes/add-clear-and-clear_edges-for-graphs-041b166aa541639c.yaml @@ -1,15 +1,10 @@ --- -prelude: > - This is a commit to add the clear and clear_edges functions from StableGraph - to PyGraph and PyDAG. - features: - | Added a new function, :func:`clear` that clears all nodes and edges - from the :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` object and - sets the `node_removed` flag to `true`. + from a :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` - | - Added a new function, :func:`clear_edges` that clears all edges from the - :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` object. Note - that all nodes remain unchanged. + Added a new function, :func:`clear_edges` that clears all edges for + :class:`rustworkx.PyGraph` or :class:`rustworkx.PyDiGraph` without + modifying nodes diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 48620abd5..411b26cc0 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -26,7 +26,20 @@ def test_clear(self): self.assertEqual(dag.num_edges(), 0) self.assertEqual(dag.nodes(), []) self.assertEqual(dag.edges(), []) - + + def test_clear_reuse(self): + dag = rustworkx.PyDAG() + node_a = dag.add_node("a") + node_b = dag.add_child(node_a, "b", {"a": 1}) + node_c = dag.add_child(node_a, "c", {"a": 2}) + dag.clear() + node_a = dag.add_node("a") + node_b = dag.add_child(node_a, "b", {"a": 1}) + node_c = dag.add_child(node_a, "c", {"a": 2}) + self.assertEqual(dag.num_nodes(), 3) + self.assertEqual(dag.num_edges(), 2) + self.assertEqual(dag.nodes(), ["a", "b", "c"]) + self.assertEqual(dag.edges(), [{"a": 1}, {"a": 2}]) def test_clear_edges(self): dag = rustworkx.PyDAG() @@ -39,3 +52,17 @@ def test_clear_edges(self): self.assertEqual(dag.nodes(), ["a", "b", "c"]) self.assertEqual(dag.edges(), []) + def test_clear_edges_reuse(self): + dag = rustworkx.PyDAG() + node_a = dag.add_node("a") + node_b = dag.add_child(node_a, "b", {"a": 1}) + node_c = dag.add_child(node_a, "c", {"a": 2}) + dag.clear_edges() + dag.add_edge(node_a, node_b, {"a": 1}) + dag.add_edge(node_a, node_c, {"a": 2}) + self.assertEqual(dag.num_nodes(), 3) + self.assertEqual(dag.num_edges(), 2) + self.assertEqual(dag.nodes(), ["a", "b", "c"]) + self.assertEqual(dag.edges(), [{"a": 1}, {"a": 2}]) + + diff --git a/tests/rustworkx_tests/graph/test_clear.py b/tests/rustworkx_tests/graph/test_clear.py index f0ba541d6..d113fea8c 100644 --- a/tests/rustworkx_tests/graph/test_clear.py +++ b/tests/rustworkx_tests/graph/test_clear.py @@ -29,6 +29,25 @@ def test_clear(self): self.assertEqual(graph.nodes(), []) self.assertEqual(graph.edges(), []) + def test_clear_reuse(self): + graph = rustworkx.PyGraph() + node_a = graph.add_node("a") + node_b = graph.add_node("b") + graph.add_edge(node_a, node_b, {"a": 1}) + node_c = graph.add_node("c") + graph.add_edge(node_a, node_c, {"a": 2}) + graph.clear() + node_a = graph.add_node("a") + node_b = graph.add_node("b") + graph.add_edge(node_a, node_b, {"a": 1}) + node_c = graph.add_node("c") + graph.add_edge(node_a, node_c, {"a": 2}) + self.assertEqual(graph.num_nodes(), 3) + self.assertEqual(graph.num_edges(), 2) + self.assertEqual(graph.nodes(), ["a", "b", "c"]) + self.assertEqual(graph.edges(), [{"a": 1}, {"a": 2}]) + + def test_clear_edges(self): graph = rustworkx.PyGraph() node_a = graph.add_node("a") @@ -41,3 +60,18 @@ def test_clear_edges(self): self.assertEqual(graph.edges(), []) self.assertEqual(graph.num_nodes(), 3) self.assertEqual(graph.nodes(), ["a", "b", "c"]) + + def test_clear_edges_reuse(self): + graph = rustworkx.PyGraph() + node_a = graph.add_node("a") + node_b = graph.add_node("b") + graph.add_edge(node_a, node_b, {"e1", 1}) + node_c = graph.add_node("c") + graph.add_edge(node_a, node_c, {"e2", 2}) + graph.clear_edges() + graph.add_edge(node_a, node_b, {"e1", 1}) + graph.add_edge(node_a, node_c, {"e2", 2}) + self.assertEqual(graph.num_nodes(), 3) + self.assertEqual(graph.num_edges(), 2) + self.assertEqual(graph.nodes(), ["a", "b", "c"]) + self.assertEqual(graph.edges(), [{"e1", 1}, {"e2", 2}]) From 8331ee214effc3946a43851e187b2ad8d25eb83e Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 16:32:21 -0400 Subject: [PATCH 07/13] Adding fix for build error with prev commit --- rustworkx-core/src/centrality.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustworkx-core/src/centrality.rs b/rustworkx-core/src/centrality.rs index c099c6304..59d0ca1dc 100644 --- a/rustworkx-core/src/centrality.rs +++ b/rustworkx-core/src/centrality.rs @@ -738,7 +738,7 @@ where { let alpha: f64 = alpha.unwrap_or(0.1); - let mut beta: HashMap = beta_map.unwrap_or_else(HashMap::new); + let mut beta: HashMap = beta_map.unwrap_or_default(HashMap::new); if beta.is_empty() { // beta_map was none From 58a2fce9d8e932117d8b106aa4768fb777492bd0 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 19:31:40 -0400 Subject: [PATCH 08/13] fixes from black codestyle format --- tests/rustworkx_tests/digraph/test_clear.py | 4 +--- tests/rustworkx_tests/graph/test_clear.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 411b26cc0..5c5e01b5b 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -26,7 +26,7 @@ def test_clear(self): self.assertEqual(dag.num_edges(), 0) self.assertEqual(dag.nodes(), []) self.assertEqual(dag.edges(), []) - + def test_clear_reuse(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") @@ -64,5 +64,3 @@ def test_clear_edges_reuse(self): self.assertEqual(dag.num_edges(), 2) self.assertEqual(dag.nodes(), ["a", "b", "c"]) self.assertEqual(dag.edges(), [{"a": 1}, {"a": 2}]) - - diff --git a/tests/rustworkx_tests/graph/test_clear.py b/tests/rustworkx_tests/graph/test_clear.py index d113fea8c..3672564fb 100644 --- a/tests/rustworkx_tests/graph/test_clear.py +++ b/tests/rustworkx_tests/graph/test_clear.py @@ -47,7 +47,6 @@ def test_clear_reuse(self): self.assertEqual(graph.nodes(), ["a", "b", "c"]) self.assertEqual(graph.edges(), [{"a": 1}, {"a": 2}]) - def test_clear_edges(self): graph = rustworkx.PyGraph() node_a = graph.add_node("a") From eee64b28378e5c7081dc98a7a4f84926818eb28f Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 20:27:49 -0400 Subject: [PATCH 09/13] fixed flake8 F841 - variable assigned to but never used errors --- tests/rustworkx_tests/digraph/test_clear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 5c5e01b5b..961cf3873 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -19,8 +19,8 @@ class TestClear(unittest.TestCase): def test_clear(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) - node_c = dag.add_child(node_a, "c", {"a": 2}) + _node_b = dag.add_child(node_a, "b", {"a": 1}) + _node_c = dag.add_child(node_a, "c", {"a": 2}) dag.clear() self.assertEqual(dag.num_nodes(), 0) self.assertEqual(dag.num_edges(), 0) @@ -44,8 +44,8 @@ def test_clear_reuse(self): def test_clear_edges(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) - node_c = dag.add_child(node_a, "c", {"a": 2}) + _node_b = dag.add_child(node_a, "b", {"a": 1}) + _node_c = dag.add_child(node_a, "c", {"a": 2}) dag.clear_edges() self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 0) From 7c35ee7c47c123d2432c539a82de8311c789abb6 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 20:34:32 -0400 Subject: [PATCH 10/13] retry at fix for F841 error, used noqa --- tests/rustworkx_tests/digraph/test_clear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 961cf3873..8019911d2 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -19,8 +19,8 @@ class TestClear(unittest.TestCase): def test_clear(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - _node_b = dag.add_child(node_a, "b", {"a": 1}) - _node_c = dag.add_child(node_a, "c", {"a": 2}) + node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 + node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 dag.clear() self.assertEqual(dag.num_nodes(), 0) self.assertEqual(dag.num_edges(), 0) @@ -44,8 +44,8 @@ def test_clear_reuse(self): def test_clear_edges(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - _node_b = dag.add_child(node_a, "b", {"a": 1}) - _node_c = dag.add_child(node_a, "c", {"a": 2}) + node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 + node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 dag.clear_edges() self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 0) From e6b807a4fbae9b726e4b59eae85e24d1a0d56b94 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 20:41:41 -0400 Subject: [PATCH 11/13] fixes for black --- tests/rustworkx_tests/digraph/test_clear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 8019911d2..351512d98 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -19,8 +19,8 @@ class TestClear(unittest.TestCase): def test_clear(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 - node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 + node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 + node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 dag.clear() self.assertEqual(dag.num_nodes(), 0) self.assertEqual(dag.num_edges(), 0) @@ -44,8 +44,8 @@ def test_clear_reuse(self): def test_clear_edges(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 - node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 + node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 + node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 dag.clear_edges() self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 0) From 3d3ff133a2f8c19e223ada7667f9ad81a3e3ee88 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 20:50:55 -0400 Subject: [PATCH 12/13] fixes for CICD, F841 local variable unused error --- tests/rustworkx_tests/digraph/test_clear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 351512d98..3057dec2e 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -19,8 +19,8 @@ class TestClear(unittest.TestCase): def test_clear(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 - node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 + dag.add_child(node_a, "b", {"a": 1}) + dag.add_child(node_a, "c", {"a": 2}) dag.clear() self.assertEqual(dag.num_nodes(), 0) self.assertEqual(dag.num_edges(), 0) @@ -44,8 +44,8 @@ def test_clear_reuse(self): def test_clear_edges(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) # noqa: F841 - node_c = dag.add_child(node_a, "c", {"a": 2}) # noqa: F841 + dag.add_child(node_a, "b", {"a": 1}) + dag.add_child(node_a, "c", {"a": 2}) dag.clear_edges() self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 0) From 8ca5634ef2eb57cffc7fc7afc066a572d75f2393 Mon Sep 17 00:00:00 2001 From: abhamra Date: Thu, 5 Oct 2023 22:16:43 -0400 Subject: [PATCH 13/13] flake8 fixes --- tests/rustworkx_tests/digraph/test_clear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rustworkx_tests/digraph/test_clear.py b/tests/rustworkx_tests/digraph/test_clear.py index 3057dec2e..043ae43e6 100644 --- a/tests/rustworkx_tests/digraph/test_clear.py +++ b/tests/rustworkx_tests/digraph/test_clear.py @@ -30,12 +30,12 @@ def test_clear(self): def test_clear_reuse(self): dag = rustworkx.PyDAG() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) - node_c = dag.add_child(node_a, "c", {"a": 2}) + dag.add_child(node_a, "b", {"a": 1}) + dag.add_child(node_a, "c", {"a": 2}) dag.clear() node_a = dag.add_node("a") - node_b = dag.add_child(node_a, "b", {"a": 1}) - node_c = dag.add_child(node_a, "c", {"a": 2}) + dag.add_child(node_a, "b", {"a": 1}) + dag.add_child(node_a, "c", {"a": 2}) self.assertEqual(dag.num_nodes(), 3) self.assertEqual(dag.num_edges(), 2) self.assertEqual(dag.nodes(), ["a", "b", "c"])