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,13 @@ 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+ {"type" : "resource" , "resource" : {"uri" : "file://data.bin" , "blob" : text_content . encode ( "utf-8" ) }}
10081003 ]
10091004 }
10101005 }
@@ -1102,7 +1097,6 @@ def test_download_files_binary(self, mock_boto3):
11021097 client .session_id = "test-session-id"
11031098
11041099 binary_content = b"\x89 PNG\r \n \x1a \n " # PNG header bytes
1105- encoded_binary = base64 .b64encode (binary_content ).decode ("utf-8" )
11061100
11071101 mock_response = {
11081102 "stream" : [
@@ -1120,7 +1114,7 @@ def test_download_files_binary(self, mock_boto3):
11201114 "type" : "resource" ,
11211115 "resource" : {
11221116 "uri" : "file:///opt/amazon/genesis1p-tools/var/chart.png" ,
1123- "blob" : encoded_binary ,
1117+ "blob" : binary_content ,
11241118 },
11251119 },
11261120 ]
@@ -1150,9 +1144,7 @@ def test_download_files_blob_utf8_returns_str(self, mock_boto3):
11501144 client .session_id = "test-session-id"
11511145
11521146 text_content = "some utf-8 blob content"
1153- encoded_text = base64 .b64encode (text_content .encode ("utf-8" )).decode ("utf-8" )
11541147 binary_content = b"\x89 PNG\r \n \x1a \n "
1155- encoded_binary = base64 .b64encode (binary_content ).decode ("utf-8" )
11561148
11571149 mock_response = {
11581150 "stream" : [
@@ -1163,14 +1155,14 @@ def test_download_files_blob_utf8_returns_str(self, mock_boto3):
11631155 "type" : "resource" ,
11641156 "resource" : {
11651157 "uri" : "file:///opt/amazon/genesis1p-tools/var/data.bin" ,
1166- "blob" : encoded_text ,
1158+ "blob" : text_content . encode ( "utf-8" ) ,
11671159 },
11681160 },
11691161 {
11701162 "type" : "resource" ,
11711163 "resource" : {
11721164 "uri" : "file:///opt/amazon/genesis1p-tools/var/chart.png" ,
1173- "blob" : encoded_binary ,
1165+ "blob" : binary_content ,
11741166 },
11751167 },
11761168 ]
0 commit comments