-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_ctx.py
76 lines (55 loc) · 1.41 KB
/
test_ctx.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pytest
from ctx import Ctx
def test_lookup_error():
"""Should return LookupError if no attiibute or key is found"""
with pytest.raises(LookupError):
x = Ctx()
(x.no_key == 5)
with pytest.raises(LookupError):
x = Ctx()
(x['no_key'] == 5)
def test_attribute_error():
"""Should raise AttributeError if attempt to set an attribute."""
with pytest.raises(AttributeError):
x = Ctx()
x.copy = 5
def test_attribue_access():
"""Should return attribute of an object."""
x = Ctx()
assert x.__doc__ == x["__doc__"]
def test_init():
"""Should initialize an object with keywords"""
p = {}
q = {}
x = Ctx(a=p, b=q)
assert x['a'] is p
assert x.a is p
assert x['b'] is q
assert x.b is q
def test_item():
"""Should set an item with ctx['a'] and retrieve it with ctx[a] or ctx.a"""
p = {}
x = Ctx()
x['a'] = p
assert x.a is p
assert x['a'] is p
def test_attr():
"""Should set an item with ctx.a and retrieve it with ctx[a] or ctx.a"""
p = {}
x = Ctx()
x.a = p
assert x.a is p
assert x['a'] is p
def test_init_copy():
"""Should create a shallow copy."""
p = {}
q = {}
x = Ctx(a=p, b=q)
y = x.copy()
assert x is not y
assert y['a'] is p
assert y.a is p
assert y['b'] is q
assert y.b is q
if __name__ == '__main__':
pytest.main()