-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
44 lines (30 loc) · 1.27 KB
/
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
"""Implementace jednotkových testů."""
from unittest.mock import *
from application import *
def test1():
"""První test neprovádí prakticky žádné reálné kontroly, jen zavolá testovanou funkci."""
print("function1 returns: {v}".format(v=function1()))
@patch('application.function2', return_value=42)
def test2(mocked_function):
# vytiskneme informaci o tom, zda se mockovaná funkce zavolala
print("mocked function called: {c}".format(c=mocked_function.called))
print("function1 returns: {v}".format(v=function1()))
# opět vytiskneme informaci o tom, zda se mockovaná funkce zavolala
print("mocked function called: {c}".format(c=mocked_function.called))
def side_effect_handler():
print("side_effect_handler function called")
return -1
@patch('application.function2', side_effect=side_effect_handler)
def test3(mocked_function):
# vytiskneme informaci o tom, zda se mockovaná funkce zavolala
print("mocked function called: {c}".format(c=mocked_function.called))
print(function1())
# opět vytiskneme informaci o tom, zda se mockovaná funkce zavolala
print("mocked function called: {c}".format(c=mocked_function.called))
if __name__ == '__main__':
test1()
print()
test2()
print()
test3()
print()