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 # https://stackoverflow.com/questions/10971033/backporting-python-3-openencoding-utf-8-to-python-2
7 if sys.version_info[0] > 2:
8  # py3k
9  pass
10 else:
11  # py2
12  import __builtin__
13  def open(filename, encoding=None):
14  return __builtin__.open(filename)
15 
16 pkg_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), os.pardir, os.pardir))
17 pkg_name = os.path.basename(pkg_dir)
18 
19 class TestRospyNode(unittest.TestCase):
20 
21  def __init__(self, *args):
22  unittest.TestCase.__init__(self, *args)
23 
24  def test_rosnode(self):
25  __name__ = 'dummy'
26  for scripts_dir in ['scripts', 'node_scripts']:
27  full_scripts_dir = os.path.join(pkg_dir, scripts_dir)
28  if not os.path.exists(full_scripts_dir):
29  continue
30  for filename in [f for f in map(lambda x: os.path.join(full_scripts_dir, x), os.listdir(full_scripts_dir)) if os.path.isfile(f) and f.endswith('.py')]:
31  print("Check if {} is loadable".format(filename))
32  # https://stackoverflow.com/questions/4484872/why-doesnt-exec-work-in-a-function-with-a-subfunction
33  exec(open(filename, encoding='utf-8').read()) in globals(), locals()
34  self.assertTrue(True)
35 
36 if __name__ == '__main__':
37  rostest.rosrun('test_rospy_node', pkg_name, TestRospyNode, sys.argv)
def open(filename, encoding=None)


nfc_ros
Author(s): Koki Shinjo
autogenerated on Sat Jun 24 2023 02:40:29