def test_same_unchanged(): cd = CowDict(base_dict) for key in keys: assert cd[key] == base_dict[key] assert set(base_dict_items) == set(cd.items()) assert base_dict_items == tuple(base_dict.items())
def test_new_keys_deleted(): cd = CowDict(base_dict) cd["foo6"] = "bar6" cd["foo7"] = "bar7" del cd["foo6"] del cd["foo7"] for key in keys: assert cd[key] == base_dict[key] assert set(base_dict_items) == set(cd.items()) assert base_dict_items == tuple(base_dict.items())
def test_new_keys_added(base_dict): cd = CowDict(base_dict) base_dict["foo6"] = "bar6" base_dict["foo7"] = "bar7" assert len(cd) == len(base_dict)
def test_missing_keys_deleted(): cd = CowDict(base_dict) with pytest.raises(KeyError): del cd["foo6"] assert base_dict_items == tuple(base_dict.items())
def test_keys_deleted(base_dict): cd = CowDict(base_dict) del base_dict["foo1"] del base_dict["foo5"] assert len(cd) == len(base_dict)
def test_same_changed(base_dict): cd = CowDict(base_dict) base_dict["foo2"] = "baz2" base_dict["foo5"] = "baz5" assert len(cd) == len(base_dict)
def test_new_keys_deleted(base_dict): cd = CowDict(base_dict) base_dict["foo6"] = "bar6" base_dict["foo7"] = "bar7" del cd["foo6"] del cd["foo7"] for key in keys: assert cd[key] == base_dict[key]
def test_same_changed(base_dict): cd = CowDict(base_dict) base_dict["foo2"] = "baz2" base_dict["foo5"] = "baz5" for key in keys: if key in ("foo2", "foo5"): assert cd[key] == key.replace("foo", "baz") else: assert cd[key] == base_dict[key] assert set(cd.items()) == { ('foo1', 'bar1'), ('foo2', 'baz2'), ('foo3', 'bar3'), ('foo4', 'bar4'), ('foo5', 'baz5'), }
def test_multiple_operations(): cd = CowDict(base_dict) del cd["foo1"] del cd["foo3"] cd["foo4"] = "changed_value" cd["new_key1"] = "new_value1" cd["new_key2"] = "new_value2" assert len(cd) == len(base_dict)
def test_multiple_operations(): cd = CowDict(base_dict) del cd["foo1"] del cd["foo3"] cd["new_key1"] = "new_value1" cd["new_key2"] = "new_value2" cd["foo4"] = "changed_value" with pytest.raises(KeyError): del cd["non_existing_key"] assert set(cd.keys()) == {"foo2", "foo4", "foo5", "new_key1", "new_key2"} assert set(cd.items()) == { ("foo2", "bar2"), ("foo4", "changed_value"), ("foo5", "bar5"), ("new_key1", "new_value1"), ("new_key2", "new_value2"), }
def test_base_keys_deleted(base_dict): cd = CowDict(base_dict) del base_dict["foo1"] del base_dict["foo5"] assert cd["foo2"] == "bar2" assert cd["foo3"] == "bar3" assert cd["foo4"] == "bar4" assert set(cd.items()) == { ('foo2', 'bar2'), ('foo3', 'bar3'), ('foo4', 'bar4'), } with pytest.raises(KeyError): cd["foo1"] with pytest.raises(KeyError): cd["foo5"]
def test_new_keys_added(base_dict): cd = CowDict(base_dict) base_dict["foo6"] = "bar6" base_dict["foo7"] = "bar7" for key in keys: assert cd[key] == base_dict[key] assert cd["foo6"] == "bar6" assert cd["foo7"] == "bar7" assert set(cd.items()) == { ('foo1', 'bar1'), ('foo2', 'bar2'), ('foo3', 'bar3'), ('foo4', 'bar4'), ('foo5', 'bar5'), ('foo6', 'bar6'), ('foo7', 'bar7'), }
def test_repr_and_str(): base = {"key1": "value1", "key2": "value2"} cd = CowDict(base) cd["new_key"] = "new_value" del cd["key2"] expected = ( "{'new_key': 'new_value', 'key1': 'value1'}", "{'key1': 'value1', 'new_key': 'new_value'}", ) assert repr(cd) in expected assert str(cd) in expected
def test_same_unchanged(): cd = CowDict(base_dict) assert len(cd) == len(base_dict)