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()
def svc(self)
Definition: test_Task.py:35
def test_reset(self)
Definition: test_Task.py:97
def test_wait(self)
Definition: test_Task.py:87
def setUp(self)
Definition: test_Task.py:74
def test_finalize(self)
Definition: test_Task.py:102
def activate(self)
Definition: test_Task.py:64
def finalize(self)
Definition: test_Task.py:47
def test_svn_run(self)
Definition: test_Task.py:107
def test_activate(self)
Definition: test_Task.py:78
def __init__(self, func)
Definition: test_Task.py:51
def activate(self)
Definition: test_Task.py:42
def __init__(self)
Definition: test_Task.py:28
def finalize(self)
Definition: test_Task.py:69
def svc(self)
Definition: test_Task.py:59


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:07