test-hostname.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 PKG = 'hrpsys'
00004 NAME = 'test-hostname'
00005 
00006 import imp  ## for rosbuild
00007 try:
00008     imp.find_module(PKG)
00009 except:
00010     import roslib; roslib.load_manifest(PKG)
00011 
00012 from hrpsys import hrpsys_config
00013 
00014 import socket
00015 import rtm
00016 
00017 import unittest
00018 import rostest
00019 import sys
00020 import time
00021 
00022 class TestHrpsysHostname(unittest.TestCase):
00023 
00024     def check_initCORBA(self, nshost, nsport=2809):
00025         try:
00026             ms = rh = None
00027             rtm.nshost = nshost
00028             rtm.nsport = nsport
00029             rtm.initCORBA()
00030             count = 0
00031             while ( not (ms and rh) ) and count < 10:
00032                 ms = rtm.findRTCmanager()
00033                 rh = rtm.findRTC("RobotHardware0")
00034                 if ms and rh :
00035                     break
00036                 time.sleep(1)
00037                 print >>sys.stderr, "wait for RTCmanager=%r, RTC(RobotHardware0)=%r"%(ms,rh)
00038                 count += 1
00039             self.assertTrue(ms and rh)
00040         except Exception as e:
00041             self.fail("%r, nshost=%r, nsport=%r RTCmanager=%r, RTC(RobotHardware0)=%r"%(str(e),nshost,nsport,ms,rh))
00042             pass
00043 
00044     def test_gethostname(self):
00045         self.check_initCORBA(socket.gethostname())
00046     def test_localhost(self):
00047         self.check_initCORBA('localhost')
00048     def test_127_0_0_1(self):
00049         self.check_initCORBA('127.0.0.1')
00050     def test_None(self):
00051         self.check_initCORBA(None)
00052 
00053     @unittest.expectedFailure
00054     def test_X_unknown(self):
00055         try:
00056             self.check_initCORBA('unknown')
00057         except SystemExit as e:
00058             print "[This is Expected Failure]"
00059             print str(e.message)
00060 
00061     @unittest.expectedFailure
00062     def test_X_123_45_67_89(self):
00063         try:
00064             self.check_initCORBA('123.45.67.89')
00065         except SystemExit as e:
00066             print "[This is Expected Failure]"
00067             print str(e.message)
00068 
00069 #unittest.main()
00070 if __name__ == '__main__':
00071     rostest.run(PKG, NAME, TestHrpsysHostname, sys.argv)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Aug 26 2015 11:53:03