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


rosbash
Author(s): Jeremy Leibs, Thibault Kruse
autogenerated on Tue Apr 2 2019 02:14:11