From 8965c736831dc9a04d2f34d6516d74b95d9c2756 Mon Sep 17 00:00:00 2001 From: eeshsaxena Date: Wed, 8 Jul 2026 21:26:19 +0530 Subject: [PATCH] tests: cover ensure_list and nested_contains --- tests/unit/utils/test_collections.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit/utils/test_collections.py b/tests/unit/utils/test_collections.py index 8d342d35b3..57dee7120c 100644 --- a/tests/unit/utils/test_collections.py +++ b/tests/unit/utils/test_collections.py @@ -4,7 +4,9 @@ from dvc.utils.collections import ( apply_diff, + ensure_list, merge_dicts, + nested_contains, remove_missing_keys, to_omegaconf, ) @@ -139,3 +141,31 @@ def test_remove_missing_keys(changes, expected): assert removed == expected == params assert params is removed # references should be preserved assert is_serializable(params) + + +@pytest.mark.parametrize( + "item, expected", + [ + (None, []), + ("foo", ["foo"]), + (["foo", "bar"], ["foo", "bar"]), + (("foo", "bar"), ["foo", "bar"]), + ([], []), + ], +) +def test_ensure_list(item, expected): + assert ensure_list(item) == expected + + +@pytest.mark.parametrize( + "dictionary, phrase, expected", + [ + ({"foo": 1, "bar": 2}, "foo", True), + ({"foo": 0}, "foo", False), # falsy value does not count + ({"foo": {"bar": {"baz": 1}}}, "baz", True), # nested match + ({"foo": 1}, "bar", False), # missing key + ({}, "foo", False), + ], +) +def test_nested_contains(dictionary, phrase, expected): + assert nested_contains(dictionary, phrase) is expected