test_scripts.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import shutil
5 import subprocess
6 import tempfile
7 import unittest
8 
9 PKG_PATH = os.getcwd()
10 TEST_PATH = os.path.join(PKG_PATH, 'test')
11 
12 
13 def make_bash_pre_command(strings, currentword):
14  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)
15 
16 
17 class TestRosBash(unittest.TestCase):
18 
19  def setUp(self):
20  self.cmdbash = os.path.join(TEST_PATH, 'test_rosbash.bash')
21  self.assertTrue(os.path.exists(self.cmdbash))
22 
23  self.cmdzsh = os.path.join(TEST_PATH, 'test_roszsh.zsh')
24  self.assertTrue(os.path.exists(self.cmdzsh))
25 
27  subprocess.check_call([self.cmdbash], cwd=TEST_PATH)
28 
30  subprocess.check_call([self.cmdzsh], cwd=TEST_PATH)
31 
32 
33 class TestWithFiles(unittest.TestCase):
34 
35  @classmethod
36  def setUpClass(self):
37  self.test_root_path = tempfile.mkdtemp()
38 
39  @classmethod
40  def tearDownClass(self):
41  shutil.rmtree(self.test_root_path)
42 
44  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))
45  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))
46 
48  # regression test that roslaunch completion works even in the presence of launchfiles
49  subprocess.check_call('touch foo.launch', shell=True, cwd=self.test_root_path)
50  subprocess.check_call('touch bar.launch', shell=True, cwd=self.test_root_path)
51 
52  cmd = make_bash_pre_command(['rosbash', 'rosbash'], 2)
53  cmd += "_roscomplete_launch rosbash rosbash; echo $COMPREPLY'"
54  p = subprocess.Popen(cmd,
55  shell=True,
56  stdout=subprocess.PIPE,
57  cwd=self.test_root_path)
58  output = p.communicate()
59  self.assertEqual(0, p.returncode, (p.returncode, output, cmd))
60 
61  self.assertTrue('example.launch' in output[0], (p.returncode, output[0], cmd))
def test_roslaunch_completion(self)
Definition: test_scripts.py:47
def test_roszsh_completion(self)
Definition: test_scripts.py:29
def make_bash_pre_command(strings, currentword)
Definition: test_scripts.py:13
def test_rosbash_completion(self)
Definition: test_scripts.py:26


rosbash
Author(s): Jeremy Leibs, Thibault Kruse
autogenerated on Thu Apr 30 2020 06:30:12