forked from ros2/launch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for not optional environment variable substitution (ros2#288
) * Add support for non optional environment variable substitution Signed-off-by: ivanpauno <[email protected]> * Address per review comments Signed-off-by: ivanpauno <[email protected]> * Correct test in launch_xml Signed-off-by: ivanpauno <[email protected]>
- Loading branch information
1 parent
060d2f3
commit dbd7016
Showing
5 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
launch/test/launch/substitutions/test_environment_variable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2019 Open Source Robotics Foundation, 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. | ||
|
||
"""Tests for the EnvironmentVariable substitution class.""" | ||
|
||
import os | ||
|
||
from launch import LaunchContext | ||
from launch.actions import SetEnvironmentVariable | ||
from launch.substitutions import EnvironmentVariable | ||
from launch.substitutions import SubstitutionFailure | ||
|
||
import pytest | ||
|
||
|
||
def test_this_launch_file_path(): | ||
if 'MY_ENVIRONMENT_VARIABLE' in os.environ: | ||
del os.environ['MY_ENVIRONMENT_VARIABLE'] | ||
lc = LaunchContext() | ||
sub1 = EnvironmentVariable('MY_ENVIRONMENT_VARIABLE') | ||
with pytest.raises(SubstitutionFailure) as ex: | ||
sub1.perform(lc) | ||
ex.match("environment variable 'MY_ENVIRONMENT_VARIABLE' does not exist") | ||
|
||
sub2 = EnvironmentVariable('MY_ENVIRONMENT_VARIABLE', default_value='') | ||
assert '' == sub2.perform(lc) | ||
|
||
sub3 = EnvironmentVariable('MY_ENVIRONMENT_VARIABLE', default_value='MY_DEFAULT_VALUE') | ||
assert 'MY_DEFAULT_VALUE' == sub3.perform(lc) | ||
|
||
SetEnvironmentVariable('MY_ENVIRONMENT_VARIABLE', 'SOME_VALUE').visit(lc) | ||
assert 'SOME_VALUE' == sub1.perform(lc) | ||
assert 'SOME_VALUE' == sub2.perform(lc) | ||
assert 'SOME_VALUE' == sub3.perform(lc) | ||
del os.environ['MY_ENVIRONMENT_VARIABLE'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<launch> | ||
<executable cmd="ls -l -a -s" cwd="/" name="my_ls" shell="true" output='log' launch-prefix='$(env LAUNCH_PREFIX)'> | ||
<executable cmd="ls -l -a -s" cwd="/" name="my_ls" shell="true" output="log" launch-prefix="$(env LAUNCH_PREFIX '')"> | ||
<env name="var" value="1"/> | ||
</executable> | ||
</launch> |