Skip to content

Commit 2ac8943

Browse files
committed
Add delete
1 parent 24ea559 commit 2ac8943

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
## Feature todo
2828

29-
* Delete node
29+
* ~~Delete node~~
3030

3131
## Testing todo
3232

freexgraph/freexgraph.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
23-
23+
from copy import copy
2424
from typing import Optional, Union, Set, List, Any
2525

2626
import networkx as nx
@@ -240,11 +240,10 @@ def remove_node(self, node_id: str) -> None:
240240
"""Remove the provided node and all its successors
241241
:param node_id: node to remove
242242
"""
243-
assert self._graph.has_node(
244-
node_id
245-
), f"{node_id} has to be in the execution graph to be removed"
246-
self._graph.remove_nodes_from(self._graph.successors(node_id))
247-
self._graph.remove_node(node_id)
243+
if self._graph.has_node(node_id):
244+
for n in copy(self._graph.successors(node_id)):
245+
self.remove_node(n)
246+
self._graph.remove_node(node_id)
248247

249248
@property
250249
def root(self) -> FreExNode:

test/basic_freexgraph_test.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_delete_one_node(visitor_test):
281281
execution_graph.add_node(NodeForTest(ida))
282282
execution_graph.add_node(NodeForTest(idb, parents={ida}))
283283
execution_graph.add_node(NodeForTest(idd, parents={idb}))
284-
execution_graph.add_node(NodeForTest(idx, parents={idb}))
284+
execution_graph.add_node(NodeForTest(idx, parents={idb, idd}))
285285
execution_graph.add_node(NodeForTest(idc, parents={idd}))
286286
execution_graph.add_node(NodeForTest(ide, parents={idd, idx}))
287287

@@ -307,7 +307,7 @@ def test_delete_one_node(visitor_test):
307307
assert idx == visitor_test.visited[4]
308308

309309

310-
def test_delete_node_with_childs(valid_complex_graph):
310+
def test_delete_node_with_childs(visitor_test):
311311
#
312312
# ida
313313
# |
@@ -330,9 +330,18 @@ def test_delete_node_with_childs(valid_complex_graph):
330330
execution_graph.add_node(NodeForTest(ida))
331331
execution_graph.add_node(NodeForTest(idb, parents={ida}))
332332
execution_graph.add_node(NodeForTest(idd, parents={idb}))
333-
execution_graph.add_node(NodeForTest(idx, parents={idb}))
333+
execution_graph.add_node(NodeForTest(idx, parents={idb, idd}))
334334
execution_graph.add_node(NodeForTest(idc, parents={idd}))
335335
execution_graph.add_node(NodeForTest(ide, parents={idd, idx}))
336336

337-
# should remove idc and ide
338-
# execution_graph.remove_node(idd)
337+
# should remove idc, ide and idx
338+
execution_graph.remove_node(idd)
339+
340+
visitor_test.visit(execution_graph.root)
341+
342+
assert len(visitor_test.visited) == 2
343+
344+
assert ide not in visitor_test.visited
345+
346+
assert ida == visitor_test.visited[0]
347+
assert idb == visitor_test.visited[1]

0 commit comments

Comments
 (0)