From 3c054f2f595576cdf12ee5c2ea3fc636d1608ddb Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Thu, 30 Jan 2025 21:53:30 -0500 Subject: [PATCH 1/6] Created test_communications.py --- tests/unit/test_communications.py | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/unit/test_communications.py diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py new file mode 100644 index 00000000..da21d226 --- /dev/null +++ b/tests/unit/test_communications.py @@ -0,0 +1,96 @@ +""" +Tests the communications class. +""" + +import pytest + +from modules.communications import communications +from modules.common.modules.logger import logger +from modules import object_in_world +from modules.common.modules import position_global + + +# Test functions use test fixture signature names and access class privates +# No enable +# pylint: disable=protected-access,redefined-outer-name + +@pytest.fixture +def communications_maker() -> communications.Communications: # type: ignore + """ + Construct a Communications instance with the Home position + """ + result, test_logger = logger.Logger.create("test_logger", False) + + assert result + assert test_logger is not None + + result, home_position = position_global.PositionGlobal.create(0, 0, 0) + assert result + assert home_position is not None + + result, communications_instance = communications.Communications.create(home_position, test_logger) + assert result + assert communications_instance is not None + + yield communications_instance # type: ignore + +class TestCommunications: + """ + Tests for the Communications.run() method. + """ + + def test_normal_data( + self, communications_maker: communications.Communications + ): + """ + Deal with one data to test if it works + """ + # Setup + result, object = object_in_world.ObjectInWorld.create(10, 20, 1.0) + + assert result + assert object is not None + objects_in_world = [object] + + # Run + result, generated_objects = communications_maker.run(objects_in_world) + + # Test + assert result + assert generated_objects is not None + + + def test_correct_data_structure( + self, communications_maker: communications.Communications, + ): + """ + Check if the coordinates are converted into the correct data structure + """ + + # Setup + result, obj_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + assert result + assert obj_1 is not None + + result, obj_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + assert result + assert obj_2 is not None + + result, obj_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + assert result + assert obj_3 is not None + + objects_in_world = [obj_1, obj_2, obj_3] + + # Run + result, generated_objects = communications_maker.run(objects_in_world) + assert result + assert generated_objects is not None + + # Test + assert isinstance(generated_objects, list) + + for object in generated_objects: + # looks like it returns back the object_world + #assert isinstance(object, position_global.PositionGlobal) + assert isinstance(object, object_in_world.ObjectInWorld) \ No newline at end of file From e9b7cfa7fd4f1760de4ded113cf0c497aaba60a7 Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:25:30 -0500 Subject: [PATCH 2/6] Modified the test to match the PR --- tests/unit/test_communications.py | 63 +++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py index da21d226..b7d1147b 100644 --- a/tests/unit/test_communications.py +++ b/tests/unit/test_communications.py @@ -7,13 +7,17 @@ from modules.communications import communications from modules.common.modules.logger import logger from modules import object_in_world +from modules.common.modules import position_local +from modules.common.modules.mavlink import local_global_conversion from modules.common.modules import position_global - +from modules.common.modules.data_encoding import metadata_encoding_decoding +from modules.common.modules.data_encoding import message_encoding_decoding # Test functions use test fixture signature names and access class privates # No enable # pylint: disable=protected-access,redefined-outer-name + @pytest.fixture def communications_maker() -> communications.Communications: # type: ignore """ @@ -28,29 +32,29 @@ def communications_maker() -> communications.Communications: # type: ignore assert result assert home_position is not None - result, communications_instance = communications.Communications.create(home_position, test_logger) + result, communications_instance = communications.Communications.create( + home_position, test_logger + ) assert result assert communications_instance is not None yield communications_instance # type: ignore + class TestCommunications: """ Tests for the Communications.run() method. """ - def test_normal_data( - self, communications_maker: communications.Communications - ): + def test_normal_data(self, communications_maker: communications.Communications) -> None: """ Deal with one data to test if it works """ # Setup - result, object = object_in_world.ObjectInWorld.create(10, 20, 1.0) - + result, local_position = object_in_world.ObjectInWorld.create(10, 20, 1.0) assert result - assert object is not None - objects_in_world = [object] + assert local_position is not None + objects_in_world = [local_position] # Run result, generated_objects = communications_maker.run(objects_in_world) @@ -58,15 +62,15 @@ def test_normal_data( # Test assert result assert generated_objects is not None - def test_correct_data_structure( - self, communications_maker: communications.Communications, - ): + self, + communications_maker: communications.Communications, + ) -> None: """ Check if the coordinates are converted into the correct data structure """ - + # Setup result, obj_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) assert result @@ -80,17 +84,36 @@ def test_correct_data_structure( assert result assert obj_3 is not None + result, home_position = position_global.PositionGlobal.create(0, 0, 0) + assert result + assert home_position is not None + objects_in_world = [obj_1, obj_2, obj_3] - + # Run result, generated_objects = communications_maker.run(objects_in_world) assert result assert generated_objects is not None # Test - assert isinstance(generated_objects, list) - - for object in generated_objects: - # looks like it returns back the object_world - #assert isinstance(object, position_global.PositionGlobal) - assert isinstance(object, object_in_world.ObjectInWorld) \ No newline at end of file + for i, generated_object in enumerate(generated_objects): + + # should convert the byte to positionGlobal + result, worker_id, generated_object = message_encoding_decoding.decode_bytes_to_position_global(generated_object) + assert result + assert generated_object is not None + assert worker_id is not None + + # convert the input data to position local + result, object_position_local = position_local.PositionLocal.create( + objects_in_world[i].location_x, east=objects_in_world[i].location_y, down=0.0 + ) + assert result + + # convert the input data to position global for comparison + result, expected = local_global_conversion.position_global_from_position_local( + home_position, object_position_local + ) + assert result + + assert generated_object == expected From ce65458c411c01988396958a7971ab90ca5468b3 Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Sat, 8 Feb 2025 03:17:51 -0500 Subject: [PATCH 3/6] wrote communications unit test and fix typo in communications --- modules/communications/communications.py | 2 +- tests/unit/test_communications.py | 280 +++++++++++++++++++---- 2 files changed, 241 insertions(+), 41 deletions(-) diff --git a/modules/communications/communications.py b/modules/communications/communications.py index dcb29595..0226511f 100644 --- a/modules/communications/communications.py +++ b/modules/communications/communications.py @@ -91,7 +91,7 @@ def run( self.__logger.info(f"{time.time()}: {objects_in_world_global}") encoded_position_global_objects = [] - for object in object_in_world_global: + for object in objects_in_world_global: result, message = message_encoding_decoding.encode_position_global( worker_enum.WorkerEnum.COMMUNICATIONS_WORKER, object diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py index b7d1147b..92805910 100644 --- a/tests/unit/test_communications.py +++ b/tests/unit/test_communications.py @@ -17,9 +17,27 @@ # No enable # pylint: disable=protected-access,redefined-outer-name +LATITUDE_TOLERANCE = 0.000001 +LONGITUDE_TOLERANCE = 0.000001 +ALTITUDE_TOLERANCE = 7 + @pytest.fixture -def communications_maker() -> communications.Communications: # type: ignore +def home_position() -> position_global.PositionGlobal: # type: ignore + """ + Home position. + """ + result, position = position_global.PositionGlobal.create(43.472978, -80.540103, 336.0) + assert result + assert position is not None + + yield position + + +@pytest.fixture +def communications_maker( + home_position: position_global.PositionGlobal, +) -> communications.Communications: # type: ignore """ Construct a Communications instance with the Home position """ @@ -28,10 +46,6 @@ def communications_maker() -> communications.Communications: # type: ignore assert result assert test_logger is not None - result, home_position = position_global.PositionGlobal.create(0, 0, 0) - assert result - assert home_position is not None - result, communications_instance = communications.Communications.create( home_position, test_logger ) @@ -41,79 +55,265 @@ def communications_maker() -> communications.Communications: # type: ignore yield communications_instance # type: ignore +def object_in_world_from_position_local( + position_local: position_local.PositionLocal, +) -> object_in_world.ObjectInWorld: + """ + Convert position local to object_in_world as defined in Communications.py + """ + result, obj = object_in_world.ObjectInWorld.create( + position_local.north, position_local.east, 0.0 + ) + assert result + assert obj is not None + + return obj + + +def assert_global_positions( + expected: position_global.PositionGlobal, actual: position_global.PositionGlobal +) -> None: + """ + Assert each values of the global positions using the Tolerances + """ + assert abs(expected.latitude - actual.latitude) < LATITUDE_TOLERANCE + assert abs(expected.longitude - actual.longitude) < LONGITUDE_TOLERANCE + assert abs(expected.altitude - actual.altitude) < ALTITUDE_TOLERANCE + + class TestCommunications: """ Tests for the Communications.run() method. """ - def test_normal_data(self, communications_maker: communications.Communications) -> None: + def test_run( + self, + home_position: position_global.PositionGlobal, + communications_maker: communications.Communications, + ) -> None: """ - Deal with one data to test if it works + Test if the Communications.run returns the correct instance """ # Setup - result, local_position = object_in_world.ObjectInWorld.create(10, 20, 1.0) + result, position = position_global.PositionGlobal.create(43.472978, -80.540103, 336.0) assert result - assert local_position is not None - objects_in_world = [local_position] + assert position is not None + + result, actual = local_global_conversion.position_local_from_position_global( + home_position, position + ) + assert result + assert actual is not None + + objects_in_world = [object_in_world_from_position_local(actual)] # Run - result, generated_objects = communications_maker.run(objects_in_world) + result, metadata, generated_objects = communications_maker.run(objects_in_world) # Test assert result + assert isinstance(metadata, bytes) + for generated_object in generated_objects: + assert isinstance(generated_object, bytes) + + def test_normal( + self, + home_position: position_global.PositionGlobal, + communications_maker: communications.Communications, + ) -> None: + """ + Normal + """ + # Setup + result, global_position_1 = position_global.PositionGlobal.create( + 43.472978, -80.540103, 336.0 + ) + assert result + assert global_position_1 is not None + + result, local_position_1 = local_global_conversion.position_local_from_position_global( + home_position, global_position_1 + ) + assert result + assert local_position_1 is not None + + result, global_position_2 = position_global.PositionGlobal.create( + 43.472800, -80.539500, 330.0 + ) + assert result + assert global_position_2 is not None + + result, local_position_2 = local_global_conversion.position_local_from_position_global( + home_position, global_position_2 + ) + assert result + assert local_position_2 is not None + + objects_in_world = [ + object_in_world_from_position_local(local_position_1), + object_in_world_from_position_local(local_position_2), + ] + number_of_messages = 2 + + # Run + result, metadata, generated_objects = communications_maker.run(objects_in_world) + assert result + assert metadata is not None assert generated_objects is not None - def test_correct_data_structure( + result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( + metadata + ) + assert result + assert worker_id is not None + assert actual_number_of_messages is not None + + # Test + assert actual_number_of_messages == number_of_messages + + # Conversion + result, worker_id, actual_1 = message_encoding_decoding.decode_bytes_to_position_global( + generated_objects[0] + ) + assert result + assert worker_id is not None + assert actual_1 is not None + + result, worker_id, actual_2 = message_encoding_decoding.decode_bytes_to_position_global( + generated_objects[1] + ) + assert result + assert worker_id is not None + assert actual_2 is not None + + # Test + assert_global_positions(global_position_1, actual_1) + assert_global_positions(global_position_2, actual_2) + + def test_empty_objects( self, communications_maker: communications.Communications, ) -> None: """ - Check if the coordinates are converted into the correct data structure + When nothing is passed in """ + objects_in_world = [] + + result, metadata, generated_objects = communications_maker.run(objects_in_world) + assert result + assert metadata is not None + assert generated_objects is not None + + result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( + metadata + ) + + # it will encounter an error where metadata is failed to encode + assert result + assert worker_id is not None + assert actual_number_of_messages is not None + + # Test + assert actual_number_of_messages == 0 + assert len(generated_objects) == 0 + def test_same_as_home( + self, + home_position: position_global.PositionGlobal, + communications_maker: communications.Communications, + ) -> None: + """ + When the objects_in_world contains the home positions + """ # Setup - result, obj_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + result, local_position = local_global_conversion.position_local_from_position_global( + home_position, home_position + ) + assert result + assert local_position is not None + + actual = object_in_world_from_position_local(local_position) + objects_in_world = [actual] + number_of_messages = 1 + + # Run + result, metadata, generated_objects = communications_maker.run(objects_in_world) + assert result + assert metadata is not None + assert generated_objects is not None + + # Conversion + result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( + metadata + ) assert result - assert obj_1 is not None + assert worker_id is not None + assert actual_number_of_messages is not None + + # Test + assert actual_number_of_messages == number_of_messages - result, obj_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + # Conversion + result, worker_id, actual = message_encoding_decoding.decode_bytes_to_position_global( + generated_objects[0] + ) assert result - assert obj_2 is not None + assert worker_id is not None + assert actual is not None - result, obj_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + # Test + assert_global_positions(home_position, actual) + + def test_duplicate_coordinates( + self, + home_position: position_global.PositionGlobal, + communications_maker: communications.Communications, + ) -> None: + """ + When the objects_in_world contains duplicate positions + """ + # Setup + result, global_position = position_global.PositionGlobal.create( + 43.472978, -80.540103, 336.0 + ) assert result - assert obj_3 is not None + assert global_position is not None - result, home_position = position_global.PositionGlobal.create(0, 0, 0) + result, local_position = local_global_conversion.position_local_from_position_global( + home_position, global_position + ) assert result - assert home_position is not None + assert local_position is not None - objects_in_world = [obj_1, obj_2, obj_3] + position = object_in_world_from_position_local(local_position) + + objects_in_world = [position, position, position] + number_of_messages = 3 # Run - result, generated_objects = communications_maker.run(objects_in_world) + result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result + assert metadata is not None assert generated_objects is not None - # Test - for i, generated_object in enumerate(generated_objects): + result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( + metadata + ) + assert result + assert worker_id is not None + assert actual_number_of_messages is not None - # should convert the byte to positionGlobal - result, worker_id, generated_object = message_encoding_decoding.decode_bytes_to_position_global(generated_object) - assert result - assert generated_object is not None - assert worker_id is not None + # Test + assert actual_number_of_messages == number_of_messages - # convert the input data to position local - result, object_position_local = position_local.PositionLocal.create( - objects_in_world[i].location_x, east=objects_in_world[i].location_y, down=0.0 + for generated_object in generated_objects: + # Conversion + result, worker_id, actual = message_encoding_decoding.decode_bytes_to_position_global( + generated_object ) assert result + assert worker_id is not None + assert actual is not None - # convert the input data to position global for comparison - result, expected = local_global_conversion.position_global_from_position_local( - home_position, object_position_local - ) - assert result - - assert generated_object == expected + # Test + assert_global_positions(global_position, actual) From 52986217708775385bb49493320dbac727d9766c Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:44:49 -0500 Subject: [PATCH 4/6] Fixed all the comments --- modules/communications/communications.py | 2 + tests/unit/test_communications.py | 56 +++++++++++++++++------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/modules/communications/communications.py b/modules/communications/communications.py index 0226511f..f43edb70 100644 --- a/modules/communications/communications.py +++ b/modules/communications/communications.py @@ -57,6 +57,8 @@ def run( ) -> tuple[True, bytes, list[bytes]] | tuple[False, None, None]: objects_in_world_global = [] + objects_in_world = objects_in_world or [] + for object_in_world in objects_in_world: # We assume detected objects are on the ground north = object_in_world.location_x diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py index 92805910..97c9b923 100644 --- a/tests/unit/test_communications.py +++ b/tests/unit/test_communications.py @@ -27,6 +27,7 @@ def home_position() -> position_global.PositionGlobal: # type: ignore """ Home position. """ + # University of Waterloo WGS84 Coordinate result, position = position_global.PositionGlobal.create(43.472978, -80.540103, 336.0) assert result assert position is not None @@ -149,11 +150,13 @@ def test_normal( assert result assert local_position_2 is not None + global_positions = [global_position_1, global_position_2] + objects_in_world = [ object_in_world_from_position_local(local_position_1), object_in_world_from_position_local(local_position_2), ] - number_of_messages = 2 + number_of_messages = len(objects_in_world) # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) @@ -172,32 +175,51 @@ def test_normal( assert actual_number_of_messages == number_of_messages # Conversion - result, worker_id, actual_1 = message_encoding_decoding.decode_bytes_to_position_global( - generated_objects[0] - ) + for i, global_position in enumerate(global_positions): + result, worker_id, actual = message_encoding_decoding.decode_bytes_to_position_global( + generated_objects[i] + ) + assert result + assert worker_id is not None + assert actual is not None + + assert_global_positions(global_position, actual) + + def test_empty_objects( + self, + communications_maker: communications.Communications, + ) -> None: + """ + When nothing is passed in + """ + objects_in_world = [] + + result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result - assert worker_id is not None - assert actual_1 is not None + assert metadata is not None + assert generated_objects is not None - result, worker_id, actual_2 = message_encoding_decoding.decode_bytes_to_position_global( - generated_objects[1] + result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( + metadata ) + + # it will encounter an error where metadata is failed to encode assert result assert worker_id is not None - assert actual_2 is not None + assert actual_number_of_messages is not None # Test - assert_global_positions(global_position_1, actual_1) - assert_global_positions(global_position_2, actual_2) + assert actual_number_of_messages == 0 + assert len(generated_objects) == 0 - def test_empty_objects( + def test_none( self, - communications_maker: communications.Communications, + communications_maker: communications.Communications ) -> None: """ - When nothing is passed in + When None is passed in """ - objects_in_world = [] + objects_in_world = None result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result @@ -234,7 +256,7 @@ def test_same_as_home( actual = object_in_world_from_position_local(local_position) objects_in_world = [actual] - number_of_messages = 1 + number_of_messages = len(objects_in_world) # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) @@ -288,7 +310,7 @@ def test_duplicate_coordinates( position = object_in_world_from_position_local(local_position) objects_in_world = [position, position, position] - number_of_messages = 3 + number_of_messages = len(objects_in_world) # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) From be98e98c4fc9cb95201ccd2ecbbc5da4c4c41547 Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:47:53 -0500 Subject: [PATCH 5/6] style: auto-format code with linter --- modules/communications/communications.py | 2 +- tests/unit/test_communications.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/communications/communications.py b/modules/communications/communications.py index f43edb70..0fbb7e77 100644 --- a/modules/communications/communications.py +++ b/modules/communications/communications.py @@ -58,7 +58,7 @@ def run( objects_in_world_global = [] objects_in_world = objects_in_world or [] - + for object_in_world in objects_in_world: # We assume detected objects are on the ground north = object_in_world.location_x diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py index 97c9b923..ea54c27d 100644 --- a/tests/unit/test_communications.py +++ b/tests/unit/test_communications.py @@ -212,10 +212,7 @@ def test_empty_objects( assert actual_number_of_messages == 0 assert len(generated_objects) == 0 - def test_none( - self, - communications_maker: communications.Communications - ) -> None: + def test_none(self, communications_maker: communications.Communications) -> None: """ When None is passed in """ From 77913cca2c4a334806973a07c037f6cb46e29bad Mon Sep 17 00:00:00 2001 From: Adrian <88257959+agslaj-ALock@users.noreply.github.com> Date: Sun, 9 Feb 2025 21:46:20 -0500 Subject: [PATCH 6/6] fix: resolve issues from code review --- modules/communications/communications.py | 1 - tests/unit/test_communications.py | 70 ++++++------------------ 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/modules/communications/communications.py b/modules/communications/communications.py index 0fbb7e77..88548a00 100644 --- a/modules/communications/communications.py +++ b/modules/communications/communications.py @@ -57,7 +57,6 @@ def run( ) -> tuple[True, bytes, list[bytes]] | tuple[False, None, None]: objects_in_world_global = [] - objects_in_world = objects_in_world or [] for object_in_world in objects_in_world: # We assume detected objects are on the ground diff --git a/tests/unit/test_communications.py b/tests/unit/test_communications.py index ea54c27d..c646d8f6 100644 --- a/tests/unit/test_communications.py +++ b/tests/unit/test_communications.py @@ -12,6 +12,7 @@ from modules.common.modules import position_global from modules.common.modules.data_encoding import metadata_encoding_decoding from modules.common.modules.data_encoding import message_encoding_decoding +from modules.common.modules.data_encoding.worker_enum import WorkerEnum # Test functions use test fixture signature names and access class privates # No enable @@ -114,8 +115,7 @@ def test_run( # Test assert result assert isinstance(metadata, bytes) - for generated_object in generated_objects: - assert isinstance(generated_object, bytes) + assert all(isinstance(obj, bytes) for obj in generated_objects) def test_normal( self, @@ -161,15 +161,14 @@ def test_normal( # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result - assert metadata is not None - assert generated_objects is not None + assert isinstance(metadata, bytes) + assert all(isinstance(obj, bytes) for obj in generated_objects) result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( metadata ) assert result - assert worker_id is not None - assert actual_number_of_messages is not None + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert actual_number_of_messages == number_of_messages @@ -180,8 +179,7 @@ def test_normal( generated_objects[i] ) assert result - assert worker_id is not None - assert actual is not None + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER assert_global_positions(global_position, actual) @@ -196,42 +194,15 @@ def test_empty_objects( result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result - assert metadata is not None - assert generated_objects is not None - - result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( - metadata - ) - - # it will encounter an error where metadata is failed to encode - assert result - assert worker_id is not None - assert actual_number_of_messages is not None - - # Test - assert actual_number_of_messages == 0 - assert len(generated_objects) == 0 - - def test_none(self, communications_maker: communications.Communications) -> None: - """ - When None is passed in - """ - objects_in_world = None - - result, metadata, generated_objects = communications_maker.run(objects_in_world) - assert result - assert metadata is not None - assert generated_objects is not None + assert isinstance(metadata, bytes) + assert all(isinstance(obj, bytes) for obj in generated_objects) result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( metadata ) - # it will encounter an error where metadata is failed to encode assert result - assert worker_id is not None - assert actual_number_of_messages is not None - + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert actual_number_of_messages == 0 assert len(generated_objects) == 0 @@ -258,16 +229,14 @@ def test_same_as_home( # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result - assert metadata is not None - assert generated_objects is not None - + assert isinstance(metadata, bytes) + assert all(isinstance(obj, bytes) for obj in generated_objects) # Conversion result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( metadata ) assert result - assert worker_id is not None - assert actual_number_of_messages is not None + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert actual_number_of_messages == number_of_messages @@ -277,8 +246,7 @@ def test_same_as_home( generated_objects[0] ) assert result - assert worker_id is not None - assert actual is not None + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert_global_positions(home_position, actual) @@ -312,16 +280,14 @@ def test_duplicate_coordinates( # Run result, metadata, generated_objects = communications_maker.run(objects_in_world) assert result - assert metadata is not None - assert generated_objects is not None + assert isinstance(metadata, bytes) + assert all(isinstance(obj, bytes) for obj in generated_objects) result, worker_id, actual_number_of_messages = metadata_encoding_decoding.decode_metadata( metadata ) assert result - assert worker_id is not None - assert actual_number_of_messages is not None - + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert actual_number_of_messages == number_of_messages @@ -331,8 +297,6 @@ def test_duplicate_coordinates( generated_object ) assert result - assert worker_id is not None - assert actual is not None - + assert worker_id == WorkerEnum.COMMUNICATIONS_WORKER # Test assert_global_positions(global_position, actual)