From 87adf72f1ce941dc41a1f7395a5d93c7300123e3 Mon Sep 17 00:00:00 2001 From: texhnolyze Date: Mon, 16 Dec 2024 19:25:06 +0100 Subject: [PATCH] test(colcon): configure our pkgs to use `pytest` to ensure that the CI `colcon test` run works, because with a change to python 3.12 the `unittest` standard library used by default with colcon now exits with an error code of 5 for an empty test suite. Additionally removed old ros 1 integration tests. See: https://github.com/colcon/colcon-core/issues/678 See: https://github.com/python/cpython/pull/102051 --- package.xml | 2 +- setup.py | 1 + test/rostests/test_sender.launch | 10 -------- test/rostests/test_sender.py | 29 ----------------------- test/rostests/test_sender_receiver.launch | 13 ---------- test/rostests/test_sender_receiver.py | 28 ---------------------- test/udp_bridge/test_aes_helper.py | 9 +++++++ test/unit_tests/test_aes_helper.py | 22 ----------------- 8 files changed, 11 insertions(+), 103 deletions(-) delete mode 100644 test/rostests/test_sender.launch delete mode 100755 test/rostests/test_sender.py delete mode 100644 test/rostests/test_sender_receiver.launch delete mode 100755 test/rostests/test_sender_receiver.py create mode 100644 test/udp_bridge/test_aes_helper.py delete mode 100644 test/unit_tests/test_aes_helper.py diff --git a/package.xml b/package.xml index 559189d..a3b99d9 100644 --- a/package.xml +++ b/package.xml @@ -18,7 +18,7 @@ bitbots_utils python3-cryptography - python3-hypothesis + python3-pytest diff --git a/setup.py b/setup.py index 9ece56e..5a63bce 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ "launch", "setuptools", ], + tests_require=["pytest"], zip_safe=True, keywords=["ROS"], license="MIT", diff --git a/test/rostests/test_sender.launch b/test/rostests/test_sender.launch deleted file mode 100644 index 9854e27..0000000 --- a/test/rostests/test_sender.launch +++ /dev/null @@ -1,10 +0,0 @@ - - - --- - port: 1234 - target_ips: [ "127.0.0.1" ] - topics: [ "/test_topic" ] - - - - \ No newline at end of file diff --git a/test/rostests/test_sender.py b/test/rostests/test_sender.py deleted file mode 100755 index fa112db..0000000 --- a/test/rostests/test_sender.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 -import socket - -import rospy -from bitbots_test.test_case import RosNodeTestCase -from std_msgs import msg - - -class SenderTestCase(RosNodeTestCase): - def test_topic_gets_published_and_sent(self): - # setup makeshift receiver - port = rospy.get_param("/udp_bridge/port") - sock = socket.socket(type=socket.SOCK_DGRAM) - sock.bind(("127.0.0.1", port)) - sock.settimeout(1.0) - - # publish a test message - topic = rospy.get_param("/udp_bridge/topics")[0] - publisher = rospy.Publisher(topic, msg.String, latch=True, queue_size=1) - publisher.publish(msg.String("Hello World")) - - # assert that a message is sent by trying to receive it - self.with_assertion_grace_period(lambda: self.assertIsNotNone(sock.recv(10240)), 1000 * 5) - - -if __name__ == "__main__": - from bitbots_test import run_rostests - - run_rostests(SenderTestCase) diff --git a/test/rostests/test_sender_receiver.launch b/test/rostests/test_sender_receiver.launch deleted file mode 100644 index 7f2430d..0000000 --- a/test/rostests/test_sender_receiver.launch +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - --- - port: 1234 - target_ips: [ "127.0.0.1" ] - topics: [ "/test_topic" ] - - - - \ No newline at end of file diff --git a/test/rostests/test_sender_receiver.py b/test/rostests/test_sender_receiver.py deleted file mode 100755 index cf4fe80..0000000 --- a/test/rostests/test_sender_receiver.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 -from socket import gethostname - -import rospy -from bitbots_test.mocks import MockSubscriber -from bitbots_test.test_case import RosNodeTestCase -from std_msgs import msg - - -class SenderReceiverTestCase(RosNodeTestCase): - def test_sent_message_gets_received_over_bridge(self): - # setup - send_topic = rospy.get_param("/udp_bridge/topics")[0] - receive_topic = f"{gethostname()}/{send_topic}".replace("//", "/") - subscriber = MockSubscriber(receive_topic, msg.String) - - # execution - publisher = rospy.Publisher(send_topic, msg.String, latch=True, queue_size=1) - publisher.publish(msg.String("Hello World")) - - # verification - self.with_assertion_grace_period(subscriber.assertOneMessageReceived, 1000 * 5) - - -if __name__ == "__main__": - from bitbots_test import run_rostests - - run_rostests(SenderReceiverTestCase) diff --git a/test/udp_bridge/test_aes_helper.py b/test/udp_bridge/test_aes_helper.py new file mode 100644 index 0000000..bedf785 --- /dev/null +++ b/test/udp_bridge/test_aes_helper.py @@ -0,0 +1,9 @@ +from udp_bridge import aes_helper + + +def test_decrypt_inverts_encrypt(): + message = b"Hello, World!" + encrypted = aes_helper.AESCipher("key").encrypt(message) + decrypted = aes_helper.AESCipher("key").decrypt(encrypted) + + assert message == decrypted diff --git a/test/unit_tests/test_aes_helper.py b/test/unit_tests/test_aes_helper.py deleted file mode 100644 index 5452ab2..0000000 --- a/test/unit_tests/test_aes_helper.py +++ /dev/null @@ -1,22 +0,0 @@ -from bitbots_test.test_case import TestCase -from hypothesis import assume, given -from hypothesis.strategies import text - -from udp_bridge import aes_helper - - -class AesHelperTestCase(TestCase): - @given(text(), text()) - def test_decrypt_inverts_encrypt(self, message, key): - assume(message != "") - - enc_text = aes_helper.AESCipher(key).encrypt(message) - dec_text = aes_helper.AESCipher(key).decrypt(enc_text) - - self.assertEqual(message, dec_text) - - -if __name__ == "__main__": - from bitbots_test import run_unit_tests - - run_unit_tests(AesHelperTestCase)