def rostestmain(): import roslaunch.rlutil from optparse import OptionParser parser = OptionParser(usage="usage: %prog [options] [package] <filename>", prog=_NAME) parser.add_option("-t", "--text", action="store_true", dest="text_mode", default=False, help="Run with stdout output instead of XML output") parser.add_option("--pkgdir", metavar="PKG_DIR", dest="pkg_dir", default=None, help="package dir") parser.add_option("--package", metavar="PACKAGE", dest="package", default=None, help="package") parser.add_option("--results-filename", metavar="RESULTS_FILENAME", dest="results_filename", default=None, help="results_filename") parser.add_option("--results-base-dir", metavar="RESULTS_BASE_DIR", help="The base directory of the test results. The test result file is " + "created in a subfolder name PKG_DIR.") (options, args) = parser.parse_args() try: args = roslaunch.rlutil.resolve_launch_arguments(args) except roslaunch.core.RLException as e: print(str(e), file=sys.stderr) sys.exit(1) # make sure all loggers are configured properly logfile_name = configure_logging() logger = logging.getLogger('rostest') import roslaunch.core roslaunch.core.add_printlog_handler(logger.info) roslaunch.core.add_printerrlog_handler(logger.error) logger.info('rostest starting with options %s, args %s'%(options, args)) if len(args) == 0: parser.error("You must supply a test file argument to rostest.") if len(args) != 1: parser.error("rostest only accepts a single test file") # compute some common names we'll be using to generate test names and files test_file = args[0] if options.pkg_dir and options.package: # rosbuild2: the build system knows what package and directory, so let it tell us, # instead of shelling back out to rospack pkg_dir, pkg = options.pkg_dir, options.package else: pkg = rospkg.get_package_name(test_file) r = rospkg.RosPack() pkg_dir = r.get_path(pkg) if options.results_filename: outname = options.results_filename if '.' in outname: outname = outname[:outname.rfind('.')] else: outname = rostest_name_from_path(pkg_dir, test_file) env = None if options.results_base_dir: env = {ROS_TEST_RESULTS_DIR: options.results_base_dir} # #1140 if not os.path.isfile(test_file): results_file = xmlResultsFile(pkg, outname, True, env=env) write_bad_filename_failure(test_file, results_file, outname) parser.error("test file is invalid. Generated failure case result file in %s"%results_file) try: testCase = rostest.runner.createUnitTest(pkg, test_file) suite = unittest.TestLoader().loadTestsFromTestCase(testCase) if options.text_mode: rostest.runner.setTextMode(True) result = unittest.TextTestRunner(verbosity=2).run(suite) else: is_rostest = True results_file = xmlResultsFile(pkg, outname, is_rostest, env=env) xml_runner = createXMLRunner(pkg, outname, \ results_file=results_file, \ is_rostest=is_rostest) result = xml_runner.run(suite) finally: # really make sure that all of our processes have been killed test_parents = rostest.runner.getRostestParents() for r in test_parents: logger.info("finally rostest parent tearDown [%s]", r) r.tearDown() del test_parents[:] from roslaunch.pmon import pmon_shutdown logger.info("calling pmon_shutdown") pmon_shutdown() logger.info("... done calling pmon_shutdown") # print config errors after test has run so that we don't get caught up in .xml results config = rostest.runner.getConfig() if config: if config.config_errors: print("\n[ROSTEST WARNINGS]"+'-'*62+'\n', file=sys.stderr) for err in config.config_errors: print(" * %s"%err, file=sys.stderr) print('') # summary is worthless if textMode is on as we cannot scrape .xml results subtest_results = rostest.runner.getResults() if not options.text_mode: printRostestSummary(result, subtest_results) else: print("WARNING: overall test result is not accurate when --text is enabled") if logfile_name: print("rostest log file is in %s"%logfile_name) if not result.wasSuccessful(): sys.exit(1) elif subtest_results.num_errors or subtest_results.num_failures: sys.exit(2)
# override outname if options.bare_name: outname = options.bare_name else: testCase = rostest.runner.createUnitTest(pkg, test_file) suite = unittest.TestLoader().loadTestsFromTestCase(testCase) if options.text_mode: rostest.runner.setTextMode(True) result = unittest.TextTestRunner(verbosity=2).run(suite) else: is_rostest = True results_file = xmlResultsFile(pkg, outname, is_rostest) xml_runner = createXMLRunner(pkg, outname, \ results_file=results_file, \ is_rostest=is_rostest) result = xml_runner.run(suite) #_accumulateResults(xmlresults.read(results_file)) finally: # really make sure that all of our processes have been killed test_parents = rostest.runner.getRostestParents() for r in test_parents: logger.info("finally rostest parent tearDown [%s]", r) r.tearDown() del test_parents[:] from roslaunch.pmon import pmon_shutdown logger.info("calling pmon_shutdown") pmon_shutdown() logger.info("... done calling pmon_shutdown")
def rostestmain(): import roslaunch.rlutil from optparse import OptionParser parser = OptionParser(usage="usage: %prog [options] [package] <filename>", prog=_NAME) parser.add_option("-t", "--text", action="store_true", dest="text_mode", default=False, help="Run with stdout output instead of XML output") parser.add_option("--pkgdir", metavar="PKG_DIR", dest="pkg_dir", default=None, help="package dir") parser.add_option("--package", metavar="PACKAGE", dest="package", default=None, help="package") parser.add_option("--results-filename", metavar="RESULTS_FILENAME", dest="results_filename", default=None, help="results_filename") (options, args) = parser.parse_args() try: args = roslaunch.rlutil.resolve_launch_arguments(args) except roslaunch.core.RLException as e: print(str(e), file=sys.stderr) sys.exit(1) # make sure all loggers are configured properly logfile_name = configure_logging() logger = logging.getLogger('rostest') import roslaunch.core roslaunch.core.add_printlog_handler(logger.info) roslaunch.core.add_printerrlog_handler(logger.error) logger.info('rostest starting with options %s, args %s'%(options, args)) if len(args) == 0: parser.error("You must supply a test file argument to rostest.") if len(args) != 1: parser.error("rostest only accepts a single test file") # compute some common names we'll be using to generate test names and files test_file = args[0] if options.pkg_dir and options.package: # rosbuild2: the build system knows what package and directory, so let it tell us, # instead of shelling back out to rospack pkg_dir, pkg = options.pkg_dir, options.package else: pkg = rospkg.get_package_name(test_file) r = rospkg.RosPack() pkg_dir = r.get_path(pkg) if options.results_filename: outname = options.results_filename if '.' in outname: outname = outname[:outname.rfind('.')] else: outname = rostest_name_from_path(pkg_dir, test_file) # #1140 if not os.path.isfile(test_file): results_file = xmlResultsFile(pkg, outname, True) write_bad_filename_failure(test_file, results_file, outname) parser.error("test file is invalid. Generated failure case result file in %s"%results_file) try: testCase = rostest.runner.createUnitTest(pkg, test_file) suite = unittest.TestLoader().loadTestsFromTestCase(testCase) if options.text_mode: rostest.runner.setTextMode(True) result = unittest.TextTestRunner(verbosity=2).run(suite) else: is_rostest = True results_file = xmlResultsFile(pkg, outname, is_rostest) xml_runner = createXMLRunner(pkg, outname, \ results_file=results_file, \ is_rostest=is_rostest) result = xml_runner.run(suite) finally: # really make sure that all of our processes have been killed test_parents = rostest.runner.getRostestParents() for r in test_parents: logger.info("finally rostest parent tearDown [%s]", r) r.tearDown() del test_parents[:] from roslaunch.pmon import pmon_shutdown logger.info("calling pmon_shutdown") pmon_shutdown() logger.info("... done calling pmon_shutdown") # print config errors after test has run so that we don't get caught up in .xml results config = rostest.runner.getConfig() if config: if config.config_errors: print("\n[ROSTEST WARNINGS]"+'-'*62+'\n', file=sys.stderr) for err in config.config_errors: print(" * %s"%err, file=sys.stderr) print('') # summary is worthless if textMode is on as we cannot scrape .xml results subtest_results = rostest.runner.getResults() if not options.text_mode: printRostestSummary(result, subtest_results) else: print("WARNING: overall test result is not accurate when --text is enabled") if logfile_name: print("rostest log file is in %s"%logfile_name) if not result.wasSuccessful(): sys.exit(1) elif subtest_results.num_errors or subtest_results.num_failures: sys.exit(2)
# override outname if options.bare_name: outname = options.bare_name else: testCase = rostest.runner.createUnitTest(pkg, test_file) suite = unittest.TestLoader().loadTestsFromTestCase(testCase) if options.text_mode: rostest.runner.setTextMode(True) result = unittest.TextTestRunner(verbosity=2).run(suite) else: is_rostest = True results_file = xmlResultsFile(pkg, outname, is_rostest) xml_runner = createXMLRunner(pkg, outname, \ results_file=results_file, \ is_rostest=is_rostest) result = xml_runner.run(suite) finally: # really make sure that all of our processes have been killed test_parents = rostest.runner.getRostestParents() for r in test_parents: logger.info("finally rostest parent tearDown [%s]", r) r.tearDown() del test_parents[:] from roslaunch.pmon import pmon_shutdown logger.info("calling pmon_shutdown") pmon_shutdown() logger.info("... done calling pmon_shutdown") # print config errors after test has run so that we don't get caught up in .xml results