From eba1148bf378f8b928c7ce45ba13a9abe2725dc0 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Tue, 24 Dec 2024 12:14:45 +0100 Subject: [PATCH] Clean up rostest (#101) --- ros/test.py.tpl | 1 + third_party/ros/rostest/rostest_main.py | 22 +---------- third_party/ros/rostest/rostest_parent.py | 45 +++-------------------- third_party/ros/rostest/runner.py | 11 +----- 4 files changed, 9 insertions(+), 70 deletions(-) diff --git a/ros/test.py.tpl b/ros/test.py.tpl index 88d3b51..b045ba7 100644 --- a/ros/test.py.tpl +++ b/ros/test.py.tpl @@ -6,6 +6,7 @@ from third_party.ros.rostest import rostest_main test_outputs_dir = os.environ['TEST_UNDECLARED_OUTPUTS_DIR'] os.environ['ROS_LOG_DIR'] = test_outputs_dir os.environ['ROS_TEST_RESULTS_DIR'] = test_outputs_dir +os.environ['ROS_HOSTNAME'] = 'localhost' LAUNCH_FILE = {launch_file} diff --git a/third_party/ros/rostest/rostest_main.py b/third_party/ros/rostest/rostest_main.py index 881cc6a..b80ee3b 100644 --- a/third_party/ros/rostest/rostest_main.py +++ b/third_party/ros/rostest/rostest_main.py @@ -90,27 +90,8 @@ def rostestmain(): dest='results_filename', default=None, help='results_filename') - parser.add_option( - '-r', - '--reuse-master', - action='store_true', - help= - 'Connect to an existing ROS master instead of spawning a new ROS master on a custom port' - ) - parser.add_option( - '-c', - '--clear', - action='store_true', - help= - 'Clear all parameters when connecting to an existing ROS master (only works with --reuse-master)' - ) (options, args) = parser.parse_args() - if options.clear and not options.reuse_master: - print('The --clear option is only valid with --reuse-master', - file=sys.stderr) - sys.exit(1) - try: args = roslaunch.rlutil.resolve_launch_arguments(args) except roslaunch.core.RLException as e: @@ -149,8 +130,7 @@ def rostestmain(): results_file) try: - testCase = runner.createUnitTest(test_file, options.reuse_master, - options.clear, results_dir) + testCase = runner.createUnitTest(test_file, results_dir) suite = unittest.TestLoader().loadTestsFromTestCase(testCase) if options.text_mode: diff --git a/third_party/ros/rostest/rostest_parent.py b/third_party/ros/rostest/rostest_parent.py index 360fba5..0451539 100644 --- a/third_party/ros/rostest/rostest_parent.py +++ b/third_party/ros/rostest/rostest_parent.py @@ -33,7 +33,6 @@ # Revision $Id$ # pylint: disable=raise-missing-from,consider-using-f-string,invalid-name # pylint: disable=line-too-long -import rosgraph from rosmaster.master import Master from third_party.ros.roslaunch import core @@ -42,50 +41,17 @@ class ROSTestLaunchParent(parent.ROSLaunchParent): - def __init__(self, - config, - roslaunch_files, - port=0, - reuse_master=False, - clear=False): + def __init__(self, config, roslaunch_files, port=0): if config is None: raise Exception('config not initialized') # we generate a run_id for each test - if reuse_master: - param_server = rosgraph.Master('/roslaunch') - try: - run_id = param_server.getParam('/run_id') - except Exception as e: - # The user asked us to connect to an existing ROS master, and - # we can't. Throw an exception and die - raise Exception('Could not connect to existing ROS master. ' + - 'Original exception was: %s' % str(e)) - except: - # oh boy; we got something that wasn't an exception. - # Throw an exception and die - raise Exception('Could not connect to existing ROS master.') - - if clear: - params = param_server.getParamNames() - # whitelist of parameters to keep - whitelist = ['/run_id', '/rosversion', '/rosdistro'] - for i in reversed(range(len(params))): - param = params[i] - if param in whitelist: - del params[i] - elif param.startswith('/roslaunch/'): - del params[i] - for param in params: - param_server.deleteParam(param) - else: - run_id = core.generate_run_id() + run_id = core.generate_run_id() super(ROSTestLaunchParent, self).__init__(run_id, roslaunch_files, is_core=False, is_rostest=True) self.config = config self.port = port - self.reuse_master = reuse_master self.master = None def _load_config(self): @@ -97,10 +63,9 @@ def setUp(self): initializes self.config and xmlrpc infrastructure """ self._start_infrastructure() - if not self.reuse_master: - self.master = Master(port=self.port) - self.master.start() - self.config.master.uri = self.master.uri + self.master = Master(port=self.port) + self.master.start() + self.config.master.uri = self.master.uri self._init_runner() def tearDown(self): diff --git a/third_party/ros/rostest/runner.py b/third_party/ros/rostest/runner.py index c7862b8..dbe3b5c 100644 --- a/third_party/ros/rostest/runner.py +++ b/third_party/ros/rostest/runner.py @@ -211,9 +211,7 @@ def setUp(self): # new test_parent for each run. we are a bit inefficient as it would be possible to # reuse the roslaunch base infrastructure for each test, but the roslaunch code # is not abstracted well enough yet - self.test_parent = ROSTestLaunchParent(self.config, [self.test_file], - reuse_master=self.reuse_master, - clear=self.clear) + self.test_parent = ROSTestLaunchParent(self.config, [self.test_file]) printlog('setup[%s] run_id[%s] starting', self.test_file, self.test_parent.run_id) @@ -239,10 +237,7 @@ def tearDown(self): printlog('rostest teardown %s complete', self.test_file) -def createUnitTest(test_file, - reuse_master=False, - clear=False, - results_base_dir=None): +def createUnitTest(test_file, results_base_dir=None): """ Unit test factory. Constructs a unittest class based on the roslaunch @@ -259,8 +254,6 @@ def createUnitTest(test_file, 'config': config, 'test_parent': None, 'test_file': test_file, - 'reuse_master': reuse_master, - 'clear': clear } # add in the tests