def test_remove_key_with_none_value(): fixture = { "a": 1, "b": None, "nested": { "ac": 1, "bc": None, "nested": { "a": 1, "b": None } }, "array": [ 1, { "nested": { "ac": 1, "bc": None, "nested": { "a": 1, "b": None } } }, { "normal": 1, "empty_string": "" }, ], "not_set": NULL, } actual_result = remove_key_with_none_value(fixture) expected = { "a": 1, "array": [1, { "nested": { "ac": 1, "nested": { "a": 1 } } }, { "normal": 1 }], "nested": { "ac": 1, "nested": { "a": 1 } }, "not_set": None, } eq_(actual_result, expected)
def options(self): return utils.remove_key_with_none_value(self._option)
def config(self): return remove_key_with_none_value(self._config)
def get_options(self, remove_none=True): if remove_none: return utils.remove_key_with_none_value(self._option) else: return copy.deepcopy(self._option)
def __json__(self): return remove_key_with_none_value(self._config)
def test_remove_key_with_none_value(): fixture = { "a": 1, "b": None, "nested": { "ac": 1, "bc": None, "nested": { "a": 1, "b": None } }, "empty_dict": { "data": [] }, "empty_dict2": { "empty_dict": {} }, "array": [ 1, { "nested": { "ac": 1, "bc": None, "nested": { "a": 1, "b": None } } }, { "normal": 1, "empty_string": "", "empty_array": [], "empty_nested_dict": {}, }, ], } actual_result = remove_key_with_none_value(fixture) expected = { "a": 1, "nested": { "ac": 1, "nested": { "a": 1 } }, "array": [1, { "nested": { "ac": 1, "nested": { "a": 1 } } }, { "normal": 1 }], } eq_(actual_result, expected)