test_rospy_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import os, sys, unittest, rostest
5 
6 try:
7  from respeaker_ros import *
8 except RuntimeError as e:
9  print("Catch runtime error ({}), check if this is expected".format(e.args[0]))
10  assert(e.args[0] == 'Check the device is connected and recognized')
11 
12 # https://stackoverflow.com/questions/10971033/backporting-python-3-openencoding-utf-8-to-python-2
13 if sys.version_info[0] > 2:
14  # py3k
15  pass
16 else:
17  # py2
18  import __builtin__
19  def open(filename, encoding=None):
20  return __builtin__.open(filename)
21 
22 pkg_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), os.pardir, os.pardir))
23 pkg_name = os.path.basename(pkg_dir)
24 
25 
26 class TestRospyNode(unittest.TestCase):
27 
28  def __init__(self, *args):
29  unittest.TestCase.__init__(self, *args)
30 
31  def test_rosnode(self):
32  __name__ = 'dummy'
33  for scripts_dir in ['scripts', 'node_scripts']:
34  full_scripts_dir = os.path.join(pkg_dir, scripts_dir)
35  if not os.path.exists(full_scripts_dir):
36  continue
37  for filename in [f for f in map(lambda x: x, os.listdir(full_scripts_dir)) if os.path.isfile(f) and f.endswith('.py')]:
38  print("Check if {} is loadable".format(filename))
39  import subprocess
40  try:
41  ret = subprocess.check_output(['rosrun', pkg_name, filename], stderr=subprocess.STDOUT)
42  except subprocess.CalledProcessError as e:
43  print("Catch runtime error ({}), check if this is expect".format(e.output))
44  self.assertTrue('Check the device is connected and recognized' in e.output)
45 
46 
47 if __name__ == '__main__':
48  rostest.rosrun('test_rospy_node', pkg_name, TestRospyNode, sys.argv)
def open(filename, encoding=None)


respeaker_ros
Author(s): Yuki Furuta
autogenerated on Sat Jun 24 2023 02:40:34