コード例 #1
0
ファイル: __init__.py プロジェクト: ckt1010/ROS-pi-toolchain
def rosrun(package, test_name, test, sysargs=None):
    """
    Run a rostest/unittest-based integration test.
    
    @param package: name of package that test is in
    @type  package: str
    @param test_name: name of test that is being run
    @type  test_name: str
    @param test: a test case instance or a name resolving to a test case or suite
    @type  test: unittest.TestCase, or string
    @param sysargs: command-line args. If not specified, this defaults to sys.argv. rostest
      will look for the --text and --gtest_output parameters
    @type  sysargs: list
    """
    if sysargs is None:
        # lazy-init sys args
        import sys
        sysargs = sys.argv

    #parse sysargs
    result_file = None
    for arg in sysargs:
        if arg.startswith(XML_OUTPUT_FLAG):
            result_file = arg[len(XML_OUTPUT_FLAG):]
    text_mode = '--text' in sysargs
    coverage_mode = '--cov' in sysargs
    if coverage_mode:
        _start_coverage([package])

    import unittest
    import rospy

    suite = None
    if isinstance(test, str):
        suite = unittest.TestLoader().loadTestsFromName(test)
    else:
        # some callers pass a TestCase type (instead of an instance)
        suite = unittest.TestLoader().loadTestsFromTestCase(test)

    if text_mode:
        result = unittest.TextTestRunner(verbosity=2).run(suite)
    else:
        result = rosunit.create_xml_runner(package, test_name,
                                           result_file).run(suite)
    if coverage_mode:
        _stop_coverage([package])
    rosunit.print_unittest_summary(result)

    # shutdown any node resources in case test forgets to
    rospy.signal_shutdown('test complete')
    if not result.wasSuccessful():
        import sys
        sys.exit(1)
コード例 #2
0
def test_main():
    (package, name, launch_arguments, pause, text_mode) = _parse_arguments()
    rocon_launcher = rocon_utilities.find_resource(package, name)  # raises an IO error if there is a problem.
    launchers = rocon_utilities.parse_rocon_launcher(rocon_launcher, launch_arguments)
    results_log_name, results_file = loggers.configure_logging(package, rocon_launcher)

    try:
        test_case = runner.create_unit_rocon_test(rocon_launcher, launchers)
        suite = unittest.TestLoader().loadTestsFromTestCase(test_case)
        if pause:
            runner.set_pause_mode(True)
        if text_mode:
            runner.set_text_mode(True)
            result = unittest.TextTestRunner(verbosity=2).run(suite)
        else:
            xml_runner = rosunit.create_xml_runner(package, results_log_name, \
                                         results_file=results_file, \
                                         is_rostest=True)
            result = xml_runner.run(suite)
    finally:
        # really make sure that all of our processes have been killed (should be automatic though)
        test_parents = runner.get_rocon_test_parents()
        for r in test_parents:
            r.tearDown()
        del test_parents[:]
        pmon_shutdown()
    subtest_results = runner.get_results()

    ################################
    # Post stuff
    ################################
    config = rostest.runner.getConfig()
    if config:
        if config.config_errors:
            print("\n[ROCON_TEST WARNINGS]" + '-' * 62 + '\n', file=sys.stderr)
        for err in config.config_errors:
            print(" * %s" % err, file=sys.stderr)
        print('')

    if not text_mode:
        printRostestSummary(result, subtest_results)
        loggers.printlog("results log file is in %s" % results_file)

    # This is not really a useful log, so dont worry about showing it.
    # if log_name:
    #     loggers.printlog("rocon_test log file is in %s" % log_name)

    if not result.wasSuccessful():
        sys.exit(1)
    elif subtest_results.num_errors or subtest_results.num_failures:
        sys.exit(2)
コード例 #3
0
ファイル: __init__.py プロジェクト: Mygao/ros_comm
def rosrun(package, test_name, test, sysargs=None):
    """
    Run a rostest/unittest-based integration test.
    
    @param package: name of package that test is in
    @type  package: str
    @param test_name: name of test that is being run
    @type  test_name: str
    @param test: a test case instance or a name resolving to a test case or suite
    @type  test: unittest.TestCase, or string
    @param sysargs: command-line args. If not specified, this defaults to sys.argv. rostest
      will look for the --text and --gtest_output parameters
    @type  sysargs: list
    """
    if sysargs is None:
        # lazy-init sys args
        import sys
        sysargs = sys.argv
        
    #parse sysargs
    result_file = None
    for arg in sysargs:
        if arg.startswith(XML_OUTPUT_FLAG):
            result_file = arg[len(XML_OUTPUT_FLAG):]
    text_mode = '--text' in sysargs
    coverage_mode = '--cov' in sysargs
    if coverage_mode:
        _start_coverage([package])

    import unittest
    import rospy
    
    suite = None
    if issubclass(test, unittest.TestCase):
        suite = unittest.TestLoader().loadTestsFromTestCase(test)
    else:
        suite = unittest.TestLoader().loadTestsFromName(test)

    if text_mode:
        result = unittest.TextTestRunner(verbosity=2).run(suite)
    else:
        result = rosunit.create_xml_runner(package, test_name, result_file).run(suite)
    if coverage_mode:
        _stop_coverage([package])
    rosunit.print_unittest_summary(result)
    
    # shutdown any node resources in case test forgets to
    rospy.signal_shutdown('test complete')
    if not result.wasSuccessful():
        import sys
        sys.exit(1)
コード例 #4
0
ファイル: main.py プロジェクト: samiamlabs/rocon_multimaster
def test_main():
    (package, name, launch_arguments, pause, text_mode, results_filename,
     results_base_dir) = _parse_arguments()

    if os.path.isabs(name):
        if os.path.exists(name):
            rocon_launcher = name
        else:
            raise IOError("cannot locate [%s]" % name)
    else:
        rocon_launcher = rocon_python_utils.ros.find_resource(
            package, name)  # raises an IO error if there is a problem.

    env = None
    if results_base_dir:
        env = {ROS_TEST_RESULTS_DIR: results_base_dir}

    if results_filename:
        results_log_name = results_filename
        if '.' in results_log_name:
            results_log_name = results_log_name[:results_log_name.rfind('.')]
        results_log_file = xmlResultsFile(package,
                                          results_log_name,
                                          is_rostest=True,
                                          env=env)
        results_log_file = results_log_file.replace("rostest", "rocon_test")
    else:
        results_log_name, results_log_file = loggers.configure_logging(
            package, rocon_launcher)

    # launchers is of type rocon_launch.RosLaunchConfiguration[]
    launchers = rocon_launch.parse_rocon_launcher(rocon_launcher,
                                                  launch_arguments,
                                                  args_mappings={})

    try:
        test_case = runner.create_unit_rocon_test(rocon_launcher, launchers)
        suite = unittest.TestLoader().loadTestsFromTestCase(test_case)
        if pause:
            runner.set_pause_mode(True)
        if text_mode:
            runner.set_text_mode(True)
            result = unittest.TextTestRunner(verbosity=2).run(suite)
        else:
            xml_runner = rosunit.create_xml_runner(
                package,
                results_log_name,
                results_file=results_log_file,
                is_rostest=True)
            result = xml_runner.run(suite)
    finally:
        # really make sure that all of our processes have been killed (should be automatic though)
        test_parents = runner.get_rocon_test_parents()
        for r in test_parents:
            r.tearDown()
        del test_parents[:]
        pmon_shutdown()
    subtest_results = runner.get_results()

    ################################
    # Post stuff
    ################################
    config = rostest.runner.getConfig()
    if config:
        if config.config_errors:
            print("\n[ROCON_TEST WARNINGS]" + '-' * 62 + '\n', file=sys.stderr)
        for err in config.config_errors:
            print(" * %s" % err, file=sys.stderr)
        print('')

    if not text_mode:
        printRostestSummary(result, subtest_results)
        loggers.printlog("results log file is in %s" % results_log_file)

    # This is not really a useful log, so dont worry about showing it.
    # if log_name:
    #     loggers.printlog("rocon_test log file is in %s" % log_name)

    if not result.wasSuccessful():
        sys.exit(1)
    elif subtest_results.num_errors or subtest_results.num_failures:
        sys.exit(2)