From c581f31bc9465e0a6b9966ec0604bbd01131bf1a Mon Sep 17 00:00:00 2001 From: eeshsaxena Date: Mon, 6 Jul 2026 10:24:09 +0530 Subject: [PATCH] tests: add unit tests for dict_filter --- tests/unit/utils/test_dict_filter.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/unit/utils/test_dict_filter.py diff --git a/tests/unit/utils/test_dict_filter.py b/tests/unit/utils/test_dict_filter.py new file mode 100644 index 0000000000..1e36d9414d --- /dev/null +++ b/tests/unit/utils/test_dict_filter.py @@ -0,0 +1,30 @@ +from dvc.utils import dict_filter + + +def test_flat_exclusion(): + assert dict_filter({"a": 1, "b": 2}, exclude=["b"]) == {"a": 1} + + +def test_multiple_excludes(): + assert dict_filter({"a": 1, "b": 2, "c": 3}, exclude=["a", "c"]) == {"b": 2} + + +def test_nested_key_removed_recursively(): + assert dict_filter({"a": {"b": 2, "c": 3}}, exclude=["b"]) == {"a": {"c": 3}} + + +def test_excluded_key_removes_its_subtree(): + assert dict_filter({"a": 1, "b": {"x": 1}}, exclude=["b"]) == {"a": 1} + + +def test_list_of_dicts_is_filtered_elementwise(): + result = dict_filter([{"b": 1, "a": 2}, {"a": 3}], exclude=["b"]) + assert result == [{"a": 2}, {"a": 3}] + + +def test_no_exclude_returns_input_unchanged(): + assert dict_filter({"a": 1}) == {"a": 1} + + +def test_scalar_is_passed_through(): + assert dict_filter(5, exclude=["b"]) == 5