-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
51 lines (32 loc) · 860 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from collections import UserDict
from src.literal_dict import DictBuilder
def test_self_reference():
d = DictBuilder()
assert d[d] == {"d": d}
def test_literals():
d = DictBuilder()
a = 1
b = [a]
c = "abc"
assert d[a, b, c, c:4] == {"a": a, "b": b, "c": c, c: 4}
def test_custom_dict_class():
class DotDict(UserDict):
def __getattr__(self, key):
return self[key]
d = DictBuilder(DotDict)
a = 1
assert d[a].a == a
def test_global_reference():
d = DictBuilder()
def f():
assert d[DictBuilder] == {"DictBuilder": DictBuilder}
f()
def test_builtin_reference():
d = DictBuilder()
def f():
assert d[print] == {"print": print}
f()
def test_same_value_different_name():
d = DictBuilder()
a = b = 1
assert d[a, b] == {"a": 1, "b": 1}