-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_decorator.py
90 lines (64 loc) · 1.98 KB
/
test_decorator.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import time
from src.thread import threaded, processor
# >>>>>>>>>> Dummy Functions <<<<<<<<<< #
def _dummy_target_raiseToPower(x: float, power: float, delay: float = 0):
time.sleep(delay)
return x**power
# >>>>>>>>>> Threaded <<<<<<<<<< #
def test_threadedCreationNoParam():
@threaded
def _run(*args):
return _dummy_target_raiseToPower(*args)
x = _run(2, 2)
assert x.get_return_value() == 4
def test_threadedCreationEmptyParam():
@threaded()
def _run(*args):
return _dummy_target_raiseToPower(*args)
x = _run(2, 2)
assert x.get_return_value() == 4
def test_threadedCreationWithParam():
@threaded(daemon = True)
def _run(*args):
return _dummy_target_raiseToPower(*args)
x = _run(2, 2)
assert x.daemon
assert x.get_return_value() == 4
def test_threadedArgJoin():
@threaded(daemon = True, args = (1, 2, 3))
def _run(*args):
return args
x = _run(8, 9)
assert x.get_return_value() == (1, 2, 3, 8, 9)
def test_processorCreationNoParam():
@processor
def _run(args):
return _dummy_target_raiseToPower(*args)
x = _run([[2, 2]])
assert x.get_return_values() == [4]
def test_processorCreationEmptyParam():
@processor()
def _run(args):
return _dummy_target_raiseToPower(*args)
x = _run([[2, 2]])
assert x.get_return_values() == [4]
def test_processorCreationWithParam():
@processor(daemon = True)
def _run(args):
return _dummy_target_raiseToPower(*args)
x = _run([[2, 2]])
assert len(x._threads) == 1
assert x._threads[0].thread.daemon
assert x.get_return_values() == [4]
def test_processorArgJoin():
@processor(daemon = True, args = (1, 2, 3))
def _run(data, *args):
return [*args, *data]
x = _run([[8, 9]])
assert x.get_return_values() == [[1, 2, 3, 8, 9]]
def test_processorMultiArgJoin():
@processor(daemon = True, args = (1, 2, 3))
def _run(data, *args):
return [*args, *data]
x = _run([[8, 9], [10, 11]])
assert x.get_return_values() == [[1, 2, 3, 8, 9], [1, 2, 3, 10, 11]]