MCPcopy Index your code
hub / github.com/plotly/dash / test_ddut001_attribute_dict

Function test_ddut001_attribute_dict

tests/unit/library/test_utils.py:6–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5
6def test_ddut001_attribute_dict():
7 a = utils.AttributeDict()
8
9 assert str(a) == "{}"
10 with pytest.raises(AttributeError):
11 a.k
12 with pytest.raises(KeyError):
13 a["k"]
14 assert a.first("no", "k", "nope") is None
15
16 a.k = 1
17
18 assert a.k == 1
19 assert a["k"] == 1
20 assert a.first("no", "k", "nope") == 1
21
22 a["k"] = 2
23
24 assert a.k == 2
25 assert a["k"] == 2
26
27 a.set_read_only(["k"], "boo")
28
29 with pytest.raises(AttributeError) as err:
30 a.k = 3
31 assert err.value.args == ("boo", "k")
32 assert a.k == 2
33 assert a._read_only == {"k": "boo"}
34
35 with pytest.raises(AttributeError) as err:
36 a["k"] = 3
37 assert err.value.args == ("boo", "k")
38 assert a.k == 2
39
40 a.set_read_only(["q"])
41
42 with pytest.raises(AttributeError) as err:
43 a.q = 3
44 assert err.value.args == ("Attribute is read-only", "q")
45 assert "q" not in a
46 assert a._read_only == {"k": "boo", "q": "Attribute is read-only"}
47
48 a.finalize("nope")
49
50 with pytest.raises(AttributeError) as err:
51 a.x = 4
52 assert err.value.args == ("nope", "x")
53 assert "x" not in a
54
55 a.finalize()
56
57 with pytest.raises(AttributeError) as err:
58 a.x = 4
59 assert err.value.args == ("Object is final: No new keys may be added.", "x")
60 assert "x" not in a
61
62
63@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 3

firstMethod · 0.95
set_read_onlyMethod · 0.95
finalizeMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…