test_ModuleManager.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 #
00005 # \file test_ModulesManager.py
00006 # \brief Loadable modules manager class
00007 # \date $Date: $
00008 # \author Shinji Kurihara
00009 #
00010 # Copyright (C) 2006
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,os
00019 sys.path.insert(1,"../")
00020 
00021 import unittest
00022 
00023 import OpenRTM_aist
00024 
00025 from ModuleManager import *
00026 
00027 configsample_spec = ["implementation_id", "ConfigSample",
00028                      "type_name",         "ConfigSample",
00029                      "description",       "Configuration example component",
00030                      "version",           "1.0",
00031                      "vendor",            "Shinji Kurihara, AIST",
00032                      "category",          "example",
00033                      "activity_type",     "DataFlowComponent",
00034                      "max_instance",      "10",
00035                      "language",          "Python",
00036                      "lang_type",         "script",
00037                      # Configuration variables
00038                      "conf.default.int_param0", "0",
00039                      "conf.default.int_param1", "1",
00040                      "conf.default.double_param0", "0.11",
00041                      "conf.default.double_param1", "9.9",
00042                      "conf.default.str_param0", "hoge",
00043                      "conf.default.str_param1", "dara",
00044                      "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00045                      "manager.modules.abs_path_allowed",   "YES",
00046                      ""]
00047 
00048 
00049 class TestModuleManager(unittest.TestCase):
00050   def setUp(self):
00051     self.mm = ModuleManager(OpenRTM_aist.Properties(defaults_str=configsample_spec))
00052 
00053   def tearDown(self):
00054     del self.mm
00055     OpenRTM_aist.Manager.instance().shutdownManager()
00056     
00057     
00058   def test_load_unload(self):
00059     try:
00060       path = os.getcwd()
00061       self.mm.load(path+"/hoge.py","echo")
00062       self.mm.unload(path+"/hoge.py")
00063 
00064       self.mm.load("hoge","echo")
00065       self.mm.unload("hoge")
00066 
00067       self.mm.load("hoge.py","echo")
00068       self.mm.unload("hoge.py")
00069 
00070       self.mm.load("./hoge.py","echo")
00071       self.mm.unload("./hoge.py")
00072 
00073       # Failure Pattern
00074       #self.mm.load("sample")
00075     except:
00076       print "exception."
00077     return
00078     
00079 
00080   def test_unloadAll(self):
00081     self.mm.unloadAll()
00082     return
00083     
00084 
00085   def test_symbol(self):
00086     path = os.getcwd()
00087     self.mm.load(path+"/hoge.py","echo")
00088     self.mm.symbol(path+"/hoge.py","echo")()
00089     self.mm.unload(path+"/hoge.py")
00090 
00091     self.mm.load("hoge","echo")
00092     self.mm.symbol("hoge","echo")()
00093     self.mm.unload("hoge")
00094 
00095     self.mm.load("hoge.py","echo")
00096     self.mm.symbol("hoge.py","echo")()
00097     self.mm.unload("hoge.py")
00098 
00099     
00100   def test_setLoadpath(self):
00101     self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
00102     return
00103   
00104   def test_getLoadPath(self):
00105     self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
00106     self.assertEqual(self.mm.getLoadPath()[0],"/usr/lib/python/site-packages")
00107     return
00108 
00109     
00110   def test_addLoadpath(self):
00111     self.mm.setLoadpath(["/usr/lib/python/site-packages","."])
00112     self.mm.addLoadpath(["/usr/local/lib/python/site-packages"])
00113     self.assertEqual(self.mm.getLoadPath()[0],"/usr/lib/python/site-packages")
00114     self.assertEqual(self.mm.getLoadPath()[-1],"/usr/local/lib/python/site-packages")
00115     return
00116 
00117   
00118   def test_getLoadedModules(self):
00119     self.mm.load("hoge","echo")
00120     self.assertNotEqual(self.mm.getLoadedModules()[0],None)
00121     return
00122     
00123 
00124   def test_allowAbsolutePath(self):
00125     self.mm.allowAbsolutePath()
00126     return
00127 
00128     
00129   def test_disallowAbsolutePath(self):
00130     self.mm.disallowAbsolutePath()
00131     return
00132 
00133     
00134   def test_allowModuleDownload(self):
00135     self.mm.allowModuleDownload()
00136     return
00137 
00138     
00139   def test_disallowModuleDownload(self):
00140     self.mm.disallowModuleDownload()
00141     return
00142 
00143     
00144   def test_findFile(self):
00145     self.assertEqual(self.mm.findFile("hoge",["."]),"hoge")
00146     self.assertEqual(self.mm.findFile("hoge.py",["."]),"hoge.py")
00147     self.assertEqual(self.mm.findFile("hogehoge",["."]),"")
00148     return
00149 
00150     
00151   def test_fileExist(self):
00152     self.assertEqual(self.mm.fileExist("hoge.py"),True)
00153     self.assertEqual(self.mm.fileExist("./hoge.py"),True)
00154     self.assertEqual(self.mm.fileExist("hoge"),True)
00155     self.assertEqual(self.mm.fileExist("./hoge"),True)
00156     self.assertEqual(self.mm.fileExist("hogehoge"),False)
00157     return
00158 
00159     
00160   def test_getInitFuncName(self):
00161     self.mm.getInitFuncName("hoge.py")
00162     return
00163     
00164 
00165   def test_getRtcProfile(self):
00166     self.assertEqual(self.mm._ModuleManager__getRtcProfile("./ConfigSample.py"),None)
00167     self.assertEqual(self.mm._ModuleManager__getRtcProfile("ConfigSample.py"),None)
00168     self.assertEqual(self.mm._ModuleManager__getRtcProfile("ConfigSample"),None)
00169     return
00170 
00171 
00172   def test_getLoadableModules(self):
00173     self.mm.setLoadpath([".","./","../"])
00174     self.assertNotEqual(self.mm.getLoadableModules(),[])
00175     return
00176 
00177 
00178 
00179 ############### test #################
00180 if __name__ == '__main__':
00181         unittest.main()


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