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_rosdep')
00033
00034 import os
00035 import struct
00036 import sys
00037 import unittest
00038
00039 import rosunit
00040 import rosdep.core
00041
00042
00043 class RosdepYamlCacheTest(unittest.TestCase):
00044 def test_YamlCache_init(self):
00045 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00046
00047 def test_YamlCache_get_yaml(self):
00048 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00049 yaml_dict = yc.get_yaml(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00050
00051 yaml_truth = {'other_rosdep_test':
00052 {'rosdep_test_os':
00053 {'other_version': 'foo'}
00054 },
00055 'no_os_rosdep_test':
00056 {'other_os': 'not_useful'
00057 },
00058 'zlib':
00059 {'rosdep_test_os': 'zlib1g-dev',
00060 'debian': 'zlib1g-dev'
00061 },
00062 'rosdep_test':
00063 {'rosdep_test_os':
00064 {'rosdep_test_version': 'librosdep_test1.37-dev',
00065 '9.10': 'librosdep_test1.40-all-dev',
00066 '8.10': 'this is a script\n'
00067 }
00068 }
00069 }
00070 self.assertEqual(yaml_dict, yaml_truth)
00071
00072 def test_YamlCache_get_yaml_repeated(self):
00073 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00074 yaml_dict = yc.get_yaml(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00075 yaml_dict2 = yc.get_yaml(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00076 self.assertEqual(yaml_dict, yaml_dict2)
00077
00078 yaml_truth = {'other_rosdep_test':
00079 {'rosdep_test_os':
00080 {'other_version': 'foo'}
00081 },
00082 'no_os_rosdep_test':
00083 {'other_os': 'not_useful'
00084 },
00085 'zlib':
00086 {'rosdep_test_os': 'zlib1g-dev',
00087 'debian': 'zlib1g-dev'
00088 },
00089 'rosdep_test':
00090 {'rosdep_test_os':
00091 {'rosdep_test_version': 'librosdep_test1.37-dev',
00092 '9.10': 'librosdep_test1.40-all-dev',
00093 '8.10': 'this is a script\n'
00094 }
00095 }
00096 }
00097 self.assertEqual(yaml_dict2, yaml_truth)
00098
00099 def test_YamlCache_rosstack_depends(self):
00100 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00101 depends = yc.get_rosstack_depends("ros")
00102 depends2 = yc.get_rosstack_depends("ros")
00103 self.assertEqual(depends, depends2)
00104
00105 def test_YamlCache_no_file(self):
00106 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00107 self.assertEqual({}, yc.get_yaml("non_extant_rosdep.yaml"))
00108
00109 def test_YamlCache_parse_failure(self):
00110 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00111 self.assertEqual({}, yc.get_yaml(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "invalid_rosdep.yaml")))
00112
00113 def test_YamlCache_get_specific_rosdeps(self):
00114 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00115 yaml_dict = yc.get_specific_rosdeps(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00116 print "yaml_dict", yaml_dict
00117 yaml_truth = {
00118 'zlib': 'zlib1g-dev',
00119 'rosdep_test':'librosdep_test1.37-dev',
00120 }
00121 self.assertEqual(yaml_dict, yaml_truth)
00122
00123 def test_YamlCache_get_specific_rosdeps_repeated(self):
00124 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00125 yaml_dict = yc.get_specific_rosdeps(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00126 yaml_dict2 = yc.get_specific_rosdeps(os.path.join(roslib.packages.get_pkg_dir("test_rosdep"), "test", "example_rosdep.yaml"))
00127 self.assertEqual(yaml_dict, yaml_dict2)
00128
00129 yaml_truth = {
00130 'zlib': 'zlib1g-dev',
00131 'rosdep_test':'librosdep_test1.37-dev',
00132 }
00133 self.assertEqual(yaml_dict2, yaml_truth)
00134
00135 def test_RosdepLookupPackage_get_os_from_yaml(self):
00136 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00137 yaml_os_map = {"rosdep_test_os":"one", "other":"two", "three":"three"};
00138 output = yc.get_os_from_yaml("rosdep_name", yaml_os_map, "source_path")
00139 self.assertEqual("one", output)
00140
00141 def test_RosdepLookupPackage_get_version_from_yaml(self):
00142 yc = rosdep.core.YamlCache("rosdep_test_os", "rosdep_test_version")
00143 yaml_map = {"8.04":"one", "rosdep_test_version":"two", "three":"three"};
00144 output = yc.get_version_from_yaml("rosdep_name", yaml_map, "source_path" )
00145 self.assertEqual("two", output)
00146
00147
00148
00149 if __name__ == '__main__':
00150 rosunit.unitrun('test_rosdep', 'test_yaml_cache', RosdepYamlCacheTest, coverage_packages=['rosdep.core'])
00151