test_ModuleManager.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 #
5 # \file test_ModulesManager.py
6 # \brief Loadable modules manager class
7 # \date $Date: $
8 # \author Shinji Kurihara
9 #
10 # Copyright (C) 2006
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,os
19 sys.path.insert(1,"../")
20 
21 import unittest
22 
23 import OpenRTM_aist
24 
25 from ModuleManager import *
26 
27 configsample_spec = ["implementation_id", "ConfigSample",
28  "type_name", "ConfigSample",
29  "description", "Configuration example component",
30  "version", "1.0",
31  "vendor", "Shinji Kurihara, AIST",
32  "category", "example",
33  "activity_type", "DataFlowComponent",
34  "max_instance", "10",
35  "language", "Python",
36  "lang_type", "script",
37  # Configuration variables
38  "conf.default.int_param0", "0",
39  "conf.default.int_param1", "1",
40  "conf.default.double_param0", "0.11",
41  "conf.default.double_param1", "9.9",
42  "conf.default.str_param0", "hoge",
43  "conf.default.str_param1", "dara",
44  "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
45  "manager.modules.abs_path_allowed", "YES",
46  ""]
47 
48 
49 class TestModuleManager(unittest.TestCase):
50  def setUp(self):
51  self.mm = ModuleManager(OpenRTM_aist.Properties(defaults_str=configsample_spec))
52 
53  def tearDown(self):
54  del self.mm
55  OpenRTM_aist.Manager.instance().shutdownManager()
56 
57 
58  def test_load_unload(self):
59  try:
60  path = os.getcwd()
61  self.mm.load(path+"/hoge.py","echo")
62  self.mm.unload(path+"/hoge.py")
63 
64  self.mm.load("hoge","echo")
65  self.mm.unload("hoge")
66 
67  self.mm.load("hoge.py","echo")
68  self.mm.unload("hoge.py")
69 
70  self.mm.load("./hoge.py","echo")
71  self.mm.unload("./hoge.py")
72 
73  # Failure Pattern
74  #self.mm.load("sample")
75  except:
76  print "exception."
77  return
78 
79 
80  def test_unloadAll(self):
81  self.mm.unloadAll()
82  return
83 
84 
85  def test_symbol(self):
86  path = os.getcwd()
87  self.mm.load(path+"/hoge.py","echo")
88  self.mm.symbol(path+"/hoge.py","echo")()
89  self.mm.unload(path+"/hoge.py")
90 
91  self.mm.load("hoge","echo")
92  self.mm.symbol("hoge","echo")()
93  self.mm.unload("hoge")
94 
95  self.mm.load("hoge.py","echo")
96  self.mm.symbol("hoge.py","echo")()
97  self.mm.unload("hoge.py")
98 
99 
100  def test_setLoadpath(self):
101  self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
102  return
103 
104  def test_getLoadPath(self):
105  self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
106  self.assertEqual(self.mm.getLoadPath()[0],"/usr/lib/python/site-packages")
107  return
108 
109 
110  def test_addLoadpath(self):
111  self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
112  self.mm.addLoadpath(["/usr/local/lib/python/site-packages"])
113  self.assertEqual(self.mm.getLoadPath()[0],"/usr/lib/python/site-packages")
114  self.assertEqual(self.mm.getLoadPath()[-1],"/usr/local/lib/python/site-packages")
115  return
116 
117 
119  self.mm.load("hoge","echo")
120  self.assertNotEqual(self.mm.getLoadedModules()[0],None)
121  return
122 
123 
125  self.mm.allowAbsolutePath()
126  return
127 
128 
130  self.mm.disallowAbsolutePath()
131  return
132 
133 
135  self.mm.allowModuleDownload()
136  return
137 
138 
140  self.mm.disallowModuleDownload()
141  return
142 
143 
144  def test_findFile(self):
145  self.assertEqual(self.mm.findFile("hoge",["."]),"hoge")
146  self.assertEqual(self.mm.findFile("hoge.py",["."]),"hoge.py")
147  self.assertEqual(self.mm.findFile("hogehoge",["."]),"")
148  return
149 
150 
151  def test_fileExist(self):
152  self.assertEqual(self.mm.fileExist("hoge.py"),True)
153  self.assertEqual(self.mm.fileExist("./hoge.py"),True)
154  self.assertEqual(self.mm.fileExist("hoge"),True)
155  self.assertEqual(self.mm.fileExist("./hoge"),True)
156  self.assertEqual(self.mm.fileExist("hogehoge"),False)
157  return
158 
159 
161  self.mm.getInitFuncName("hoge.py")
162  return
163 
164 
166  self.assertEqual(self.mm._ModuleManager__getRtcProfile("./ConfigSample.py"),None)
167  self.assertEqual(self.mm._ModuleManager__getRtcProfile("ConfigSample.py"),None)
168  self.assertEqual(self.mm._ModuleManager__getRtcProfile("ConfigSample"),None)
169  return
170 
171 
173  self.mm.setLoadpath([".","./","../"])
174  self.assertNotEqual(self.mm.getLoadableModules(),[])
175  return
176 
177 
178 
179 ############### test #################
180 if __name__ == '__main__':
181  unittest.main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83


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