OpenRTM_aist
test
test_Task.py
Go to the documentation of this file.
1
#!/usr/bin/env/python
2
# -*- Python -*-
3
4
#
5
# \file Task.py
6
# \brief Task class
7
# \date $Date: $
8
# \author Shinji Kurihara
9
#
10
# Copyright (C) 2007
11
# Task-intelligence Research Group,
12
# Intelligent Systems Research Institute,
13
# National Institute of
14
# Advanced Industrial Science and Technology (AIST), Japan
15
# All rights reserved.
16
#
17
18
import
sys,time
19
sys.path.insert(1,
"../"
)
20
21
import
unittest
22
23
from
Task
import
*
24
25
cnt = 0
26
27
class
Mock
(
Task
):
28
def
__init__
(self):
29
global
cnt
30
cnt += 1
31
self.
cnt
= cnt
32
Task.__init__(self)
33
self.
flag
=
False
34
35
def
svc
(self):
36
print
"cnt: "
,
37
while
self.
flag
:
38
print
self.
cnt
,
" "
,
39
time.sleep(0.1)
40
return
41
42
def
activate
(self):
43
self.
flag
=
True
44
Task.activate(self)
45
return
46
47
def
finalize
(self):
48
self.
flag
=
False
49
50
class
Mock2
(
Task
):
51
def
__init__
(self,func):
52
global
cnt
53
cnt += 1
54
self.
cnt
= cnt
55
Task.__init__(self)
56
self.
flag
=
False
57
self.
func
= func
58
59
def
svc
(self):
60
time.sleep(1)
61
self.
func
()
62
return
63
64
def
activate
(self):
65
self.
flag
=
True
66
Task.activate(self)
67
return
68
69
def
finalize
(self):
70
self.
flag
=
False
71
72
73
class
TestTask
(unittest.TestCase):
74
def
setUp
(self):
75
self.
mock
=
Mock
()
76
return
77
78
def
test_activate
(self):
79
self.
mock
.activate()
80
mock2=
Mock
()
81
mock2.activate()
82
time.sleep(2)
83
mock2.finalize()
84
self.
mock
.finalize()
85
return
86
87
def
test_wait
(self):
88
self.
mock
.activate()
89
time.sleep(0.5)
90
mock2=
Mock2
(self.
mock
.finalize)
91
mock2.activate()
92
self.
mock
.wait()
93
mock2.finalize()
94
return
95
96
97
def
test_reset
(self):
98
self.
mock
.reset()
99
return
100
101
102
def
test_finalize
(self):
103
self.
mock
.finalize()
104
return
105
106
107
def
test_svn_run
(self):
108
self.
mock
.svc_run()
109
return
110
111
112
113
if
__name__ ==
'__main__'
:
114
unittest.main()
test_Task.TestTask
Definition:
test_Task.py:73
Task
test_Task.Mock.svc
def svc(self)
Definition:
test_Task.py:35
test_Task.TestTask.test_reset
def test_reset(self)
Definition:
test_Task.py:97
test_Task.TestTask.mock
mock
Definition:
test_Task.py:75
test_Task.TestTask.test_wait
def test_wait(self)
Definition:
test_Task.py:87
test_Task.Mock2.func
func
Definition:
test_Task.py:57
test_Task.TestTask.setUp
def setUp(self)
Definition:
test_Task.py:74
test_Task.Mock.cnt
cnt
Definition:
test_Task.py:31
test_Task.Mock2.cnt
cnt
Definition:
test_Task.py:54
test_Task.TestTask.test_finalize
def test_finalize(self)
Definition:
test_Task.py:102
test_Task.Mock2.activate
def activate(self)
Definition:
test_Task.py:64
test_Task.Mock2
Definition:
test_Task.py:50
test_Task.Mock.finalize
def finalize(self)
Definition:
test_Task.py:47
test_Task.Mock
Definition:
test_Task.py:27
test_Task.TestTask.test_svn_run
def test_svn_run(self)
Definition:
test_Task.py:107
test_Task.TestTask.test_activate
def test_activate(self)
Definition:
test_Task.py:78
test_Task.Mock.flag
flag
Definition:
test_Task.py:33
test_Task.Mock2.flag
flag
Definition:
test_Task.py:56
test_Task.Mock2.__init__
def __init__(self, func)
Definition:
test_Task.py:51
test_Task.Mock.activate
def activate(self)
Definition:
test_Task.py:42
test_Task.Mock.__init__
def __init__(self)
Definition:
test_Task.py:28
test_Task.Mock2.finalize
def finalize(self)
Definition:
test_Task.py:69
test_Task.Mock2.svc
def svc(self)
Definition:
test_Task.py:59
openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:07