Skip to content

Commit e63f222

Browse files
committed
Make the directory-finding substitutions into a PathSubstitution for / operator
1 parent 10b99ae commit e63f222

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

launch/launch/substitutions/launch_log_dir.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@
2121
from typing import Tuple
2222
from typing import Type
2323

24-
24+
from .path_join_substitution import PathSubstitution
2525
from ..frontend.expose import expose_substitution
2626
from ..launch_context import LaunchContext
2727
from ..logging import launch_config as launch_logging_config
2828
from ..some_substitutions_type import SomeSubstitutionsType
29-
from ..substitution import Substitution
3029

3130

3231
@expose_substitution('launch_log_dir')
3332
@expose_substitution('log_dir')
34-
class LaunchLogDir(Substitution):
33+
class LaunchLogDir(PathSubstitution):
3534
"""Substitution that returns the absolute path to the current launch log directory."""
3635

3736
def __init__(self) -> None:
3837
"""Create a LaunchLogDir substitution."""
39-
super().__init__()
38+
super().__init__(self)
4039

4140
@classmethod
4241
def parse(cls, data: Sequence[SomeSubstitutionsType]

launch/launch/substitutions/this_launch_file_dir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
from typing import Type
2323

2424

25+
from .path_join_substitution import PathSubstitution
2526
from .substitution_failure import SubstitutionFailure
2627
from ..frontend.expose import expose_substitution
2728
from ..launch_context import LaunchContext
2829
from ..some_substitutions_type import SomeSubstitutionsType
29-
from ..substitution import Substitution
3030

3131

3232
@expose_substitution('dirname')
33-
class ThisLaunchFileDir(Substitution):
33+
class ThisLaunchFileDir(PathSubstitution):
3434
"""Substitution that returns the absolute path to the current launch file."""
3535

3636
def __init__(self) -> None:
3737
"""Create a ThisLaunchFileDir substitution."""
38-
super().__init__()
38+
super().__init__(self)
3939

4040
@classmethod
4141
def parse(cls, data: Sequence[SomeSubstitutionsType]

launch/test/launch/substitutions/test_launch_log_dir.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def test_launch_log_dir_methods():
3232
assert lld.perform(lc)
3333

3434

35+
def test_launch_log_dir_path():
36+
test_dir = LaunchLogDir() / 'subdir'
37+
lc = LaunchContext()
38+
result = test_dir.perform(lc)
39+
assert result
40+
assert result.endswith('subdir')
41+
42+
3543
def test_launch_log_dir_frontend():
3644
"""Test launch_log_dir/log_dir frontend substitutions."""
3745
for sub in ('launch_log_dir', 'log_dir'):

launch/test/launch/substitutions/test_this_launch_file_dir.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Tests for the ThisLaunchFileDir substitution class."""
1616

17+
import os
18+
1719
from launch import LaunchContext
1820
from launch.substitutions import SubstitutionFailure
1921
from launch.substitutions import ThisLaunchFileDir
@@ -35,3 +37,10 @@ def test_this_launch_file_path_methods():
3537
tlfp.perform(lc)
3638
lc.extend_locals({'current_launch_file_directory': 'foo'})
3739
assert tlfp.perform(lc) == 'foo'
40+
41+
42+
def test_this_launch_file_dir_pathing():
43+
test_file = ThisLaunchFileDir() / 'some_launch.xml'
44+
lc = LaunchContext()
45+
lc.extend_locals({'current_launch_file_directory': 'foo'})
46+
assert test_file.perform(lc) == os.path.join('foo', 'some_launch.xml')

0 commit comments

Comments
 (0)