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, '']:
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, '']:
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 ]
00082 for type_, url in bad:
00083 try:
00084 VersionControl(type_,url)
00085 self.fail("should have failed on [%s] [%s]"%(type_, url))
00086 except ValueError: pass
00087
00088 tests = [
00089 ('svn', ros_svn, '<versioncontrol type="svn" url="%s" />'%ros_svn),
00090 ('cvs', None, '<versioncontrol type="cvs" />'),
00091 ]
00092 for type_, url, xml in tests:
00093 vc = VersionControl(type_, url)
00094 self.assertEquals(type_, vc.type)
00095 self.assertEquals(url, vc.url)
00096 self.assertEquals(xml, vc.xml())
00097
00098 def _subtest_parse_example1(self, m):
00099 from roslib.manifest import Manifest
00100 self.assert_(isinstance(m, Manifest))
00101 self.assertEquals("a brief description", m.brief)
00102 self.assertEquals("Line 1\nLine 2", m.description.strip())
00103 self.assertEquals("The authors\ngo here", m.author.strip())
00104 self.assertEquals("Public Domain\nwith other stuff", m.license.strip())
00105 self.assertEquals("http://pr.willowgarage.com/package/", m.url)
00106 self.assertEquals("http://www.willowgarage.com/files/willowgarage/robot10.jpg", m.logo)
00107 dpkgs = [d.package for d in m.depends]
00108 self.assertEquals(set(['pkgname', 'common']), set(dpkgs))
00109 rdpkgs = [d.name for d in m.rosdeps]
00110 self.assertEquals(set(['python', 'bar', 'baz']), set(rdpkgs))
00111
00112 def test_parse_example1_file(self):
00113 from roslib.manifest import parse_file, Manifest
00114 p = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'manifest_tests', 'example1.xml')
00115 self._subtest_parse_example1(parse_file(p))
00116
00117 def test_parse_example1_string(self):
00118 from roslib.manifest import parse, Manifest
00119 self._subtest_parse_example1(parse(EXAMPLE1))
00120
00121 def test_Manifest_str(self):
00122
00123 from roslib.manifest import parse
00124 str(parse(EXAMPLE1))
00125
00126 def test_Manifest_xml(self):
00127 from roslib.manifest import parse
00128 m = parse(EXAMPLE1)
00129 self._subtest_parse_example1(m)
00130
00131 m2 = parse(m.xml())
00132 self._subtest_parse_example1(m2)
00133
00134
00135 def test_parse_bad_file(self):
00136 from roslib.manifest import parse_file, Manifest
00137
00138 from roslib.manifestlib import ManifestException
00139 my_dir = roslib.packages.get_pkg_dir('test_roslib')
00140 base_p = os.path.join(my_dir, 'test', 'manifest_tests')
00141 for b in ['bad1.xml', 'bad2.xml', 'bad3.xml']:
00142 p = os.path.join(base_p, b)
00143 try:
00144 parse_file(p)
00145 self.fail("parse should have failed on bad manifest")
00146 except ManifestException, e:
00147 print str(e)
00148 self.assert_(b in str(e), "file name should be in error message: %s"%(str(e)))
00149
00150 EXAMPLE1 = """<package>
00151 <description brief="a brief description">Line 1
00152 Line 2
00153 </description>
00154 <author>The authors
00155 go here</author>
00156 <license>Public Domain
00157 with other stuff</license>
00158 <url>http://pr.willowgarage.com/package/</url>
00159 <logo>http://www.willowgarage.com/files/willowgarage/robot10.jpg</logo>
00160 <depend package="pkgname" />
00161 <depend package="common"/>
00162 <export>
00163 <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lros"/>
00164 <cpp os="osx" cflags="-I${prefix}/include" lflags="-L${prefix}/lib -lrosthread -framework CoreServices"/>
00165 </export>
00166 <rosdep name="python" />
00167 <rosdep name="bar" />
00168 <rosdep name="baz" />
00169 <rosbuild2>
00170 <depend thirdparty="thisshouldbeokay"/>
00171 </rosbuild2>
00172 </package>"""
00173
00174
00175
00176 if __name__ == '__main__':
00177 rosunit.unitrun('test_roslib', 'test_manifest', RoslibManifestTest, coverage_packages=['roslib.manifest', 'roslib.manifestlib'])
00178