00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import roslib; roslib.load_manifest('test_roslib')
00034
00035 import os
00036 import struct
00037 import sys
00038 import unittest
00039
00040 import roslib.rosenv
00041 import roslib.os_detect
00042 import rosunit
00043
00044 class test_OS(roslib.os_detect.OSBase):
00045 def check_presence(self):
00046 return True
00047 def get_name(self):
00048 return "os_name"
00049 def get_version(self):
00050 return "os_version"
00051
00052 class dummy_OS(roslib.os_detect.OSBase):
00053 def check_presence(self):
00054 return False
00055 def get_name(self):
00056 return "os_name2"
00057 def get_version(self):
00058 return "os_version2"
00059
00060
00061 class RoslibOsDetectTest(unittest.TestCase):
00062
00063 def test_tripwire_ubuntu(self):
00064 ubuntu = roslib.os_detect.Ubuntu()
00065 self.assertEqual("ubuntu", ubuntu.get_name())
00066
00067 def test_tripwire_debian(self):
00068 debian = roslib.os_detect.Debian()
00069 self.assertEqual("debian", debian.get_name())
00070
00071 def test_tripwire_macports(self):
00072 macports = roslib.os_detect.Macports()
00073 self.assertEqual("macports", macports.get_name())
00074
00075 def test_tripwire_arch(self):
00076 arch = roslib.os_detect.Arch()
00077 self.assertEqual("arch", arch.get_name())
00078
00079 def test_tripwire_opensuse(self):
00080 opensuse = roslib.os_detect.OpenSuse()
00081 self.assertEqual("opensuse", opensuse.get_name())
00082
00083 def test_tripwire_fedora(self):
00084 fedora = roslib.os_detect.Fedora()
00085 self.assertEqual("fedora", fedora.get_name())
00086
00087 def test_tripwire_rhel(self):
00088 rhel = roslib.os_detect.Rhel()
00089 self.assertEqual("rhel", rhel.get_name())
00090
00091
00092 def test_tripwire_OSDetect(self):
00093 osa = roslib.os_detect.OSDetect()
00094
00095 def test_OSDetect_single(self):
00096 osa = roslib.os_detect.OSDetect([test_OS()])
00097 self.assertEqual("os_name", osa.get_name())
00098 self.assertEqual("os_version", osa.get_version())
00099
00100 def test_OSDetect_first_of_two(self):
00101 osa = roslib.os_detect.OSDetect([test_OS(), dummy_OS()])
00102 self.assertEqual("os_name", osa.get_name())
00103 self.assertEqual("os_version", osa.get_version())
00104 os_class = osa.get_os()
00105 self.assertEqual("os_name", os_class.get_name())
00106 self.assertEqual("os_version", os_class.get_version())
00107
00108 def test_OSDetect_second_of_two(self):
00109 osa = roslib.os_detect.OSDetect([dummy_OS(), test_OS()])
00110 self.assertEqual("os_name", osa.get_name())
00111 self.assertEqual("os_version", osa.get_version())
00112 os_class = osa.get_os()
00113 self.assertEqual("os_name", os_class.get_name())
00114 self.assertEqual("os_version", os_class.get_version())
00115
00116 def test_OSDetect_first_of_many(self):
00117 osa = roslib.os_detect.OSDetect([test_OS(), dummy_OS(), dummy_OS(), dummy_OS(), dummy_OS()])
00118 self.assertEqual("os_name", osa.get_name())
00119 self.assertEqual("os_version", osa.get_version())
00120 os_class = osa.get_os()
00121 self.assertEqual("os_name", os_class.get_name())
00122 self.assertEqual("os_version", os_class.get_version())
00123
00124 def test_OSDetect_second_of_many(self):
00125 osa = roslib.os_detect.OSDetect([dummy_OS(), test_OS(), dummy_OS(), dummy_OS(), dummy_OS()])
00126 self.assertEqual("os_name", osa.get_name())
00127 self.assertEqual("os_version", osa.get_version())
00128 os_class = osa.get_os()
00129 self.assertEqual("os_name", os_class.get_name())
00130 self.assertEqual("os_version", os_class.get_version())
00131
00132 def test_OSDetect_last_of_many(self):
00133 osa = roslib.os_detect.OSDetect([dummy_OS(), dummy_OS(), dummy_OS(), dummy_OS(), test_OS(),])
00134 self.assertEqual("os_name", osa.get_name())
00135 self.assertEqual("os_version", osa.get_version())
00136 os_class = osa.get_os()
00137 self.assertEqual("os_name", os_class.get_name())
00138 self.assertEqual("os_version", os_class.get_version())
00139
00140 def test_ubuntu_in_OSA(self):
00141 ubuntu = roslib.os_detect.Ubuntu()
00142 def return_true():
00143 return True
00144 ubuntu.check_presence = return_true
00145 osa = roslib.os_detect.OSDetect([ubuntu])
00146 self.assertEqual("ubuntu", ubuntu.get_name())
00147 os_class = osa.get_os()
00148 self.assertEqual("ubuntu", os_class.get_name())
00149
00150
00151
00152 if __name__ == '__main__':
00153 rosunit.unitrun('test_roslib', 'test_os_detect', RoslibOsDetectTest, coverage_packages=['roslib.os_detect'])
00154