Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: ymski <[email protected]>
  • Loading branch information
ymski committed Dec 21, 2023
1 parent 950a4c3 commit 552702e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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,13 @@ 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 validate the workspace.' in caplog.messages[0]

0 comments on commit 552702e

Please sign in to comment.