Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions launch/launch/substitutions/launch_log_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
from typing import Tuple
from typing import Type


from .path_join_substitution import PathSubstitution
from ..frontend.expose import expose_substitution
from ..launch_context import LaunchContext
from ..logging import launch_config as launch_logging_config
from ..some_substitutions_type import SomeSubstitutionsType
from ..substitution import Substitution


@expose_substitution('launch_log_dir')
@expose_substitution('log_dir')
class LaunchLogDir(Substitution):
class LaunchLogDir(PathSubstitution):
"""Substitution that returns the absolute path to the current launch log directory."""

def __init__(self) -> None:
"""Create a LaunchLogDir substitution."""
super().__init__()
super().__init__(path=self)

@classmethod
def parse(cls, data: Sequence[SomeSubstitutionsType]
Expand Down
6 changes: 3 additions & 3 deletions launch/launch/substitutions/this_launch_file_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
from typing import Type


from .path_join_substitution import PathSubstitution
from .substitution_failure import SubstitutionFailure
from ..frontend.expose import expose_substitution
from ..launch_context import LaunchContext
from ..some_substitutions_type import SomeSubstitutionsType
from ..substitution import Substitution


@expose_substitution('dirname')
class ThisLaunchFileDir(Substitution):
class ThisLaunchFileDir(PathSubstitution):
"""Substitution that returns the absolute path to the current launch file."""

def __init__(self) -> None:
"""Create a ThisLaunchFileDir substitution."""
super().__init__()
super().__init__(path=self)

@classmethod
def parse(cls, data: Sequence[SomeSubstitutionsType]
Expand Down
8 changes: 8 additions & 0 deletions launch/test/launch/substitutions/test_launch_log_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def test_launch_log_dir_methods():
assert lld.perform(lc)


def test_launch_log_dir_path():
test_dir = LaunchLogDir() / 'subdir'
lc = LaunchContext()
result = test_dir.perform(lc)
assert result
assert result.endswith('subdir')


def test_launch_log_dir_frontend():
"""Test launch_log_dir/log_dir frontend substitutions."""
for sub in ('launch_log_dir', 'log_dir'):
Expand Down
9 changes: 9 additions & 0 deletions launch/test/launch/substitutions/test_this_launch_file_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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

import os

from launch import LaunchContext
from launch.substitutions import SubstitutionFailure
from launch.substitutions import ThisLaunchFileDir
Expand All @@ -35,3 +37,10 @@ def test_this_launch_file_path_methods():
tlfp.perform(lc)
lc.extend_locals({'current_launch_file_directory': 'foo'})
assert tlfp.perform(lc) == 'foo'


def test_this_launch_file_dir_pathing():
test_file = ThisLaunchFileDir() / 'some_launch.xml'
lc = LaunchContext()
lc.extend_locals({'current_launch_file_directory': 'foo'})
assert test_file.perform(lc) == os.path.join('foo', 'some_launch.xml')