Skip to content

Commit

Permalink
fix(check_caret_rclcpp): skip check_caret_rclcpp for ROS Distribution…
Browse files Browse the repository at this point in the history
…s after iron (#135)

* fix(check_caret_rclcpp): skip check_caret_rclcpp for ROS Distributions after iron

Signed-off-by: ymski <[email protected]>

* refactor: fix log message

Signed-off-by: ymski <[email protected]>

* fix typo

Signed-off-by: ymski <[email protected]>

* fix style

Signed-off-by: ymski <[email protected]>

* add test

Signed-off-by: ymski <[email protected]>

* modify message

Signed-off-by: ymski <[email protected]>

* style

Signed-off-by: ymski <[email protected]>

---------

Signed-off-by: ymski <[email protected]>
  • Loading branch information
ymski authored Dec 27, 2023
1 parent be98213 commit b281acc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ros2caret/verb/check_caret_rclcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class RclcppCheck():

def __init__(self, root_dir_path: str) -> None:
RclcppCheck._ensure_dir_exist(root_dir_path)
RclcppCheck._validate_ros_distribution(root_dir_path)

get_package_name = RclcppCheck._create_get_package_name(root_dir_path)
ros_obj_paths = RclcppCheck._get_obj_paths(root_dir_path)
Expand Down Expand Up @@ -171,6 +172,15 @@ def _ensure_dir_exist(path: str):
'where the build command completed.')
exit(1)

@staticmethod
def _validate_ros_distribution(path: str):
distribution = os.environ['ROS_DISTRO']
if distribution[0] < 'i':
return
logger.info('There is no need to build packages '
f'using caret-rclcpp under ROS 2 {distribution}.')
exit(0)

@staticmethod
def get_package_name_from_path(root_dir_path: str, path: str) -> str:
package_name = path.replace(root_dir_path, '').split('/')[0]
Expand Down
17 changes: 17 additions & 0 deletions test/verb/test_check_caret_rclcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TestCheckCaretRclcpp:

def test_file_exist(self, caplog, mocker):
mocker.patch('os.path.exists', return_value=True)
mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution',
return_value=None)
mocker.patch(
'ros2caret.verb.check_caret_rclcpp.RclcppCheck._get_obj_paths', return_value=[])
RclcppCheck('')
Expand All @@ -30,6 +32,8 @@ def test_file_exist(self, caplog, mocker):

def test_ng_case(self, caplog, mocker):
mocker.patch('os.path.exists', return_value=True)
mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution',
return_value=None)
base_path = 'ros2caret.verb.check_caret_rclcpp.RclcppCheck.'
mocker.patch(base_path+'_get_obj_paths', return_value=[''])
mocker.patch(base_path+'_has_caret_rclcpp_tp', return_value=False)
Expand All @@ -40,6 +44,8 @@ def test_ng_case(self, caplog, mocker):
assert record.levelno == WARNING

def test_ok_case(self, caplog, mocker):
mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution',
return_value=None)
mocker.patch('os.path.exists', return_value=True)
base_path = 'ros2caret.verb.check_caret_rclcpp.RclcppCheck.'
mocker.patch(base_path+'_get_obj_paths', return_value=[''])
Expand Down Expand Up @@ -69,3 +75,14 @@ def test_get_package_name(self):

get_package_name = RclcppCheck._create_get_package_name('foo/bar/')
assert get_package_name('foo/bar/baz') == 'baz'

def test_validate_ros_distribution(self, mocker, caplog):
mocker.patch('os.path.exists', return_value=True)
mocker.patch.dict('os.environ', {'ROS_DISTRO': 'iron'})

try:
RclcppCheck('')
except SystemExit:
assert len(caplog.records) == 1
assert 'There is no need to build packages ' \
'using caret-rclcpp under ROS 2 iron.' in caplog.messages[0]

0 comments on commit b281acc

Please sign in to comment.