From df5cadcd0fd157b02620cdcdc98a8471a7ce2ac2 Mon Sep 17 00:00:00 2001 From: Jafar Al-Gharaibeh Date: Sun, 19 Jan 2025 16:44:40 -0600 Subject: [PATCH] fix partial match for non dictionary items currenlty with partial match `[{"foo":"foo"}]` is considered a subset of `[{"foo":"foo"}, {"bar":"bar"}]`. However `[1]` is not considered a subset of `[1,2]`. This fixes the behavior so that partial match rules apply to non dictionary items within a list. Signed-off-by: Jafar Al-Gharaibeh --- munet/mutest/userapi.py | 3 +-- tests/mutest/mutest_matchwait_json.py | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/munet/mutest/userapi.py b/munet/mutest/userapi.py index e367e65..a8100bc 100644 --- a/munet/mutest/userapi.py +++ b/munet/mutest/userapi.py @@ -579,8 +579,7 @@ def _match_command_json( if (new_items := json_diff.get("iterable_item_added")) is not None: new_item_paths = list(new_items.keys()) for path in new_item_paths: - if type(new_items[path]) is dict: - del new_items[path] + del new_items[path] if len(new_items) == 0: del json_diff["iterable_item_added"] diff --git a/tests/mutest/mutest_matchwait_json.py b/tests/mutest/mutest_matchwait_json.py index 519cae1..c7153b8 100644 --- a/tests/mutest/mutest_matchwait_json.py +++ b/tests/mutest/mutest_matchwait_json.py @@ -242,8 +242,7 @@ "r1", f"echo '{json2}'", json1, - "Data in different arrays don't match", - expect_fail=True, + "Data in one array is a subest of another" ) test_step( ret == {'iterable_item_added': {'root[1]': 'bar'}}, @@ -300,8 +299,7 @@ "r1", f"echo '{json4}'", json1, - "Data in different arrays don't match (nested)", - expect_fail=True + "Data in one array is a subest of another" ) test_step( ret == {'iterable_item_added': {"root['level1'][1]['level3'][1]": 'l4'}},