Package rocon_test :: Module main
[frames] | no frames]

Source Code for Module rocon_test.main

  1  #!/usr/bin/env python 
  2  # 
  3  # License: BSD 
  4  #   https://raw.github.com/robotics-in-concert/rocon_multimaster/hydro-devel/rocon_test/LICENSE 
  5  # 
  6   
  7  ############################################################################## 
  8  # Imports 
  9  ############################################################################## 
 10   
 11  from __future__ import print_function 
 12   
 13  import os 
 14  import sys 
 15  import unittest 
 16  import rostest.runner 
 17  import rocon_utilities 
 18  import rospkg 
 19  import argparse 
 20  from argparse import RawTextHelpFormatter 
 21  from rostest.rostestutil import printRostestSummary 
 22  import rosunit 
 23  from roslaunch.pmon import pmon_shutdown 
 24   
 25  # Local imports 
 26  import loggers 
 27  #from loggers import printlog 
 28  import runner 
 29   
 30  ############################################################################## 
 31  # Methods 
 32  ############################################################################## 
 33   
 34   
35 -def help_string():
36 overview = 'Launches a rocon multi-launch test.\n\n' 37 instructions = " \ 38 - 'rocon-test xxx' : create an empty workspace in ./ecl.\n \ 39 With some extra info (todo).\n\n \ 40 " 41 return overview + instructions
42 43
44 -def _parse_arguments():
45 ''' 46 @raise IOError : if no package name is given and the rocon launcher cannot be found on the filesystem. 47 ''' 48 parser = argparse.ArgumentParser(description=help_string(), formatter_class=RawTextHelpFormatter) 49 parser.add_argument('package', nargs='?', default=None, help='name of the package in which to find the test configuration') 50 parser.add_argument('test', nargs=1, help='name of the test configuration (xml) file') 51 parser.add_argument('-l', '--launch', action='store_true', help='launch each component with rocon_launch [false]') 52 parser.add_argument('-p', '--pause', action='store_true', help='pause before tearing down so you can introspect easily [false]') 53 parser.add_argument('-s', '--screen', action='store_true', help='run each roslaunch with the --screen option') 54 parser.add_argument('-t', '--text-mode', action='store_true', help='log the rostest output to screen rather than log file.') 55 args = parser.parse_args() 56 # Stop it from being a list (happens when nargs is an integer) 57 args.test = args.test[0] 58 if args.screen: 59 args.screen = "--screen" 60 else: 61 args.screen = "" 62 if not args.package: 63 if not os.path.isfile(args.test): 64 raise IOError("Test launcher file does not exist [%s]." % args.test) 65 else: 66 args.package = rospkg.get_package_name(args.test) 67 return (args.package, args.test, args.screen, args.pause, args.text_mode)
68 69
70 -def test_main():
71 (package, name, launch_arguments, pause, text_mode) = _parse_arguments() 72 rocon_launcher = rocon_utilities.find_resource(package, name) # raises an IO error if there is a problem. 73 launchers = rocon_utilities.parse_rocon_launcher(rocon_launcher, launch_arguments) 74 results_log_name, results_file = loggers.configure_logging(package, rocon_launcher) 75 76 try: 77 test_case = runner.create_unit_rocon_test(rocon_launcher, launchers) 78 suite = unittest.TestLoader().loadTestsFromTestCase(test_case) 79 if pause: 80 runner.set_pause_mode(True) 81 if text_mode: 82 runner.set_text_mode(True) 83 result = unittest.TextTestRunner(verbosity=2).run(suite) 84 else: 85 xml_runner = rosunit.create_xml_runner(package, results_log_name, \ 86 results_file=results_file, \ 87 is_rostest=True) 88 result = xml_runner.run(suite) 89 finally: 90 # really make sure that all of our processes have been killed (should be automatic though) 91 test_parents = runner.get_rocon_test_parents() 92 for r in test_parents: 93 r.tearDown() 94 del test_parents[:] 95 pmon_shutdown() 96 subtest_results = runner.get_results() 97 98 ################################ 99 # Post stuff 100 ################################ 101 config = rostest.runner.getConfig() 102 if config: 103 if config.config_errors: 104 print("\n[ROCON_TEST WARNINGS]" + '-' * 62 + '\n', file=sys.stderr) 105 for err in config.config_errors: 106 print(" * %s" % err, file=sys.stderr) 107 print('') 108 109 if not text_mode: 110 printRostestSummary(result, subtest_results) 111 loggers.printlog("results log file is in %s" % results_file) 112 113 # This is not really a useful log, so dont worry about showing it. 114 # if log_name: 115 # loggers.printlog("rocon_test log file is in %s" % log_name) 116 117 if not result.wasSuccessful(): 118 sys.exit(1) 119 elif subtest_results.num_errors or subtest_results.num_failures: 120 sys.exit(2)
121