test_scripts.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 import subprocess
00005 import unittest
00006 import tempfile
00007 import shutil
00008 
00009 PKG_PATH = os.getcwd()
00010 TEST_PATH = os.path.join(PKG_PATH, 'test')
00011 
00012 def make_bash_pre_command(strings, currentword):
00013     return "bash -c '. %s; export COMP_WORDS=(%s); export COMP_CWORD=%s;"%(os.path.join(PKG_PATH, 'rosbash'), ' '.join(['"%s"'%w for w in strings]), currentword)
00014 
00015 class TestRosBash(unittest.TestCase):
00016 
00017     def setUp(self):
00018         self.cmdbash = os.path.join(TEST_PATH, 'test_rosbash.bash')
00019         self.assertTrue(os.path.exists(self.cmdbash))
00020         
00021         self.cmdzsh = os.path.join(TEST_PATH, 'test_roszsh.zsh')
00022         self.assertTrue(os.path.exists(self.cmdzsh))
00023         
00024     def test_rosbash_completion(self):
00025         subprocess.check_call([self.cmdbash], cwd = TEST_PATH)
00026  
00027     def test_roszsh_completion(self):
00028         subprocess.check_call([self.cmdzsh], cwd = TEST_PATH)
00029 
00030 
00031 class TestWithFiles(unittest.TestCase):
00032 
00033     @classmethod
00034     def setUpClass(self):
00035         self.test_root_path = tempfile.mkdtemp()
00036 
00037     @classmethod
00038     def tearDownClass(self):
00039         shutil.rmtree(self.test_root_path)
00040 
00041     def test_make_precommand(self):
00042         self.assertEqual( "bash -c '. %s; export COMP_WORDS=(\"foo\" \"bar\"); export COMP_CWORD=1;"%os.path.join(PKG_PATH, 'rosbash'), make_bash_pre_command(['foo', 'bar'], 1))
00043         self.assertEqual( "bash -c '. %s; export COMP_WORDS=(\"foo\"); export COMP_CWORD=2;"%os.path.join(PKG_PATH, 'rosbash'), make_bash_pre_command(['foo'], 2))
00044         
00045     def test_roslaunch_completion(self):
00046         # regression test that roslaunch completion works even in the presence of launchfiles
00047         subprocess.check_call("touch foo.launch", shell=True, cwd=self.test_root_path)
00048         subprocess.check_call("touch bar.launch", shell=True, cwd=self.test_root_path)
00049 
00050         cmd = make_bash_pre_command(['rosbash', 'rosbash'], 2)
00051         cmd += "_roscomplete_launch rosbash rosbash; echo $COMPREPLY'"
00052         p = subprocess.Popen(cmd,
00053                              shell=True,
00054                              stdout=subprocess.PIPE,
00055                              cwd=self.test_root_path)
00056         output = p.communicate()
00057         self.assertEqual(0, p.returncode, (p.returncode, output, cmd))
00058         
00059         self.assertTrue('example.launch' in output[0], (p.returncode, output[0], cmd))


rosbash
Author(s): Jeremy Leibs, Thibault Kruse
autogenerated on Sat Jun 8 2019 20:33:18