forked from ApexAI/apex_rostest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.test.py
92 lines (72 loc) · 2.69 KB
/
args.test.py
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
# Copyright 2019 Apex.AI, Inc.
#
# 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 os
import unittest
import ament_index_python
import apex_launchtest
import apex_launchtest.util
import launch
import launch.actions
import launch.substitutions
dut_process = launch.actions.ExecuteProcess(
cmd=[
os.path.join(
ament_index_python.get_package_prefix('apex_launchtest'),
'lib/apex_launchtest',
'terminating_proc',
),
# Arguments
launch.substitutions.LaunchConfiguration('dut_arg')
],
)
def generate_test_description(ready_fn):
return launch.LaunchDescription([
# This argument can be passed into the test, and can be discovered by running
# apex_launchtest --show-args
launch.actions.DeclareLaunchArgument(
'dut_arg',
default_value=['default'],
description='Passed to the terminating process',
),
dut_process,
# In tests where all of the procs under tests terminate themselves, it's necessary
# to add a dummy process not under test to keep the launch alive. apex_launchtest
# provides a simple launch action that does this:
apex_launchtest.util.KeepAliveProc(),
launch.actions.OpaqueFunction(function=lambda context: ready_fn())
])
class TestTerminatingProcessStops(unittest.TestCase):
def test_proc_terminates(self):
self.proc_info.assertWaitForShutdown(process=dut_process, timeout=10)
@apex_launchtest.post_shutdown_test()
class TestProcessOutput(unittest.TestCase):
def test_ran_with_arg(self):
self.assertNotIn(
'default',
dut_process.process_details['cmd'],
'Try running: apex_launchtest test_with_args.test.py dut_arg:=arg'
)
def test_arg_printed_in_output(self):
apex_launchtest.asserts.assertInStdout(
self.proc_output,
self.test_args['dut_arg'],
dut_process
)
def test_default_not_printed(self):
with self.assertRaises(AssertionError):
apex_launchtest.asserts.assertInStdout(
self.proc_output,
'default',
dut_process
)