@@ -661,10 +661,7 @@ def fail_send_message(message, callback):
661661 pytest .param (1.5 , id = "Float input" ),
662662 pytest .param (b"message" , id = "Bytes input" ),
663663 pytest .param (bytearray (b"message" ), id = "Bytearray input" ),
664- pytest .param (object (), id = "Object input" ),
665664 pytest .param (None , id = "None input" ),
666- pytest .param ([1 , "str" ], id = "List input" ),
667- pytest .param ({"a" : 2 }, id = "Dictionary input" ),
668665 ],
669666 )
670667 async def test_wraps_data_in_message_and_calls_pipeline_send_message (
@@ -676,6 +673,23 @@ async def test_wraps_data_in_message_and_calls_pipeline_send_message(
676673 assert isinstance (sent_message , Message )
677674 assert sent_message .data == message_input
678675
676+ @pytest .mark .it ("Raises TypeError when the message data type is unsupported" )
677+ @pytest .mark .parametrize (
678+ "message_input" ,
679+ [
680+ pytest .param (object (), id = "Object input" ),
681+ pytest .param ([1 , "str" ], id = "List input" ),
682+ pytest .param ({"a" : 2 }, id = "Dictionary input" ),
683+ ],
684+ )
685+ async def test_raises_type_error_for_unsupported_message_data (
686+ self , client , mqtt_pipeline , message_input
687+ ):
688+ with pytest .raises (TypeError , match = "Message data must be" ):
689+ await client .send_message (message_input )
690+
691+ assert mqtt_pipeline .send_message .call_count == 0
692+
679693 @pytest .mark .it ("Validates message size at the 256 KB boundary" )
680694 @pytest .mark .parametrize (
681695 "size_delta, raises_error" ,
@@ -2049,10 +2063,7 @@ def fail_send_output_message(message, callback):
20492063 pytest .param (1.5 , id = "Float input" ),
20502064 pytest .param (b"message" , id = "Bytes input" ),
20512065 pytest .param (bytearray (b"message" ), id = "Bytearray input" ),
2052- pytest .param (object (), id = "Object input" ),
20532066 pytest .param (None , id = "None input" ),
2054- pytest .param ([1 , "str" ], id = "List input" ),
2055- pytest .param ({"a" : 2 }, id = "Dictionary input" ),
20562067 ],
20572068 )
20582069 async def test_send_message_to_output_calls_pipeline_wraps_data_in_message (
@@ -2065,6 +2076,23 @@ async def test_send_message_to_output_calls_pipeline_wraps_data_in_message(
20652076 assert isinstance (sent_message , Message )
20662077 assert sent_message .data == message_input
20672078
2079+ @pytest .mark .it ("Raises TypeError when the message data type is unsupported" )
2080+ @pytest .mark .parametrize (
2081+ "message_input" ,
2082+ [
2083+ pytest .param (object (), id = "Object input" ),
2084+ pytest .param ([1 , "str" ], id = "List input" ),
2085+ pytest .param ({"a" : 2 }, id = "Dictionary input" ),
2086+ ],
2087+ )
2088+ async def test_raises_type_error_for_unsupported_message_data (
2089+ self , client , mqtt_pipeline , message_input
2090+ ):
2091+ with pytest .raises (TypeError , match = "Message data must be" ):
2092+ await client .send_message_to_output (message_input , "some_output" )
2093+
2094+ assert mqtt_pipeline .send_output_message .call_count == 0
2095+
20682096 @pytest .mark .it ("Validates message size at the 256 KB boundary" )
20692097 @pytest .mark .parametrize (
20702098 "size_delta, raises_error" ,
0 commit comments