Skip to content

Commit

Permalink
Add auto-expansion of LaunchConfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
  • Loading branch information
Kenji Miyake committed Mar 10, 2022
1 parent 375486a commit 8bdf336
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
21 changes: 16 additions & 5 deletions launch/launch/substitutions/boolean_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import Iterable
from typing import Text

from .launch_configuration import LaunchConfiguration
from .substitution_failure import SubstitutionFailure
from ..frontend import expose_substitution
from ..launch_context import LaunchContext
Expand Down Expand Up @@ -55,7 +56,9 @@ def describe(self) -> Text:
def perform(self, context: LaunchContext) -> Text:
"""Perform the substitution."""
try:
condition = perform_typed_substitution(context, self.value, bool)
value = LaunchConfiguration(self.value, default=self.value).perform(context)
condition = perform_typed_substitution(
context, normalize_to_list_of_substitutions(value), bool)
except (TypeError, ValueError) as e:
raise SubstitutionFailure(e)

Expand Down Expand Up @@ -97,11 +100,15 @@ def describe(self) -> Text:
def perform(self, context: LaunchContext) -> Text:
"""Perform the substitution."""
try:
left_condition = perform_typed_substitution(context, self.left, bool)
value = LaunchConfiguration(self.left, default=self.left).perform(context)
left_condition = perform_typed_substitution(
context, normalize_to_list_of_substitutions(value), bool)
except (TypeError, ValueError) as e:
raise SubstitutionFailure(e)
try:
right_condition = perform_typed_substitution(context, self.right, bool)
value = LaunchConfiguration(self.right, default=self.right).perform(context)
right_condition = perform_typed_substitution(
context, normalize_to_list_of_substitutions(value), bool)
except (TypeError, ValueError) as e:
raise SubstitutionFailure(e)

Expand Down Expand Up @@ -143,11 +150,15 @@ def describe(self) -> Text:
def perform(self, context: LaunchContext) -> Text:
"""Perform the substitution."""
try:
left_condition = perform_typed_substitution(context, self.left, bool)
value = LaunchConfiguration(self.left, default=self.left).perform(context)
left_condition = perform_typed_substitution(
context, normalize_to_list_of_substitutions(value), bool)
except (TypeError, ValueError) as e:
raise SubstitutionFailure(e)
try:
right_condition = perform_typed_substitution(context, self.right, bool)
value = LaunchConfiguration(self.right, default=self.right).perform(context)
right_condition = perform_typed_substitution(
context, normalize_to_list_of_substitutions(value), bool)
except (TypeError, ValueError) as e:
raise SubstitutionFailure(e)

Expand Down
28 changes: 27 additions & 1 deletion launch_xml/test/launch_xml/test_boolean_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from launch.utilities import perform_substitutions


def test_boolean_substitution_xml():
def test_boolean_substitution():
xml_file = textwrap.dedent(
r"""
<launch>
Expand All @@ -46,6 +46,32 @@ def test_boolean_substitution_xml():
check_boolean_substitution(f)


def test_boolean_substitution_no_var():
xml_file = textwrap.dedent(
r"""
<launch>
<let name="true_value" value="true" />
<let name="false_value" value="false" />
<let name="not_true" value="$(not true_value)" />
<let name="not_false" value="$(not false_value)" />
<let name="and_true_true" value="$(and true_value true_value)" />
<let name="and_true_false" value="$(and true_value false_value)" />
<let name="and_false_true" value="$(and false_value true_value)" />
<let name="and_false_false" value="$(and false_value false_value)" />
<let name="or_true_true" value="$(or true_value true_value)" />
<let name="or_true_false" value="$(or true_value false_value)" />
<let name="or_false_true" value="$(or false_value true_value)" />
<let name="or_false_false" value="$(or false_value false_value)" />
</launch>
"""
)
with io.StringIO(xml_file) as f:
check_boolean_substitution(f)


def check_boolean_substitution(file):
root_entity, parser = Parser.load(file)
ld = parser.parse_description(root_entity)
Expand Down

0 comments on commit 8bdf336

Please sign in to comment.