def test_flat_data(self) -> None: data = { "field1": 0.5, "field2": "value2", "field3": 42, } assert flatten(data) == data
def test_not_flat_data(self) -> None: data = { "field1": 4.5, "field2": {"field1": 1, "field2": [2, "elem2"]}, "field3": [3, False, {"field1": "value1", "field2": True}], } assert flatten(data) == { "field1": 4.5, "field2.field1": 1, "field2.field2[0]": 2, "field2.field2[1]": "elem2", "field3[0]": 3, "field3[1]": False, "field3[2].field1": "value1", "field3[2].field2": True, }
def test_empty_data(self) -> None: assert flatten({}) == {}
def test_non_dict_data(self, data: Any) -> None: with pytest.raises(AttributeError): flatten(data)