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 RoslibManifestlibTest(unittest.TestCase):
00042
00043 def test_ManifestException(self):
00044 from roslib.manifestlib import ManifestException
00045 self.assert_(isinstance(ManifestException(), Exception))
00046
00047 def test_Platform(self):
00048 from roslib.manifestlib import Platform, ManifestException
00049 for bad in [None, '', 1]:
00050 try:
00051 Platform(bad, '1')
00052 self.fail("should have failed on [%s]"%bad)
00053 except ValueError: pass
00054 try:
00055 Platform('ubuntu', bad)
00056 self.fail("should have failed on [%s]"%bad)
00057 except ValueError: pass
00058
00059 p = Platform('ubuntu', '8.04')
00060 self.assertEquals('ubuntu 8.04', str(p))
00061 self.assertEquals('ubuntu 8.04', repr(p))
00062
00063 self.assertEquals('<platform os="ubuntu" version="8.04"/>',p.xml())
00064 self.assertEquals(p, Platform('ubuntu', '8.04'))
00065 self.assertEquals(p, Platform('ubuntu', '8.04', notes=None))
00066 self.assertNotEquals(p, Platform('ubuntu', '8.04', 'some notes'))
00067 self.assertNotEquals(p, 'foo')
00068 self.assertNotEquals(p, 1)
00069
00070
00071 p = Platform('OS X', '10.6', 'macports')
00072 self.assertEquals('OS X 10.6', str(p))
00073 self.assertEquals('OS X 10.6', repr(p))
00074
00075 self.assertEquals('<platform os="OS X" version="10.6" notes="macports"/>',p.xml())
00076 self.assertEquals(p, p)
00077 self.assertEquals(p, Platform('OS X', '10.6', 'macports'))
00078 self.assertNotEquals(p, Platform('OS X', '10.6'))
00079 self.assertNotEquals(p, 'foo')
00080 self.assertNotEquals(p, 1)
00081
00082
00083 def test_Depend(self):
00084 from roslib.manifestlib import Depend, StackDepend, ManifestException
00085 for bad in [None, '', 1]:
00086 try:
00087 Depend(bad)
00088 self.fail("should have failed on [%s]"%bad)
00089 except ValueError: pass
00090
00091 d = Depend('roslib')
00092 self.assertEquals('roslib', str(d))
00093 self.assertEquals('roslib', repr(d))
00094
00095 self.assertEquals('<depend package="roslib" />',d.xml())
00096 self.assertEquals(d, Depend('roslib'))
00097 self.assertNotEquals(d, StackDepend('roslib'))
00098 self.assertNotEquals(d, Depend('roslib2'))
00099 self.assertNotEquals(d, 1)
00100
00101 def test_StackDepend(self):
00102 from roslib.manifestlib import Depend, StackDepend, ManifestException
00103 for bad in [None, '', 1]:
00104 try:
00105 StackDepend(bad)
00106 self.fail("should have failed on [%s]"%bad)
00107 except ValueError: pass
00108
00109 d = StackDepend('common')
00110 self.assertEquals('common', str(d))
00111 self.assertEquals('common', repr(d))
00112
00113 self.assertEquals('<depend stack="common" />',d.xml())
00114 self.assertEquals(d, StackDepend('common'))
00115 self.assertNotEquals(d, Depend('common'))
00116 self.assertNotEquals(d, StackDepend('common2'))
00117 self.assertNotEquals(d, 1)
00118
00119 def test_ROSDep(self):
00120 from roslib.manifestlib import ROSDep, ManifestException
00121 for bad in [None, '', 1]:
00122 try:
00123 rd = ROSDep(bad)
00124 self.fail("should have failed on [%s]"%bad)
00125 except ValueError: pass
00126
00127 rd = ROSDep('python')
00128 self.assertEquals('<rosdep name="python" />',rd.xml())
00129
00130 def test_VersionControl(self):
00131 from roslib.manifestlib import VersionControl, ManifestException
00132 ros_svn = 'https://ros.svn.sf.net/svnroot'
00133
00134 bad = [
00135 (None, ros_svn),
00136 ('svn', 1),
00137 ]
00138 for type_, url in bad:
00139 try:
00140 VersionControl(type_,url)
00141 self.fail("should have failed on [%s] [%s]"%(type_, url))
00142 except ValueError: pass
00143
00144 tests = [
00145 ('svn', ros_svn, '<versioncontrol type="svn" url="%s" />'%ros_svn),
00146 ('cvs', None, '<versioncontrol type="cvs" />'),
00147 ]
00148 for type_, url, xml in tests:
00149 vc = VersionControl(type_, url)
00150 self.assertEquals(type_, vc.type)
00151 self.assertEquals(url, vc.url)
00152 self.assertEquals(xml, vc.xml())
00153
00154 def _subtest_parse_example1(self, m):
00155 from roslib.manifestlib import _Manifest
00156 self.assert_(isinstance(m, _Manifest))
00157 self.assertEquals("a brief description", m.brief)
00158 self.assertEquals("Line 1\nLine 2", m.description.strip())
00159 self.assertEquals("The authors\ngo here", m.author.strip())
00160 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00161 self.assertEquals("http://pr.willowgarage.com/package/", m.url)
00162 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00163 dpkgs = [d.package for d in m.depends]
00164 self.assertEquals(set(['pkgname', 'common']), set(dpkgs))
00165 rdpkgs = [d.name for d in m.rosdeps]
00166 self.assertEquals(set(['python', 'bar', 'baz']), set(rdpkgs))
00167 for p in m.platforms:
00168 if p.os == 'ubuntu':
00169 self.assertEquals("8.04", p.version)
00170 self.assertEquals('', p.notes)
00171 elif p.os == 'OS X':
00172 self.assertEquals("10.6", p.version)
00173 self.assertEquals("macports", p.notes)
00174 else:
00175 self.fail("unknown platform "+str(p))
00176
00177 def _subtest_parse_stack_example1(self, m):
00178 from roslib.manifestlib import _Manifest
00179 self.assert_(isinstance(m, _Manifest))
00180 self.assertEquals('stack', m._type)
00181 self.assertEquals("a brief description", m.brief)
00182 self.assertEquals("Line 1\nLine 2", m.description.strip())
00183 self.assertEquals("The authors\ngo here", m.author.strip())
00184 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00185 self.assertEquals("http://ros.org/stack/", m.url)
00186 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00187 dpkgs = [d.stack for d in m.depends]
00188 self.assertEquals(set(['stackname', 'common']), set(dpkgs))
00189 self.assertEquals([], m.rosdeps)
00190 self.assertEquals([], m.exports)
00191
00192 def test_parse_example1_file(self):
00193 from roslib.manifestlib import parse_file, _Manifest
00194 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'example1.xml')
00195 self._subtest_parse_example1(parse_file(_Manifest(), p))
00196
00197 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'stack_example1.xml')
00198 self._subtest_parse_stack_example1(parse_file(_Manifest('stack'), p))
00199
00200 def test_parse_example1_string(self):
00201 from roslib.manifestlib import parse, _Manifest
00202 self._subtest_parse_example1(parse(_Manifest(), EXAMPLE1))
00203 self._subtest_parse_stack_example1(parse(_Manifest('stack'), STACK_EXAMPLE1))
00204
00205 def test__Manifest(self):
00206 from roslib.manifestlib import _Manifest
00207 m = _Manifest()
00208
00209 self.assertEquals('package', m._type)
00210 m = _Manifest('stack')
00211 self.assertEquals('stack', m._type)
00212
00213 def test_Manifest_str(self):
00214
00215 from roslib.manifestlib import parse, _Manifest
00216 str(parse(_Manifest(), EXAMPLE1))
00217
00218 def test_Manifest_xml(self):
00219 from roslib.manifestlib import parse, _Manifest
00220 m = _Manifest()
00221 parse(m, EXAMPLE1)
00222 self._subtest_parse_example1(m)
00223
00224 m2 = _Manifest()
00225 parse(m2, m.xml())
00226 self._subtest_parse_example1(m2)
00227
00228
00229 def test_parse_bad_file(self):
00230 from roslib.manifestlib import parse_file, _Manifest, ManifestException
00231 my_dir = roslib.packages.get_pkg_dir('test_roslib')
00232 base_p = os.path.join(my_dir, 'test', 'manifest_tests')
00233 m = _Manifest()
00234 for b in ['bad1.xml', 'bad2.xml', 'bad3.xml']:
00235 p = os.path.join(base_p, b)
00236 try:
00237 parse_file(m, p)
00238 self.fail("parse should have failed on bad manifest")
00239 except ManifestException, e:
00240 print str(e)
00241 self.assert_(b in str(e), "file name should be in error message [%s]"%(str(e)))
00242
00243 EXAMPLE1 = """<package>
00244 <description brief="a brief description">Line 1
00245 Line 2
00246 </description>
00247 <author>The authors
00248 go here</author>
00249 <license>Public Domain
00250 with other stuff</license>
00251 <url>http://pr.willowgarage.com/package/</url>
00252 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00253 <depend package="pkgname" />
00254 <depend package="common"/>
00255 <export>
00256 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00257 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00258 </export>
00259 <rosdep name="python" />
00260 <rosdep name="bar" />
00261 <rosdep name="baz" />
00262 <platform os="ubuntu" version="8.04" />
00263 <platform os="OS X" version="10.6" notes="macports" />
00264 </package>"""
00265
00266 STACK_EXAMPLE1 = """<stack>
00267 <description brief="a brief description">Line 1
00268 Line 2
00269 </description>
00270 <author>The authors
00271 go here</author>
00272 <license>Public Domain
00273 with other stuff</license>
00274 <url>http://ros.org/stack/</url>
00275 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00276 <depend stack="stackname" />
00277 <depend stack="common"/>
00278 </stack>"""
00279
00280 STACK_INVALID1 = """<stack>
00281 <description brief="a brief description">Line 1</description>
00282 <author>The authors</author>
00283 <license>Public Domain</license>
00284 <rosdep name="python" />
00285 </stack>"""
00286
00287 STACK_INVALID2 = """<stack>
00288 <description brief="a brief description">Line 1</description>
00289 <author>The authors</author>
00290 <license>Public Domain</license>
00291 <export>
00292 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00293 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00294 </export>
00295 </stack>"""
00296
00297
00298 if __name__ == '__main__':
00299 rosunit.unitrun('test_roslib', 'test_manifest', RoslibManifestlibTest, coverage_packages=['roslib.manifestlib'])
00300