unit_test_node.py 1.62 KB
Newer Older
Maximilien Naveau's avatar
Maximilien Naveau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
"""python_service_server

license BSD 3-clause
Copyright (c) 2020, CNRS

small server for running unit-test on the generated API of ROS2 services.
"""

import os
import rospy
from dynamic_graph_bridge_msgs.srv import (
    RunPythonCommand,
    RunCommand,
    RunPythonFile,
    RunPythonCommandResponse,
    RunCommandResponse,
    RunPythonFileResponse,
)


class ServerNode(object):
    def __init__(self):
        self._run_python_command_srv = rospy.Service(
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
25
26
            "run_python_command", RunPythonCommand, self._run_python_command
        )
Maximilien Naveau's avatar
Maximilien Naveau committed
27
28

        self._run_command_srv = rospy.Service(
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
29
30
31
            "run_command", RunCommand, self._run_command
        )

Maximilien Naveau's avatar
Maximilien Naveau committed
32
        self._run_python_file_srv = rospy.Service(
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
33
34
35
            "run_python_file", RunPythonFile, self._run_python_file
        )

Maximilien Naveau's avatar
Maximilien Naveau committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    def _run_python_command(self, request):
        response = RunPythonCommandResponse()
        response.result = request.input + "_result_python_cmd"
        response.standardoutput = "standardoutput"
        response.standarderror = "standarderror"
        return response

    def _run_command(self, request):
        response = RunCommandResponse()
        response.result = request.input + "_result_cmd"
        response.standardoutput = "standardoutput"
        response.standarderror = "standarderror"
        return response

    def _run_python_file(self, request):
        response = RunPythonFileResponse()
        response.result = str(os.path.exists(request.input))
        return response

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
55

Maximilien Naveau's avatar
Maximilien Naveau committed
56
def main(args=None):
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
57
58
    rospy.init_node("unit_test_node")
    ServerNode()
Maximilien Naveau's avatar
Maximilien Naveau committed
59
60
61
    rospy.spin()


Guilhem Saurel's avatar
format    
Guilhem Saurel committed
62
if __name__ == "__main__":
Maximilien Naveau's avatar
Maximilien Naveau committed
63
    main()