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
00033
00034
00035 from __future__ import with_statement
00036
00037 PKG = 'test_rxdeps'
00038 import roslib; roslib.load_manifest(PKG)
00039
00040 import os
00041 import unittest
00042 import tempfile
00043 import shutil
00044 from subprocess import Popen, PIPE
00045
00046 ROS_ROOT = 'ROS_ROOT'
00047 ROS_PACKAGE_PATH = 'ROS_PACKAGE_PATH'
00048 ROS_LANG_DISABLE = 'ROS_LANG_DISABLE'
00049
00050
00051 class RxdepsTestCase(unittest.TestCase):
00052
00053 def setUp(self):
00054 self.rxdeps_dir = roslib.packages.get_pkg_dir("rxdeps")
00055 self.pkg_dir = roslib.packages.get_pkg_dir("test_rxdeps")
00056 self.assert_(os.path.isdir(self.pkg_dir), "cannot locate test_rxdeps")
00057 self.test_dir = os.path.join(self.pkg_dir,"test/test_packages")
00058 self.assert_(os.path.isdir(self.test_dir), "cannot locate test dirs")
00059
00060
00061
00062 def _run_rxdeps(self, ros_package_path, pkgname, command):
00063 env = os.environ.copy()
00064 if ros_package_path is not None:
00065 env[ROS_PACKAGE_PATH] = ros_package_path+os.pathsep+self.rxdeps_dir
00066
00067
00068
00069
00070
00071 args = ["rxdeps"]
00072 if command:
00073 for s in command.split():
00074 args.append(s)
00075 if pkgname is not None:
00076 args.append("--target=%s"%pkgname)
00077 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00078 stdout, stderr = p.communicate()
00079
00080
00081
00082 if command:
00083 aliases = {}
00084 cmd = command.split()[-1]
00085 if cmd in aliases:
00086 args[-2] = aliases[cmd]
00087 alias_p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00088 alias_stdout, alias_stderr = alias_p.communicate()
00089 self.assertEquals(p.returncode, alias_p.returncode)
00090 self.assertEquals(stdout, alias_stdout)
00091
00092
00093 return p.returncode, stdout.strip(), stderr
00094
00095
00096 def test_utest(self):
00097 ret, out, err = self._run_rxdeps(self.test_dir, "pkg1", "--graphviz-output=deps.gv")
00098 self.assertTrue(ret == 0)
00099
00100 with open("deps.gv") as fh:
00101 lines = fh.read().split("\n")
00102 self.assertTrue(" \"pkg2\" -> \"pkg1\";" in lines)
00103 self.assertTrue(" \"pkg3\" -> \"pkg2\";" in lines)
00104 self.assertTrue(" \"pkg4\" -> \"pkg2\";" in lines)
00105 self.assertTrue(" \"pkg5\" -> \"pkg3\";" in lines)
00106 self.assertTrue(" \"pkg5\" -> \"pkg4\";" in lines)
00107
00108
00109 os.remove("deps.gv")
00110
00111
00112 self.assertTrue(os.path.exists("deps.pdf"))
00113 os.remove("deps.pdf")
00114
00115 def test_exclude(self):
00116 ret, out, err = self._run_rxdeps(self.test_dir, "pkg1", "--graphviz-output=deps.gv --exclude=pkg2")
00117 self.assertTrue(ret == 0)
00118
00119 with open("deps.gv") as fh:
00120 lines = fh.read().split("\n")
00121 self.assertFalse("pkg2" in lines)
00122 self.assertTrue(" \"pkg5\" -> \"pkg3\";" in lines)
00123 self.assertTrue(" \"pkg5\" -> \"pkg4\";" in lines)
00124
00125
00126 os.remove("deps.gv")
00127
00128
00129 self.assertTrue(os.path.exists("deps.pdf"))
00130 os.remove("deps.pdf")
00131
00132
00133 def test_output_arg(self):
00134 ret, out, err = self._run_rxdeps(self.test_dir, "pkg1", "--graphviz-output=deps.gv -oout.pdf")
00135 self.assertTrue(ret == 0)
00136
00137 with open("deps.gv") as fh:
00138 lines = fh.read().split("\n")
00139 self.assertTrue(" \"pkg2\" -> \"pkg1\";" in lines)
00140 self.assertTrue(" \"pkg3\" -> \"pkg2\";" in lines)
00141 self.assertTrue(" \"pkg4\" -> \"pkg2\";" in lines)
00142 self.assertTrue(" \"pkg5\" -> \"pkg3\";" in lines)
00143 self.assertTrue(" \"pkg5\" -> \"pkg4\";" in lines)
00144
00145
00146
00147 os.remove("deps.gv")
00148
00149
00150 self.assertTrue(os.path.exists("out.pdf"))
00151 os.remove("out.pdf")
00152
00153 def test_usage(self):
00154 ret, out, err = self._run_rxdeps(self.test_dir, "pkg1", "-h")
00155 self.assertTrue(ret == 0)
00156 self.assertEqual(out.count("Usage:"), 1)
00157
00158
00159 if __name__ == '__main__':
00160 import rostest
00161 rostest.unitrun(PKG, 'rxdeps_exe_process', RxdepsTestCase)