1- import base64
21import datetime
32from unittest .mock import ANY , MagicMock , patch
43
@@ -657,7 +656,6 @@ def test_upload_file_binary_content(self, mock_boto3):
657656 client .data_plane_client .invoke_code_interpreter .return_value = mock_response
658657
659658 binary_content = b"\x89 PNG\r \n \x1a \n " # PNG header bytes
660- expected_b64 = base64 .b64encode (binary_content ).decode ("utf-8" )
661659
662660 # Act
663661 result = client .upload_file (path = "image.png" , content = binary_content )
@@ -667,7 +665,7 @@ def test_upload_file_binary_content(self, mock_boto3):
667665 codeInterpreterIdentifier = "test.identifier" ,
668666 sessionId = "test-session-id" ,
669667 name = "writeFiles" ,
670- arguments = {"content" : [{"path" : "image.png" , "blob" : expected_b64 }]},
668+ arguments = {"content" : [{"path" : "image.png" , "blob" : binary_content }]},
671669 )
672670 assert result == mock_response
673671
@@ -758,7 +756,6 @@ def test_upload_files_mixed_content(self, mock_boto3):
758756 client .data_plane_client .invoke_code_interpreter .return_value = mock_response
759757
760758 binary_content = b"\x00 \x01 \x02 \x03 "
761- expected_b64 = base64 .b64encode (binary_content ).decode ("utf-8" )
762759
763760 files = [
764761 {"path" : "text.txt" , "content" : "hello world" },
@@ -776,7 +773,7 @@ def test_upload_files_mixed_content(self, mock_boto3):
776773 arguments = {
777774 "content" : [
778775 {"path" : "text.txt" , "text" : "hello world" },
779- {"path" : "binary.bin" , "blob" : expected_b64 },
776+ {"path" : "binary.bin" , "blob" : binary_content },
780777 ]
781778 },
782779 )
@@ -963,14 +960,13 @@ def test_download_file_binary(self, mock_boto3):
963960 client .session_id = "test-session-id"
964961
965962 binary_content = b"\x89 PNG\r \n \x1a \n " # PNG header bytes
966- encoded_content = base64 .b64encode (binary_content ).decode ("utf-8" )
967963
968964 mock_response = {
969965 "stream" : [
970966 {
971967 "result" : {
972968 "content" : [
973- {"type" : "resource" , "resource" : {"uri" : "file://image.png" , "blob" : encoded_content }}
969+ {"type" : "resource" , "resource" : {"uri" : "file://image.png" , "blob" : binary_content }}
974970 ]
975971 }
976972 }
@@ -997,14 +993,16 @@ def test_download_file_blob_utf8_returns_str(self, mock_boto3):
997993 client .session_id = "test-session-id"
998994
999995 text_content = "hello world"
1000- encoded_content = base64 .b64encode (text_content .encode ("utf-8" )).decode ("utf-8" )
1001996
1002997 mock_response = {
1003998 "stream" : [
1004999 {
10051000 "result" : {
10061001 "content" : [
1007- {"type" : "resource" , "resource" : {"uri" : "file://data.bin" , "blob" : encoded_content }}
1002+ {
1003+ "type" : "resource" ,
1004+ "resource" : {"uri" : "file://data.bin" , "blob" : text_content .encode ("utf-8" )},
1005+ }
10081006 ]
10091007 }
10101008 }
@@ -1102,7 +1100,6 @@ def test_download_files_binary(self, mock_boto3):
11021100 client .session_id = "test-session-id"
11031101
11041102 binary_content = b"\x89 PNG\r \n \x1a \n " # PNG header bytes
1105- encoded_binary = base64 .b64encode (binary_content ).decode ("utf-8" )
11061103
11071104 mock_response = {
11081105 "stream" : [
@@ -1120,7 +1117,7 @@ def test_download_files_binary(self, mock_boto3):
11201117 "type" : "resource" ,
11211118 "resource" : {
11221119 "uri" : "file:///opt/amazon/genesis1p-tools/var/chart.png" ,
1123- "blob" : encoded_binary ,
1120+ "blob" : binary_content ,
11241121 },
11251122 },
11261123 ]
@@ -1150,9 +1147,7 @@ def test_download_files_blob_utf8_returns_str(self, mock_boto3):
11501147 client .session_id = "test-session-id"
11511148
11521149 text_content = "some utf-8 blob content"
1153- encoded_text = base64 .b64encode (text_content .encode ("utf-8" )).decode ("utf-8" )
11541150 binary_content = b"\x89 PNG\r \n \x1a \n "
1155- encoded_binary = base64 .b64encode (binary_content ).decode ("utf-8" )
11561151
11571152 mock_response = {
11581153 "stream" : [
@@ -1163,14 +1158,14 @@ def test_download_files_blob_utf8_returns_str(self, mock_boto3):
11631158 "type" : "resource" ,
11641159 "resource" : {
11651160 "uri" : "file:///opt/amazon/genesis1p-tools/var/data.bin" ,
1166- "blob" : encoded_text ,
1161+ "blob" : text_content . encode ( "utf-8" ) ,
11671162 },
11681163 },
11691164 {
11701165 "type" : "resource" ,
11711166 "resource" : {
11721167 "uri" : "file:///opt/amazon/genesis1p-tools/var/chart.png" ,
1173- "blob" : encoded_binary ,
1168+ "blob" : binary_content ,
11741169 },
11751170 },
11761171 ]
0 commit comments