From 9a0d0d3816dc34dfbbbd25204c66ed07b44218e5 Mon Sep 17 00:00:00 2001 From: Jonathan Karlsen Date: Tue, 2 Jan 2024 16:30:10 +0100 Subject: [PATCH] Improve error message on missing root links --- komodo/symlink/sanity_check.py | 7 ++++--- tests/test_sanity_check.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/test_sanity_check.py diff --git a/komodo/symlink/sanity_check.py b/komodo/symlink/sanity_check.py index b24a95826..4898f0805 100644 --- a/komodo/symlink/sanity_check.py +++ b/komodo/symlink/sanity_check.py @@ -82,10 +82,11 @@ def assert_root_nodes(link_dict): inferred_roots = _get_root_nodes(link_dict) if set(input_roots) != inferred_roots: raise AssertionError( - "The roots in the link-tree is not matching " - + "the roots defined in link_roots in dict\n" + "The roots in the link-tree do not match " + + "the roots defined in the root_links dict\n" + f"Roots defined: {set(input_roots)}\n" - + f"Roots expected: {inferred_roots}", + + f"Roots expected: {inferred_roots}\n" + + f"Missing root(s): {str(set(inferred_roots).difference(input_roots))}" ) diff --git a/tests/test_sanity_check.py b/tests/test_sanity_check.py new file mode 100644 index 000000000..d66990a28 --- /dev/null +++ b/tests/test_sanity_check.py @@ -0,0 +1,22 @@ +import pytest + +from komodo.symlink.sanity_check import assert_root_nodes + + +def test_assert_root_nodes_error_message(): + link_dict = { + "links": { + "stable": "2012.01", + "testing": "2012.03", + "missing_root_1": "2011.12", + "missing_root_2": "2011.11", + "missing_root_3": "2011.10", + }, + "root_links": ["stable", "testing"], + } + + with pytest.raises( + AssertionError, + match=r"Missing root\(s\): {(?=.*missing_root_1)(?=.*missing_root_2)(?=.*missing_root_3)", + ): + assert_root_nodes(link_dict)