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

Make use of ros_testing to test policy generation. #214

Merged
merged 9 commits into from
Jun 21, 2020
2 changes: 2 additions & 0 deletions sros2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<test_depend>ament_mypy</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<!-- Single entrypoint to depend on launch based testing -->
<test_depend>ros_testing</test_depend>
mikaelarguedas marked this conversation as resolved.
Show resolved Hide resolved
<test_depend>test_msgs</test_depend>

<export>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import rclpy
from rclpy.node import Node

import test_msgs.srv


class ClientServiceNode(Node):
Copy link
Member

@kyrofa kyrofa May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this (and other similar constructs) be turned into an actual pytest fixture on a conftest.py somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer is no, because test_generate_policy*.py is no longer a pytest, but a pytest-run launch test.


def __init__(self, name='client_srv_node'):
super().__init__(name)
self.client = self.create_client(test_msgs.srv.Empty, '~/client')
self.service = self.create_service(
test_msgs.srv.Empty, '~/server', lambda request, response: response
)

def destroy_node(self):
self.client.destroy()
self.service.destroy()
super().destroy_node()


def main(args=None):
rclpy.init(args=args)

node = ClientServiceNode()

try:
rclpy.spin(node)
except KeyboardInterrupt:
print('node stopped cleanly')
finally:
node.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
main()
54 changes: 54 additions & 0 deletions sros2/test/sros2/commands/security/verbs/fixtures/pub_sub_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import rclpy
from rclpy.node import Node

import test_msgs.msg


class PubSubNode(Node):

def __init__(self, name='pub_sub_node'):
super().__init__(name)

self.publisher = self.create_publisher(
test_msgs.msg.Strings, '~/pub', 1
)
self.subscription = self.create_subscription(
test_msgs.msg.Strings, '~/sub', lambda msg: None, 1
)

def destroy_node(self):
self.publisher.destroy()
self.subscription.destroy()
super().destroy_node()


def main(args=None):
rclpy.init(args=args)

node = PubSubNode()

try:
rclpy.spin(node)
except KeyboardInterrupt:
print('node stopped cleanly')
finally:
node.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
main()
Loading