def test_array_replace(array): new = replace(array, 1, 456) assert array is not new assert len(new) == len(array) assert new[0] is array[0] assert new[1] == 456 assert new[2] is array[2]
def test_replace_type_error(): node = {'key': 'value'} with pytest.raises(TypeError): replace(node, 'key', 123)
def test_object_replace(obj): new = replace(obj, 'key', 456) assert obj is not new assert set(new.keys()) == set(obj.keys()) for key in set(new.keys()) - set(['key']): assert obj[key] is new[key]
def test_document_replace(doc): new = replace(doc, 'integer', 456) assert doc is not new assert set(new.keys()) == set(doc.keys()) for key in set(new.keys()) - set(['integer']): assert doc[key] is new[key]