-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathexecute_and_validate_talker.py
More file actions
118 lines (91 loc) · 2.73 KB
/
Copy pathexecute_and_validate_talker.py
File metadata and controls
118 lines (91 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import log
import os
import validation
DESCRIPTION = """Script to validate talkers output"""
USAGE = ('python3 execute_and_validate_talker.py '
'[-s <samples>] [-t <timeout>] [-d]')
def parse_options():
"""
Parse arguments.
:return: The arguments parsed.
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
add_help=True,
description=(DESCRIPTION),
usage=(USAGE)
)
parser.add_argument(
'-t',
'--timeout',
type=int,
default=5,
help='Timeout for the subscriber application.'
)
parser.add_argument(
'--delay',
type=float,
default=0,
help='Time to wait before starting execution.'
)
parser.add_argument(
'-d',
'--debug',
action='store_true',
help='Print test debugging info.'
)
return parser.parse_args()
def _talker_command(args):
"""
Build the command to execute the talker.
:param args: Arguments parsed
:return: Command to execute the talker
"""
command = [
'python3',
f'/opt/ros/{os.environ["ROS_DISTRO"]}/lib/demo_nodes_py/talker']
return command
def _talker_parse_output(stdout, stderr):
"""
Do nothing.
Dummy method as talker will not parse output.
"""
return stdout, stderr
def _talker_validate(stdout_parsed, stderr_parsed):
"""
Do nothing.
Dummy method as talker will not validate anything.
"""
return validation.ReturnCode.SUCCESS
if __name__ == '__main__':
# Parse arguments
args = parse_options()
# Set log level
if args.debug:
log.activate_debug()
# Prepare command
command = _talker_command(args)
# Run command and validate
ret_code = validation.run_and_validate(
command=command,
timeout=args.timeout,
delay=args.delay,
parse_output_function=_talker_parse_output,
validate_output_function=_talker_validate,
timeout_as_error=False)
print(f'talker validator exited with code {ret_code}')
exit(ret_code.value)