From f74adb94cc1e8439c8076f563ec112466fdd174b Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Tue, 26 Nov 2024 15:53:38 +0100 Subject: [PATCH] CLI: Handle `None` process states in build_call_graph (#6590) The process definition allows a None state but the `build_call_graph` utils function intended for creating a printable output of the call graph does crash in this case. A None state indicates an undefined behavior in the code, but the application should not fail because of the formatting of the output. This commit makes `build_call_graph` handle `None` states. Partial fix for #6585. --- src/aiida/cmdline/utils/ascii_vis.py | 2 +- tests/cmdline/utils/test_ascii_vis.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/cmdline/utils/test_ascii_vis.py diff --git a/src/aiida/cmdline/utils/ascii_vis.py b/src/aiida/cmdline/utils/ascii_vis.py index f42317e7a8..502abf3bcf 100644 --- a/src/aiida/cmdline/utils/ascii_vis.py +++ b/src/aiida/cmdline/utils/ascii_vis.py @@ -29,7 +29,7 @@ def calc_info(node, call_link_label: bool = False) -> str: raise TypeError(f'Unknown type: {type(node)}') process_label = node.process_label - process_state = node.process_state.value.capitalize() + process_state = 'None' if node.process_state is None else node.process_state.value.capitalize() exit_status = node.exit_status if call_link_label and (caller := node.caller): diff --git a/tests/cmdline/utils/test_ascii_vis.py b/tests/cmdline/utils/test_ascii_vis.py new file mode 100644 index 0000000000..9fb6d26423 --- /dev/null +++ b/tests/cmdline/utils/test_ascii_vis.py @@ -0,0 +1,20 @@ +########################################################################### +# Copyright (c), The AiiDA team. All rights reserved. # +# This file is part of the AiiDA code. # +# # +# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # +# For further information on the license, see the LICENSE.txt file # +# For further information please visit http://www.aiida.net # +########################################################################### +"""Tests for the :mod:`aiida.cmdline.utils.ascii_vis` module.""" + +from aiida.orm.nodes.process.process import ProcessNode + + +def test_build_call_graph(): + from aiida.cmdline.utils.ascii_vis import build_call_graph + + node = ProcessNode() + + call_graph = build_call_graph(node) + assert call_graph == 'None None'