Exemplo n.º 1
0
def test_itemdel_unset_error() -> None:
    d = {"foo": 42}
    with pytest.raises(RuntimeError, match="Catch this!"):
        with itemdel(d, "bar"):
            assert "bar" not in d
            raise RuntimeError("Catch this!")
    assert "bar" not in d
Exemplo n.º 2
0
def test_itemdel_error() -> None:
    d = {"foo": 42}
    with pytest.raises(RuntimeError, match="Catch this!"):
        with itemdel(d, "foo"):
            assert "foo" not in d
            raise RuntimeError("Catch this!")
    assert d["foo"] == 42
Exemplo n.º 3
0
def test_itemdel_not_copied_error() -> None:
    x = object()
    d = {"foo": x}
    with pytest.raises(RuntimeError, match="Catch this!"):
        with itemdel(d, "foo"):
            assert "foo" not in d
            raise RuntimeError("Catch this!")
    assert d["foo"] is x
Exemplo n.º 4
0
def test_itemdel_unset_modified_error() -> None:
    d: Dict[str, Any] = {"foo": 42}
    with pytest.raises(RuntimeError, match="Catch this!"):
        with itemdel(d, "bar"):
            assert "bar" not in d
            d["bar"] = [3.14]
            raise RuntimeError("Catch this!")
    assert "bar" not in d
Exemplo n.º 5
0
def test_itemdel_not_copied() -> None:
    x = object()
    d = {"foo": x}
    with itemdel(d, "foo"):
        assert "foo" not in d
    assert d["foo"] is x
Exemplo n.º 6
0
def test_itemdel_unset_modified() -> None:
    d: Dict[str, Any] = {"foo": 42}
    with itemdel(d, "bar"):
        assert "bar" not in d
        d["bar"] = [3.14]
    assert "bar" not in d
Exemplo n.º 7
0
def test_itemdel() -> None:
    d = {"foo": 42}
    with itemdel(d, "foo"):
        assert "foo" not in d
    assert d["foo"] == 42
Exemplo n.º 8
0
def test_itemdel_unset() -> None:
    d = {"foo": 42}
    with itemdel(d, "bar"):
        assert "bar" not in d
    assert "bar" not in d
Exemplo n.º 9
0
def test_itemdel_modified() -> None:
    d: Dict[str, Any] = {"foo": 42}
    with itemdel(d, "foo"):
        assert "foo" not in d
        d["foo"] = [3.14]
    assert d["foo"] == 42