11 from __future__
import print_function
16 from argparse
import RawTextHelpFormatter
21 from rospkg.environment
import ROS_TEST_RESULTS_DIR
22 from rostest.rostestutil
import printRostestSummary, xmlResultsFile
24 from roslaunch.pmon
import pmon_shutdown
25 import rocon_python_utils
37 overview =
'Launches a rocon multi-master test.\n\n' 43 @raise IOError : if no package name is given and the rocon launcher cannot be found on the filesystem. 45 parser = argparse.ArgumentParser(description=
help_string(), formatter_class=RawTextHelpFormatter)
46 parser.add_argument(
'package', nargs=
'?', default=
None, help=
'name of the package in which to find the test configuration')
47 parser.add_argument(
'test', nargs=1, help=
'name of the test configuration (xml) file')
50 parser.add_argument(
'-p',
'--pause', action=
'store_true', help=
'pause before tearing down so you can introspect easily [false]')
51 parser.add_argument(
'-n',
'--no-screen', action=
'store_true', help=
'do run each roslaunch with the --screen option [true]')
52 parser.add_argument(
'-t',
'--text-mode', action=
'store_true', help=
'log the rostest output to screen rather than log file.')
53 parser.add_argument(
"--results-filename", action=
'store', type=str, default=
None, help=
"results_filename")
54 parser.add_argument(
'--results-base-dir', action=
'store', default=
'', help=
"The base directory of the test results. The test result file is created in a subfolder name PKG_DIR.")
55 args = parser.parse_args()
57 args.test = args.test[0]
59 if not args.no_screen:
60 launch_arguments =
"--screen" 62 if not os.path.isfile(args.test):
63 raise IOError(
"Test launcher file does not exist [%s]." % args.test)
65 args.package = rospkg.get_package_name(args.test)
66 return (args.package, args.test, launch_arguments, args.pause, args.text_mode,
67 args.results_filename, args.results_base_dir)
71 (package, name, launch_arguments, pause, text_mode, results_filename, results_base_dir) =
_parse_arguments()
73 if os.path.isabs(name):
74 if os.path.exists(name):
77 raise IOError(
"cannot locate [%s]" % name)
79 rocon_launcher = rocon_python_utils.ros.find_resource(package, name)
83 env = {ROS_TEST_RESULTS_DIR: results_base_dir}
86 results_log_name = results_filename
87 if '.' in results_log_name:
88 results_log_name = results_log_name[:results_log_name.rfind(
'.')]
89 results_log_file = xmlResultsFile(package, results_log_name, is_rostest=
True, env=env)
90 results_log_file = results_log_file.replace(
"rostest",
"rocon_test")
92 results_log_name, results_log_file = loggers.configure_logging(package, rocon_launcher)
95 launchers = rocon_launch.parse_rocon_launcher(rocon_launcher, launch_arguments, args_mappings={})
98 test_case = runner.create_unit_rocon_test(rocon_launcher, launchers)
99 suite = unittest.TestLoader().loadTestsFromTestCase(test_case)
101 runner.set_pause_mode(
True)
103 runner.set_text_mode(
True)
104 result = unittest.TextTestRunner(verbosity=2).run(suite)
106 xml_runner = rosunit.create_xml_runner(package,
108 results_file=results_log_file,
111 result = xml_runner.run(suite)
114 test_parents = runner.get_rocon_test_parents()
115 for r
in test_parents:
119 subtest_results = runner.get_results()
124 config = rostest.runner.getConfig()
126 if config.config_errors:
127 print(
"\n[ROCON_TEST WARNINGS]" +
'-' * 62 +
'\n', file=sys.stderr)
128 for err
in config.config_errors:
129 print(
" * %s" % err, file=sys.stderr)
133 printRostestSummary(result, subtest_results)
134 loggers.printlog(
"results log file is in %s" % results_log_file)
140 if not result.wasSuccessful():
142 elif subtest_results.num_errors
or subtest_results.num_failures:
def help_string()
Methods.