Example #1
0
def test_get_test_results_dir():
    from rospkg import get_ros_root, get_test_results_dir
    base = tempfile.gettempdir()
    ros_test_results_dir = os.path.join(base, 'ros_test_results_dir')
    ros_home_dir = os.path.join(base, 'ros_home_dir')
    home_dir = os.path.expanduser('~')

    # ROS_TEST_RESULTS_DIR has precedence
    env = {
        'ROS_ROOT': get_ros_root(),
        'ROS_TEST_RESULTS_DIR': ros_test_results_dir,
        'ROS_HOME': ros_home_dir
    }
    assert ros_test_results_dir == get_test_results_dir(env=env)

    env = {'ROS_ROOT': get_ros_root(), 'ROS_HOME': ros_home_dir}
    assert os.path.join(ros_home_dir,
                        'test_results') == get_test_results_dir(env=env)

    env = {'ROS_ROOT': get_ros_root()}
    assert os.path.join(home_dir, '.ros',
                        'test_results') == get_test_results_dir(env=env)

    # test default assignment of env. Don't both checking return value as we would duplicate get_test_results_dir
    assert get_test_results_dir() is not None
Example #2
0
File: core.py Project: safdark/ros
def xml_results_file(test_pkg, test_name, is_rostest=False):
    """
    @param test_pkg: name of test's package 
    @type  test_pkg: str
    @param test_name str: name of test
    @type  test_name: str
    @param is_rostest: True if the results file is for a rostest-generated unit instance
    @type  is_rostest: bool
    @return: name of xml results file for specified test
    @rtype:  str
    """
    test_dir = os.path.join(rospkg.get_test_results_dir(), test_pkg)
    if not os.path.exists(test_dir):
        try:
            makedirs_with_parent_perms(test_dir)
        except OSError:
            raise IOError(
                "cannot create test results directory [%s]. Please check permissions."
                % (test_dir))

    # #576: strip out chars that would bork the filename
    # this is fairly primitive, but for now just trying to catch some common cases
    for c in ' "\'&$!`/\\':
        if c in test_name:
            test_name = test_name.replace(c, '_')
    if is_rostest:
        return os.path.join(test_dir, 'TEST-rostest__%s.xml' % test_name)
    else:
        return os.path.join(test_dir, 'TEST-%s.xml' % test_name)
Example #3
0
def xml_results_file(test_pkg, test_name, is_rostest=False):
    """
    @param test_pkg: name of test's package 
    @type  test_pkg: str
    @param test_name str: name of test
    @type  test_name: str
    @param is_rostest: True if the results file is for a rostest-generated unit instance
    @type  is_rostest: bool
    @return: name of xml results file for specified test
    @rtype:  str
    """
    test_dir = os.path.join(rospkg.get_test_results_dir(), test_pkg)
    if not os.path.exists(test_dir):
        try:
            makedirs_with_parent_perms(test_dir)
        except OSError:
            raise IOError("cannot create test results directory [%s]. Please check permissions."%(test_dir))
        
    # #576: strip out chars that would bork the filename
    # this is fairly primitive, but for now just trying to catch some common cases
    for c in ' "\'&$!`/\\':
        if c in test_name:
            test_name = test_name.replace(c, '_')
    if is_rostest:
        return os.path.join(test_dir, 'rostest-%s.xml'%test_name)
    else:
        return os.path.join(test_dir, 'rosunit-%s.xml'%test_name)
Example #4
0
    def test_path_smoothing(self):
        test_dir = rospkg.get_test_results_dir() + '/' + PKG
        if not os.path.exists(test_dir):
            os.makedirs(test_dir)

        path = np.array([[0, 0],
                         [1, 0],
                         [1, 1],
                         [2, 1]])
        pos, vel, acc, jerk, time = smooth_path(path)
        plt.figure()
        ax1 = plt.subplot2grid((3, 2), (0, 0), rowspan=3)
        ax1.plot(pos[:, 0], pos[:, 1])
        ax1.set_xlabel('x position')
        ax1.set_ylabel('y position')
        ax2 = plt.subplot2grid((3, 2), (0, 1))
        ax2.plot(time, vel[:, 0], time, vel[:, 1])
        ax2.set_ylabel('Velocity')
        ax3 = plt.subplot2grid((3, 2), (1, 1), sharex=ax2)
        ax3.plot(time, acc[:, 0], time, acc[:, 1])
        ax3.set_ylabel('Acceleration')
        ax4 = plt.subplot2grid((3, 2), (2, 1), sharex=ax2)
        ax4.plot(time, jerk[:, 0], time, jerk[:, 1])
        ax4.set_ylabel('Jerk')
        ax4.set_xlabel('Time')
        for ax in [ax2, ax3]:
            plt.setp(ax.get_xticklabels(), visible=False)
        plt.tight_layout()
        filepath = test_dir + '/smoothing.png'
        plt.savefig(filepath)
        self.assertTrue(True)
Example #5
0
def prepare_dirs(output_dir_name):
    test_results_dir = rospkg.get_test_results_dir()
    print("will read test results from", test_results_dir)
    output_dir = os.path.join(test_results_dir, output_dir_name)
    if not os.path.exists(output_dir):
        print("creating directory", output_dir)
        os.makedirs(output_dir)
    return test_results_dir, output_dir
Example #6
0
def prepare_dirs(output_dir_name):
    test_results_dir = rospkg.get_test_results_dir()
    print("will read test results from", test_results_dir)
    output_dir = os.path.join(test_results_dir, output_dir_name)
    if not os.path.exists(output_dir):
        print("creating directory", output_dir)
        os.makedirs(output_dir)
    return test_results_dir, output_dir
Example #7
0
 def test_plot_map(self):
     test_dir = rospkg.get_test_results_dir() + '/' + PKG
     if not os.path.exists(test_dir):
         os.makedirs(test_dir)
     filepath = test_dir + '/prm.png'
     plt.figure()
     self.prm.plot()
     plt.savefig(filepath)
     self.assertTrue(True)
def test_get_test_results_dir():
    from rospkg import get_ros_root, get_test_results_dir
    base = tempfile.gettempdir()
    ros_test_results_dir = os.path.join(base, 'ros_test_results_dir')
    ros_home_dir = os.path.join(base, 'ros_home_dir')
    home_dir = os.path.expanduser('~')

    # ROS_TEST_RESULTS_DIR has precedence
    env = {'ROS_ROOT': get_ros_root(), 'ROS_TEST_RESULTS_DIR': ros_test_results_dir, 'ROS_HOME': ros_home_dir }
    assert ros_test_results_dir == get_test_results_dir(env=env)

    env = {'ROS_ROOT': get_ros_root(), 'ROS_HOME': ros_home_dir }
    assert os.path.join(ros_home_dir, 'test_results') == get_test_results_dir(env=env)

    env = {'ROS_ROOT': get_ros_root()}
    assert os.path.join(home_dir, '.ros', 'test_results') == get_test_results_dir(env=env)

    # test default assignment of env. Don't both checking return value as we would duplicate get_test_results_dir
    assert get_test_results_dir() is not None
    def build(self):
# Hudson sets the WORKSPACE env var
        workspace = os.environ['STACK_BUILD_DIR']
#workspace = '/tmp'
        os.environ['JOB_NAME'] = 'build'

        ros_test_results_dir = rospkg.get_test_results_dir()
        print '1. Test results dir is set to %s'%ros_test_results_dir

        # Blow away old ~/.ros content. self.dotrosname is used at the end
        # of this method, for tarring up the result of this run.
        self.dotrosname = os.path.join(workspace, '.ros')
    def build(self):
        # Hudson sets the WORKSPACE env var
        workspace = os.environ["STACK_BUILD_DIR"]
        # workspace = '/tmp'
        os.environ["JOB_NAME"] = "build"

        ros_test_results_dir = rospkg.get_test_results_dir()
        print "1. Test results dir is set to %s" % ros_test_results_dir

        # Blow away old ~/.ros content. self.dotrosname is used at the end
        # of this method, for tarring up the result of this run.
        self.dotrosname = os.path.join(workspace, ".ros")
        if os.path.isdir(self.dotrosname):
            try:
                shutil.rmtree(self.dotrosname)
            except OSError, e:
                # Ignore this; it's usually a stale NFS handle.
                pass
Example #11
0
    def build(self):
        # Hudson sets the WORKSPACE env var
        workspace = os.environ['STACK_BUILD_DIR']
        #workspace = '/tmp'
        os.environ['JOB_NAME'] = 'build'

        ros_test_results_dir = rospkg.get_test_results_dir()
        print '1. Test results dir is set to %s' % ros_test_results_dir

        # Blow away old ~/.ros content. self.dotrosname is used at the end
        # of this method, for tarring up the result of this run.
        self.dotrosname = os.path.join(workspace, '.ros')
        if os.path.isdir(self.dotrosname):
            try:
                shutil.rmtree(self.dotrosname)
            except OSError, e:
                # Ignore this; it's usually a stale NFS handle.
                pass
Example #12
0
def read_all(filter_=[]):
    """
    Read in the test_results and aggregate into a single Result object
    @param filter_: list of packages that should be processed
    @type filter_: [str]
    @return: aggregated result
    @rtype: L{Result}
    """
    dir_ = rospkg.get_test_results_dir()
    root_result = Result('ros', 0, 0, 0)
    if not os.path.exists(dir_):
        return root_result
    for d in os.listdir(dir_):
        if filter_ and not d in filter_:
            continue
        subdir = os.path.join(dir_, d)
        if os.path.isdir(subdir):
            for filename in os.listdir(subdir):
                if filename.endswith('.xml'):
                    filename = os.path.join(subdir, filename)
                    result = read(filename, os.path.basename(subdir))
                    root_result.accumulate(result)
    return root_result
Example #13
0
def read_all(filter_=[]):
    """
    Read in the test_results and aggregate into a single Result object
    @param filter_: list of packages that should be processed
    @type filter_: [str]
    @return: aggregated result
    @rtype: L{Result}
    """
    dir_ = rospkg.get_test_results_dir()
    root_result = Result('ros', 0, 0, 0)
    if not os.path.exists(dir_):
        return root_result
    for d in os.listdir(dir_):
        if filter_ and d not in filter_:
            continue
        subdir = os.path.join(dir_, d)
        if os.path.isdir(subdir):
            for filename in os.listdir(subdir):
                if filename.endswith('.xml'):
                    filename = os.path.join(subdir, filename)
                    result = read(filename, os.path.basename(subdir))
                    root_result.accumulate(result)
    return root_result
Example #14
0
    run_shell_cmd,
    add_text_to_video,
    concatenate_videos,
    rosbag_msg_generator,
    get_rosbag_file,
    check_if_ffmpeg_satisfied,
)
from blender_api_msgs.msg import *
from genpy import Duration

from roslaunch import nodeprocess

nodeprocess._TIMEOUT_SIGINT = 2
nodeprocess._TIMEOUT_SIGTERM = 1

TEST_DIR = rospkg.get_test_results_dir()
PKG = "blender_api_msgs"


def parse_msg(msg):
    return eval(msg.split(":")[1].strip())


class BlenderAPITest(unittest.TestCase):
    def setUp(self):
        blender_api_path = os.path.join(rospkg.RosPack().get_path("blender_api_msgs"), "../blender_api")
        config = roslaunch.config.ROSLaunchConfig()
        config.add_node(
            core.Node(
                package="blender_api_msgs",
                node_type="blender",
Example #15
0
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of Willow Garage, Inc. nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$

"""
test_results_dir.py simply prints the directory that rosunit/rostest
results are stored in.
"""

from __future__ import print_function
import rospkg
print(rospkg.get_test_results_dir())
Example #16
0
import rostopic
import rosbag
import rosnode
from roslaunch import core
from testing_tools.misc import (wait_for, startxvfb, stopxvfb, capture_screen,
                                run_shell_cmd, add_text_to_video,
                                concatenate_videos, rosbag_msg_generator,
                                get_rosbag_file, check_if_ffmpeg_satisfied)
from blender_api_msgs.msg import *
from genpy import Duration

from roslaunch import nodeprocess
nodeprocess._TIMEOUT_SIGINT = 2
nodeprocess._TIMEOUT_SIGTERM = 1

TEST_DIR = rospkg.get_test_results_dir()
PKG = 'blender_api_msgs'


def parse_msg(msg):
    return eval(msg.split(':')[1].strip())


class BlenderAPITest(unittest.TestCase):
    def setUp(self):
        blender_api_path = os.path.join(
            rospkg.RosPack().get_path('blender_api_msgs'), '../blender_api')
        config = roslaunch.config.ROSLaunchConfig()
        config.add_node(
            core.Node(package='blender_api_msgs',
                      node_type='blender',
Example #17
0
        )
        result = [{
            "topic": "/appctl/mode",
            "message_type": "appctl/Mode",
            "slot": "mode",
            "strategy": "value",
            "value_min": None,
            "value_max": None,
            "value": "tactile"
        }, {
            "topic": "/director/scene",
            "message_type": "interactivespaces_msgs/GenericMessage",
            "slot": "message.slug",
            "strategy": "value",
            "value_min": None,
            "value_max": None,
            "value": "online_scene"
        }]
        assert result == unpack_activity_sources(source_string)


if __name__ == "__main__":
    test_pkg = "lg_common"
    test_name = "test_helpers"
    test_dir = os.path.join(rospkg.get_test_results_dir(env=None), test_pkg)
    pytest_result_path = os.path.join(test_dir, "rosunit-%s.xml" % test_name)
    # run only itself
    test_path = os.path.abspath(os.path.abspath(__file__))
    # output is unfortunately handled / controlled by above layer of rostest (-s has no effect)
    pytest.main("%s -s -v --junit-xml=%s" % (test_path, pytest_result_path))
        assert self.publisher.msgs[0].strings == []
        # check that the hide message was sent just once
        assert len(self.publisher.msgs) == 1

    def test_handle_visibility_show_onboard(self):
        msg = Bool(data=True)
        assert self.router.last_state is None
        self.router.handle_visibility(msg)
        assert self.router.last_state is True
        assert self.publisher.msgs[0].strings == ["wall"]
        # check that the hide message was sent just once
        assert len(self.publisher.msgs) == 1
        # check that repeatedly sending messages of the same value
        # won't get processed multiple times but only once
        for _ in range(10):
            self.router.handle_visibility(msg)
        assert self.router.last_state is True
        assert self.publisher.msgs[0].strings == ["wall"]
        # check that the hide message was sent just once
        assert len(self.publisher.msgs) == 1


if __name__ == "__main__":
    test_pkg = "lg_keyboard"
    test_name = "test_onboard_router"
    test_dir = os.path.join(rospkg.get_test_results_dir(env=None), test_pkg)
    pytest_result_path = os.path.join(test_dir, "rosunit-%s.xml" % test_name)
    # run only itself
    test_path = os.path.abspath(os.path.abspath(__file__))
    pytest.main("-vv -rfsX -s --junit-xml=%s %s" % (pytest_result_path, test_path))
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of Willow Garage, Inc. nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$
"""
test_results_dir.py simply prints the directory that rosunit/rostest
results are stored in.
"""

from __future__ import print_function
import rospkg
print(rospkg.get_test_results_dir())