4 import os, sys, unittest, rostest
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')
13 if sys.version_info[0] > 2:
19 def open(filename, encoding=None):
20 return __builtin__.open(filename)
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)
29 unittest.TestCase.__init__(self, *args)
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):
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))
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)
47 if __name__ ==
'__main__':
48 rostest.rosrun(
'test_rospy_node', pkg_name, TestRospyNode, sys.argv)
def open(filename, encoding=None)