-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_2_fetch.py
More file actions
43 lines (28 loc) · 815 Bytes
/
test_2_fetch.py
File metadata and controls
43 lines (28 loc) · 815 Bytes
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
from ghoshell_container import Container
from abc import ABC, abstractmethod
import pytest
class _Foo(ABC):
pass
class _Bar(_Foo):
pass
class _Baz:
pass
def test_fetch():
container = Container()
bar = _Bar()
container.set(_Foo, bar)
assert container.fetch(_Foo) is bar
assert container.force_fetch(_Foo) is bar
def test_fetch_exception():
container = Container()
container.set(_Foo, _Baz())
with pytest.raises(TypeError):
container.fetch(_Foo)
assert isinstance(container[_Foo], _Baz)
def test_fetch_non_existent():
container = Container()
container.set(_Foo, _Baz())
assert container.fetch(_Baz) is None
with pytest.raises(KeyError):
# force fetch raise exception when not bound
container.force_fetch(_Baz)