test_Async.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 # @file test_Async.py
5 # @brief test for Async class
6 # @date $Date: 2009/02/18$
7 # @author Shinji Kurihara
8 #
9 # Copyright (C) 2009
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 
17 import time
18 import sys
19 sys.path.insert(1,"../")
20 
21 import unittest
22 from Async import *
23 
24 class A:
25  def __init__(self):
26  self._hoge = False
27  self._munya = False
28  self._addone = False
29  return
30 
31  def hoge(self):
32  for i in range(5):
33  print(",", end=' ')
34  time.sleep(1)
35  print()
36  self._hoge = True
37  return
38 
39  def hoge_invoked(self):
40  return self._hoge
41 
42  def munya(self, msg):
43  print()
44  for i in range(5):
45  print(",", end=' ')
46  time.sleep(1)
47  self._munya = True
48  return
49 
50  def munya_invoked(self):
51  return self._munya
52 
53  def add_one(self, val):
54  for i in range(5):
55  print(",", end=' ')
56  time.sleep(1)
57  self._addone = True
58  return val+1
59 
60  def add_one_invoked(self):
61  return self._addone
62 
63 
65  def __init__(self, val):
66  self._val = val
67  self._ret = None
68 
69  def __call__(self, obj):
70  self._ret = obj.add_one(self._val)
71 
72  def get_ret(self):
73  return self._ret
74 
75 
76 
77 class TestAsync(unittest.TestCase):
78  def setUp(self):
79  pass
80 
81  def test_memfun(self):
82  a = A()
83  invoker = Async_tInvoker(a,A.hoge)
84  invoker.invoke()
85  self.assertEqual(a.hoge_invoked(),False)
86  invoker.wait()
87  self.assertEqual(a.hoge_invoked(),True)
88  return
89 
90 
92  a = A()
93  invoker = Async_tInvoker(a,A.munya,"munyamunya")
94  invoker.invoke()
95  self.assertEqual(a.munya_invoked(),False)
96  invoker.wait()
97  self.assertEqual(a.munya_invoked(),True)
98  return
99 
100 
101  def test_functor(self):
102  a = A()
103  val = 100
104  aof = add_one_functor(val)
105  invoker = Async_tInvoker(a,aof)
106  invoker.invoke()
107  self.assertEqual(a.add_one_invoked(),False)
108  invoker.wait()
109  self.assertEqual(a.add_one_invoked(),True)
110  self.assertEqual(aof.get_ret(),val+1)
111  return
112 
113 
114 
115 
116 if __name__ == '__main__':
117  unittest.main()
test_Async.TestAsync.setUp
def setUp(self)
Definition: test_Async.py:78
test_Async.A.add_one_invoked
def add_one_invoked(self)
Definition: test_Async.py:60
test_Async.A.add_one
def add_one(self, val)
Definition: test_Async.py:53
test_Async.A._hoge
_hoge
Definition: test_Async.py:26
OpenRTM_aist.Async.Async_tInvoker
def Async_tInvoker(obj, func, *args)
def Async_tInvoker(func, auto_delete = False):
Definition: Async.py:165
test_Async.A.hoge
def hoge(self)
Definition: test_Async.py:31
test_Async.TestAsync.test_memfun
def test_memfun(self)
Definition: test_Async.py:81
test_Async.A
Definition: test_Async.py:24
test_Async.A.munya
def munya(self, msg)
Definition: test_Async.py:42
test_Async.add_one_functor._val
_val
Definition: test_Async.py:66
test_Async.TestAsync.test_memfun_with_args
def test_memfun_with_args(self)
Definition: test_Async.py:91
test_Async.A._addone
_addone
Definition: test_Async.py:28
test_Async.add_one_functor._ret
_ret
Definition: test_Async.py:67
test_Async.A._munya
_munya
Definition: test_Async.py:27
test_Async.add_one_functor.__call__
def __call__(self, obj)
Definition: test_Async.py:69
test_Async.A.hoge_invoked
def hoge_invoked(self)
Definition: test_Async.py:39
test_Async.TestAsync
Definition: test_Async.py:77
test_Async.add_one_functor.__init__
def __init__(self, val)
Definition: test_Async.py:65
test_Async.A.__init__
def __init__(self)
Definition: test_Async.py:25
test_Async.A.munya_invoked
def munya_invoked(self)
Definition: test_Async.py:50
test_Async.add_one_functor
Definition: test_Async.py:64
test_Async.add_one_functor.get_ret
def get_ret(self)
Definition: test_Async.py:72
test_Async.TestAsync.test_functor
def test_functor(self)
Definition: test_Async.py:101


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Apr 21 2025 02:45:06