test_Async.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 # @file test_Async.py
00005 # @brief test for Async class
00006 # @date $Date: 2009/02/18$
00007 # @author Shinji Kurihara
00008 #
00009 # Copyright (C) 2009
00010 #     Task-intelligence Research Group,
00011 #     Intelligent Systems Research Institute,
00012 #     National Institute of
00013 #         Advanced Industrial Science and Technology (AIST), Japan
00014 #     All rights reserved.
00015 #
00016 
00017 import time
00018 import sys
00019 sys.path.insert(1,"../")
00020 
00021 import unittest
00022 from Async import *
00023 
00024 class A:
00025         def __init__(self):
00026                 self._hoge   = False
00027                 self._munya  = False
00028                 self._addone = False
00029                 return
00030 
00031         def hoge(self):
00032                 for i in range(5):
00033                         print ",",
00034                         time.sleep(1)
00035                 print
00036                 self._hoge = True
00037                 return
00038 
00039         def hoge_invoked(self):
00040                 return self._hoge
00041 
00042         def munya(self, msg):
00043                 print
00044                 for i in range(5):
00045                         print ",",
00046                         time.sleep(1)
00047                 self._munya = True
00048                 return
00049 
00050         def munya_invoked(self):
00051                 return self._munya
00052 
00053         def add_one(self, val):
00054                 for i in range(5):
00055                         print ",",
00056                         time.sleep(1)
00057                 self._addone = True
00058                 return val+1
00059 
00060         def add_one_invoked(self):
00061                 return self._addone
00062 
00063 
00064 class add_one_functor:
00065         def __init__(self, val):
00066                 self._val = val
00067                 self._ret = None
00068 
00069         def __call__(self, obj):
00070                 self._ret = obj.add_one(self._val)
00071                 
00072         def get_ret(self):
00073                 return self._ret
00074                 
00075 
00076 
00077 class TestAsync(unittest.TestCase):
00078         def setUp(self):
00079                 pass
00080 
00081         def test_memfun(self):
00082                 a = A()
00083                 invoker = Async_tInvoker(a,A.hoge)
00084                 invoker.invoke()
00085                 self.assertEqual(a.hoge_invoked(),False)
00086                 invoker.wait()
00087                 self.assertEqual(a.hoge_invoked(),True)
00088                 return
00089 
00090 
00091         def test_memfun_with_args(self):
00092                 a = A()
00093                 invoker = Async_tInvoker(a,A.munya,"munyamunya")
00094                 invoker.invoke()
00095                 self.assertEqual(a.munya_invoked(),False)
00096                 invoker.wait()
00097                 self.assertEqual(a.munya_invoked(),True)
00098                 return
00099 
00100 
00101         def test_functor(self):
00102                 a = A()
00103                 val = 100
00104                 aof = add_one_functor(val)
00105                 invoker = Async_tInvoker(a,aof)
00106                 invoker.invoke()
00107                 self.assertEqual(a.add_one_invoked(),False)
00108                 invoker.wait()
00109                 self.assertEqual(a.add_one_invoked(),True)
00110                 self.assertEqual(aof.get_ret(),val+1)
00111                 return
00112 
00113                 
00114 
00115 ############### test #################
00116 if __name__ == '__main__':
00117         unittest.main()


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