test_Task.py
Go to the documentation of this file.
00001 #!/usr/bin/env/python
00002 # -*- Python -*-
00003 
00004 #
00005 # \file Task.py
00006 # \brief Task class
00007 # \date $Date: $
00008 # \author Shinji Kurihara
00009 #
00010 # Copyright (C) 2007
00011 #     Task-intelligence Research Group,
00012 #     Intelligent Systems Research Institute,
00013 #     National Institute of
00014 #         Advanced Industrial Science and Technology (AIST), Japan
00015 #     All rights reserved.
00016 #
00017 
00018 import sys,time
00019 sys.path.insert(1,"../")
00020 
00021 import unittest
00022 
00023 from Task import *
00024 
00025 cnt = 0
00026 
00027 class Mock(Task):
00028         def __init__(self):
00029                 global cnt
00030                 cnt += 1
00031                 self.cnt = cnt
00032                 Task.__init__(self)
00033                 self.flag = False
00034 
00035         def svc(self):
00036                 print "cnt: ",
00037                 while self.flag:
00038                         print self.cnt, " ",
00039                         time.sleep(0.1)
00040                 return
00041 
00042         def activate(self):
00043                 self.flag = True
00044                 Task.activate(self)
00045                 return
00046 
00047         def finalize(self):
00048                 self.flag = False
00049 
00050 class Mock2(Task):
00051         def __init__(self,func):
00052                 global cnt
00053                 cnt += 1
00054                 self.cnt = cnt
00055                 Task.__init__(self)
00056                 self.flag = False
00057                 self.func = func
00058 
00059         def svc(self):
00060                 time.sleep(1)
00061                 self.func()
00062                 return
00063 
00064         def activate(self):
00065                 self.flag = True
00066                 Task.activate(self)
00067                 return
00068 
00069         def finalize(self):
00070                 self.flag = False
00071                 
00072 
00073 class TestTask(unittest.TestCase):
00074         def setUp(self):
00075                 self.mock = Mock()
00076                 return
00077 
00078         def test_activate(self):
00079                 self.mock.activate()
00080                 mock2= Mock()
00081                 mock2.activate()
00082                 time.sleep(2)
00083                 mock2.finalize()
00084                 self.mock.finalize()
00085                 return
00086 
00087         def test_wait(self):
00088                 self.mock.activate()
00089                 time.sleep(0.5)
00090                 mock2= Mock2(self.mock.finalize)
00091                 mock2.activate()
00092                 self.mock.wait()
00093                 mock2.finalize()
00094                 return
00095     
00096 
00097         def test_reset(self):
00098                 self.mock.reset()
00099                 return
00100 
00101 
00102         def test_finalize(self):
00103                 self.mock.finalize()
00104                 return
00105     
00106 
00107         def test_svn_run(self):
00108                 self.mock.svc_run()
00109                 return
00110 
00111 
00112 ############### test #################
00113 if __name__ == '__main__':
00114         unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28