Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/unit/utils/test_dict_filter.py
Original file line number Diff line number Diff line change
@@ -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
Loading