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 import roslib; roslib.load_manifest('test_roslib')
00033
00034 import os
00035 import struct
00036 import sys
00037 import unittest
00038
00039 import rosunit
00040
00041 class RoslibManifestTest(unittest.TestCase):
00042
00043 def test_ManifestException(self):
00044 from roslib.manifest import ManifestException
00045 self.assert_(isinstance(ManifestException(), Exception))
00046
00047 def test_Depend(self):
00048 from roslib.manifestlib import Depend, ManifestException
00049 for bad in [None, '', 1]:
00050 try:
00051 Depend(bad)
00052 self.fail("should have failed on [%s]"%bad)
00053 except ValueError: pass
00054
00055 d = Depend('roslib')
00056 self.assertEquals('roslib', str(d))
00057 self.assertEquals('roslib', repr(d))
00058
00059 self.assertEquals('<depend package="roslib" />',d.xml())
00060 self.assertEquals(d, Depend('roslib'))
00061 self.assertNotEquals(d, Depend('roslib2'))
00062 self.assertNotEquals(d, 1)
00063
00064 def test_ROSDep(self):
00065 from roslib.manifest import ROSDep, ManifestException
00066 for bad in [None, '', 1]:
00067 try:
00068 rd = ROSDep(bad)
00069 self.fail("should have failed on [%s]"%bad)
00070 except ValueError: pass
00071
00072 rd = ROSDep('python')
00073 self.assertEquals('<rosdep name="python" />',rd.xml())
00074
00075 def test_VersionControl(self):
00076 from roslib.manifest import VersionControl, ManifestException
00077 ros_svn = 'https://ros.svn.sf.net/svnroot'
00078
00079 bad = [
00080 (None, ros_svn),
00081 ('svn', 1),
00082 ]
00083 for type_, url in bad:
00084 try:
00085 VersionControl(type_,url)
00086 self.fail("should have failed on [%s] [%s]"%(type_, url))
00087 except ValueError: pass
00088
00089 tests = [
00090 ('svn', ros_svn, '<versioncontrol type="svn" url="%s" />'%ros_svn),
00091 ('cvs', None, '<versioncontrol type="cvs" />'),
00092 ]
00093 for type_, url, xml in tests:
00094 vc = VersionControl(type_, url)
00095 self.assertEquals(type_, vc.type)
00096 self.assertEquals(url, vc.url)
00097 self.assertEquals(xml, vc.xml())
00098
00099 def _subtest_parse_example1(self, m):
00100 from roslib.manifest import Manifest
00101 self.assert_(isinstance(m, Manifest))
00102 self.assertEquals("a brief description", m.brief)
00103 self.assertEquals("Line 1\nLine 2", m.description.strip())
00104 self.assertEquals("The authors\ngo here", m.author.strip())
00105 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00106 self.assertEquals("http://pr.willowgarage.com/package/", m.url)
00107 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00108 dpkgs = [d.package for d in m.depends]
00109 self.assertEquals(set(['pkgname', 'common']), set(dpkgs))
00110 rdpkgs = [d.name for d in m.rosdeps]
00111 self.assertEquals(set(['python', 'bar', 'baz']), set(rdpkgs))
00112
00113 def test_parse_example1_file(self):
00114 from roslib.manifest import parse_file, Manifest
00115 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'example1.xml')
00116 self._subtest_parse_example1(parse_file(p))
00117
00118 def test_parse_example1_string(self):
00119 from roslib.manifest import parse, Manifest
00120 self._subtest_parse_example1(parse(EXAMPLE1))
00121
00122 def test_Manifest_str(self):
00123
00124 from roslib.manifest import parse
00125 str(parse(EXAMPLE1))
00126
00127 def test_Manifest_xml(self):
00128 from roslib.manifest import parse
00129 m = parse(EXAMPLE1)
00130 self._subtest_parse_example1(m)
00131
00132 m2 = parse(m.xml())
00133 self._subtest_parse_example1(m2)
00134
00135
00136 def test_parse_bad_file(self):
00137 from roslib.manifest import parse_file, Manifest
00138
00139 from roslib.manifestlib import ManifestException
00140 my_dir = roslib.packages.get_pkg_dir('test_roslib')
00141 base_p = os.path.join(my_dir, 'test', 'manifest_tests')
00142 for b in ['bad1.xml', 'bad2.xml', 'bad3.xml']:
00143 p = os.path.join(base_p, b)
00144 try:
00145 parse_file(p)
00146 self.fail("parse should have failed on bad manifest")
00147 except ManifestException, e:
00148 print str(e)
00149 self.assert_(b in str(e), "file name should be in error message: %s"%(str(e)))
00150
00151 EXAMPLE1 = """<package>
00152 <description brief="a brief description">Line 1
00153 Line 2
00154 </description>
00155 <author>The authors
00156 go here</author>
00157 <license>Public Domain
00158 with other stuff</license>
00159 <url>http://pr.willowgarage.com/package/</url>
00160 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00161 <depend package="pkgname" />
00162 <depend package="common"/>
00163 <export>
00164 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00165 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00166 </export>
00167 <rosdep name="python" />
00168 <rosdep name="bar" />
00169 <rosdep name="baz" />
00170 </package>"""
00171
00172
00173
00174 if __name__ == '__main__':
00175 rosunit.unitrun('test_roslib', 'test_manifest', RoslibManifestTest, coverage_packages=['roslib.manifest', 'roslib.manifestlib'])
00176