|
6 | 6 | from typing import Any |
7 | 7 |
|
8 | 8 | import pytest |
| 9 | +from common_library.dict_tools import assert_equal_ignoring_none |
9 | 10 | from common_library.dict_tools import ( |
10 | 11 | copy_from_dict, |
11 | 12 | get_from_dict, |
@@ -160,3 +161,31 @@ def test_copy_from_dict(data: dict[str, Any]): |
160 | 161 | assert selected_data["Status"]["State"] == data["Status"]["State"] |
161 | 162 | assert "Message" not in selected_data["Status"]["State"] |
162 | 163 | assert "running" in data["Status"]["State"] |
| 164 | + |
| 165 | + |
| 166 | +@pytest.mark.parametrize( |
| 167 | + "expected, actual", |
| 168 | + [ |
| 169 | + ({"a": 1, "b": 2}, {"a": 1, "b": 2, "c": 3}), |
| 170 | + ({"a": 1, "b": None}, {"a": 1, "b": 42}), |
| 171 | + ({"a": {"x": 10, "y": None}}, {"a": {"x": 10, "y": 99}}), |
| 172 | + ({"a": {"x": 10, "y": 20}}, {"a": {"x": 10, "y": 20, "z": 30}}), |
| 173 | + ({}, {"foo": "bar"}), |
| 174 | + ], |
| 175 | +) |
| 176 | +def test_assert_equal_ignoring_none_passes(expected, actual): |
| 177 | + assert_equal_ignoring_none(expected, actual) |
| 178 | + |
| 179 | +@pytest.mark.parametrize( |
| 180 | + "expected, actual, error_msg", |
| 181 | + [ |
| 182 | + ({"a": 1, "b": 2}, {"a": 1}, "Missing key b"), |
| 183 | + ({"a": 1, "b": 2}, {"a": 1, "b": 3}, "Mismatch in b: 3 != 2"), |
| 184 | + ({"a": {"x": 10, "y": 20}}, {"a": {"x": 10, "y": 99}}, "Mismatch in y: 99 != 20"), |
| 185 | + ({"a": {"x": 10}}, {"a": {}}, "Missing key x"), |
| 186 | + ], |
| 187 | +) |
| 188 | +def test_assert_equal_ignoring_none_fails(expected, actual, error_msg): |
| 189 | + with pytest.raises(AssertionError) as exc_info: |
| 190 | + assert_equal_ignoring_none(expected, actual) |
| 191 | + assert error_msg in str(exc_info.value) |
0 commit comments