-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_1_set_and_get.py
More file actions
42 lines (32 loc) · 1.1 KB
/
test_1_set_and_get.py
File metadata and controls
42 lines (32 loc) · 1.1 KB
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
from ghoshell_container import Container, IoCContainer
def test_set_and_get():
container = Container()
container.set('foo', 'bar')
assert container.get('foo') == 'bar'
assert container.bound('foo')
def test_get_none():
container = Container()
container.set('foo', 'bar')
# if not set, get none
assert container.get('zoo') is None
assert container['foo'] is 'bar'
del container['foo']
assert container.get('foo') is None
def test_get_recursively():
parent = Container()
parent.set('foo', 'bar')
child = Container(parent, name="self")
assert child.name == 'self'
assert child.parent is parent
# child get contract from parent
assert child.get('foo') == 'bar'
# child get contract from self only
assert child.get('foo', recursively=False) is None
def test_get_self():
parent = Container()
child = Container(parent, name="child")
assert child.get(Container) is child
assert parent.get(Container) is parent
assert child is not parent
assert child.get(IoCContainer) is child
assert parent.get(IoCContainer) is parent