Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(check_caret_rclcpp): skip check_caret_rclcpp for ROS Distributions after iron #135

Merged
merged 7 commits into from
Dec 27, 2023
Merged
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
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]