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, '']:
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, '']:
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, '']:
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, '']:
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 ]
00137 for type_, url in bad:
00138 try:
00139 VersionControl(type_,url)
00140 self.fail("should have failed on [%s] [%s]"%(type_, url))
00141 except ValueError: pass
00142
00143 tests = [
00144 ('svn', ros_svn, '<versioncontrol type="svn" url="%s" />'%ros_svn),
00145 ('cvs', None, '<versioncontrol type="cvs" />'),
00146 ]
00147 for type_, url, xml in tests:
00148 vc = VersionControl(type_, url)
00149 self.assertEquals(type_, vc.type)
00150 self.assertEquals(url, vc.url)
00151 self.assertEquals(xml, vc.xml())
00152
00153 def _subtest_parse_example1(self, m):
00154 from roslib.manifestlib import _Manifest
00155 self.assert_(isinstance(m, _Manifest))
00156 self.assertEquals("a brief description", m.brief)
00157 self.assertEquals("Line 1\nLine 2", m.description.strip())
00158 self.assertEquals("The authors\ngo here", m.author.strip())
00159 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00160 self.assertEquals("http://pr.willowgarage.com/package/", m.url)
00161 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00162 dpkgs = [d.package for d in m.depends]
00163 self.assertEquals(set(['pkgname', 'common']), set(dpkgs))
00164 rdpkgs = [d.name for d in m.rosdeps]
00165 self.assertEquals(set(['python', 'bar', 'baz']), set(rdpkgs))
00166 for p in m.platforms:
00167 if p.os == 'ubuntu':
00168 self.assertEquals("8.04", p.version)
00169 self.assertEquals('', p.notes)
00170 elif p.os == 'OS X':
00171 self.assertEquals("10.6", p.version)
00172 self.assertEquals("macports", p.notes)
00173 else:
00174 self.fail("unknown platform "+str(p))
00175
00176 def _subtest_parse_stack_example1(self, m):
00177 from roslib.manifestlib import _Manifest
00178 self.assert_(isinstance(m, _Manifest))
00179 self.assertEquals('stack', m._type)
00180 self.assertEquals("a brief description", m.brief)
00181 self.assertEquals("Line 1\nLine 2", m.description.strip())
00182 self.assertEquals("The authors\ngo here", m.author.strip())
00183 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00184 self.assertEquals("http://ros.org/stack/", m.url)
00185 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00186 dpkgs = [d.stack for d in m.depends]
00187 self.assertEquals(set(['stackname', 'common']), set(dpkgs))
00188 self.assertEquals([], m.rosdeps)
00189 self.assertEquals([], m.exports)
00190
00191 def _subtest_parse_stack_version(self, m):
00192 self.assertEquals("1.2.3", m.version)
00193
00194 def test_parse_example1_file(self):
00195 from roslib.manifestlib import parse_file, _Manifest
00196 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'example1.xml')
00197 self._subtest_parse_example1(parse_file(_Manifest(), p))
00198
00199 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'stack_example1.xml')
00200 self._subtest_parse_stack_example1(parse_file(_Manifest('stack'), p))
00201
00202 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'stack_version.xml')
00203 self._subtest_parse_stack_version(parse_file(_Manifest('stack'), p))
00204
00205 def test_parse_example1_string(self):
00206 from roslib.manifestlib import parse, _Manifest
00207 self._subtest_parse_example1(parse(_Manifest(), EXAMPLE1))
00208 self._subtest_parse_stack_example1(parse(_Manifest('stack'), STACK_EXAMPLE1))
00209
00210 def test__Manifest(self):
00211 from roslib.manifestlib import _Manifest
00212 m = _Manifest()
00213
00214 self.assertEquals('package', m._type)
00215 m = _Manifest('stack')
00216 self.assertEquals('stack', m._type)
00217
00218 def test_Manifest_str(self):
00219
00220 from roslib.manifestlib import parse, _Manifest
00221 str(parse(_Manifest(), EXAMPLE1))
00222
00223 def test_Manifest_xml(self):
00224 from roslib.manifestlib import parse, _Manifest
00225 m = _Manifest()
00226 parse(m, EXAMPLE1)
00227 self._subtest_parse_example1(m)
00228
00229 m2 = _Manifest()
00230 parse(m2, m.xml())
00231 self._subtest_parse_example1(m2)
00232
00233
00234 def test_parse_bad_file(self):
00235 from roslib.manifestlib import parse_file, _Manifest, ManifestException
00236 my_dir = roslib.packages.get_pkg_dir('test_roslib')
00237 base_p = os.path.join(my_dir, 'test', 'manifest_tests')
00238 m = _Manifest()
00239 for b in ['bad1.xml', 'bad2.xml', 'bad3.xml']:
00240 p = os.path.join(base_p, b)
00241 try:
00242 parse_file(m, p)
00243 self.fail("parse should have failed on bad manifest")
00244 except ManifestException, e:
00245 print str(e)
00246 self.assert_(b in str(e), "file name should be in error message [%s]"%(str(e)))
00247
00248 EXAMPLE1 = """<package>
00249 <description brief="a brief description">Line 1
00250 Line 2
00251 </description>
00252 <author>The authors
00253 go here</author>
00254 <license>Public Domain
00255 with other stuff</license>
00256 <url>http://pr.willowgarage.com/package/</url>
00257 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00258 <depend package="pkgname" />
00259 <depend package="common"/>
00260 <export>
00261 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00262 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00263 </export>
00264 <rosdep name="python" />
00265 <rosdep name="bar" />
00266 <rosdep name="baz" />
00267 <platform os="ubuntu" version="8.04" />
00268 <platform os="OS X" version="10.6" notes="macports" />
00269 <rosbuild2>
00270 <depend thirdparty="thisshouldbeokay"/>
00271 </rosbuild2>
00272 </package>"""
00273
00274 STACK_EXAMPLE1 = """<stack>
00275 <description brief="a brief description">Line 1
00276 Line 2
00277 </description>
00278 <author>The authors
00279 go here</author>
00280 <license>Public Domain
00281 with other stuff</license>
00282 <url>http://ros.org/stack/</url>
00283 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00284 <depend stack="stackname" />
00285 <depend stack="common"/>
00286 </stack>"""
00287
00288 STACK_INVALID1 = """<stack>
00289 <description brief="a brief description">Line 1</description>
00290 <author>The authors</author>
00291 <license>Public Domain</license>
00292 <rosdep name="python" />
00293 </stack>"""
00294
00295 STACK_INVALID2 = """<stack>
00296 <description brief="a brief description">Line 1</description>
00297 <author>The authors</author>
00298 <license>Public Domain</license>
00299 <export>
00300 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00301 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00302 </export>
00303 </stack>"""
00304
00305
00306 if __name__ == '__main__':
00307 rosunit.unitrun('test_roslib', 'test_manifest', RoslibManifestlibTest, coverage_packages=['roslib.manifestlib'])
00308