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 ",",
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 ",",
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 ",",
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 ############### test #################
116 if __name__ == '__main__':
117  unittest.main()
def test_functor(self)
Definition: test_Async.py:101
def test_memfun_with_args(self)
Definition: test_Async.py:91
def test_memfun(self)
Definition: test_Async.py:81
def munya_invoked(self)
Definition: test_Async.py:50
def hoge_invoked(self)
Definition: test_Async.py:39
def __init__(self)
Definition: test_Async.py:25
def add_one_invoked(self)
Definition: test_Async.py:60
def add_one(self, val)
Definition: test_Async.py:53
def munya(self, msg)
Definition: test_Async.py:42
def __init__(self, val)
Definition: test_Async.py:65
def __call__(self, obj)
Definition: test_Async.py:69
def hoge(self)
Definition: test_Async.py:31
def Async_tInvoker(obj, func, args)
def Async_tInvoker(func, auto_delete = False):
Definition: Async.py:165


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34