@@ -70,9 +70,9 @@ def test_put_success_returns_self(self):
7070 test_input = [1 , 2 , 3 ]
7171 result = blob .put (test_input )
7272 # Should return the blob itself (self) on success
73- self .assertIsInstance (result , LocalFileBlob )
74- self .assertEqual (result , blob )
75-
73+ self .assertIsInstance (result , StorageExportResult )
74+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
75+
7676 def test_put_file_write_error_returns_string (self ):
7777 blob = LocalFileBlob (os .path .join (TEST_FOLDER , "write_error_blob" ))
7878 test_input = [1 , 2 , 3 ]
@@ -129,8 +129,8 @@ def test_put_with_lease_period_success(self):
129129 lease_period = 60
130130
131131 result = blob .put (test_input , lease_period = lease_period )
132- self .assertIsInstance (result , LocalFileBlob )
133- self .assertEqual (result , blob )
132+ self .assertIsInstance (result , StorageExportResult )
133+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
134134 # File should have .lock extension due to lease period
135135 self .assertTrue (blob .fullpath .endswith (".lock" ))
136136
@@ -150,17 +150,17 @@ def test_put_empty_data_success(self):
150150 empty_data = []
151151
152152 result = blob .put (empty_data )
153- self .assertIsInstance (result , LocalFileBlob )
154- self .assertEqual (result , blob )
153+ self .assertIsInstance (result , StorageExportResult )
154+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
155155
156156 def test_put_large_data_success (self ):
157157 blob = LocalFileBlob (os .path .join (TEST_FOLDER , "large_data_blob" ))
158158 # Create a large list of data
159159 large_data = [{"id" : i , "value" : f"data_{ i } " } for i in range (1000 )]
160160
161161 result = blob .put (large_data )
162- self .assertIsInstance (result , LocalFileBlob )
163- self .assertEqual (result , blob )
162+ self .assertIsInstance (result , StorageExportResult )
163+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
164164
165165 # Verify data can be retrieved
166166 retrieved_data = blob .get ()
@@ -174,13 +174,25 @@ def test_put_return_type_consistency(self):
174174
175175 # Test successful case
176176 result_success = blob .put (test_input )
177- self .assertTrue (isinstance (result_success , LocalFileBlob ) or isinstance (result_success , str ))
177+ self .assertTrue (isinstance (result_success , StorageExportResult ) or isinstance (result_success , str ))
178178
179179 # Test error case
180180 blob2 = LocalFileBlob (os .path .join (TEST_FOLDER , "consistency_blob2" ))
181181 with mock .patch ("os.rename" , side_effect = Exception ("Test error" )):
182182 result_error = blob2 .put (test_input )
183183 self .assertIsInstance (result_error , str )
184+
185+ def test_put_invalid_return_type (self ):
186+ blob = LocalFileBlob (os .path .join (TEST_FOLDER , "invalid_return_blob" ))
187+ test_input = [1 , 2 , 3 ]
188+
189+ # This tests that even if os.rename somehow returns something unexpected,
190+ # the put method still maintains its type contract
191+ with mock .patch ("os.rename" , return_value = 42 ):
192+ result = blob .put (test_input )
193+ # Should either convert to string or return StorageExportResult
194+ self .assertTrue (isinstance (result , (StorageExportResult , str )),
195+ f"Expected StorageExportResult or str, got { type (result )} " )
184196
185197 @unittest .skip ("transient storage" )
186198 def test_put (self ):
@@ -334,7 +346,7 @@ def test_put_success_returns_localfileblob(self):
334346 test_input = (1 , 2 , 3 )
335347 with LocalFileStorage (os .path .join (TEST_FOLDER , "success_test" )) as stor :
336348 result = stor .put (test_input , lease_period = 0 ) # No lease period so file is immediately available
337- self .assertIsInstance (result , LocalFileBlob )
349+ self .assertIsInstance (result , StorageExportResult )
338350 self .assertEqual (stor .get ().get (), test_input )
339351
340352 def test_put_blob_put_failure_returns_string (self ):
@@ -379,19 +391,19 @@ def test_put_with_lease_period(self):
379391
380392 with LocalFileStorage (os .path .join (TEST_FOLDER , "lease_test" )) as stor :
381393 result = stor .put (test_input , lease_period = custom_lease_period )
382- self .assertIsInstance (result , LocalFileBlob )
394+ self .assertIsInstance (result , StorageExportResult )
383395 # Verify the file was created with lease period
384- self .assertTrue (result . fullpath . endswith ( ".lock" ) )
396+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
385397
386398 def test_put_default_lease_period (self ):
387399 test_input = (1 , 2 , 3 )
388400
389401 with LocalFileStorage (os .path .join (TEST_FOLDER , "default_lease_test" ), lease_period = 90 ) as stor :
390402 result = stor .put (test_input )
391- self .assertIsInstance (result , LocalFileBlob )
403+ self .assertIsInstance (result , StorageExportResult )
392404 # File should be created with lease (since default lease_period > 0)
393- self .assertTrue (result . fullpath . endswith ( ".lock" ) )
394-
405+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
406+
395407 def test_check_and_set_folder_permissions_oserror_sets_exception_state (self ):
396408 test_input = (1 , 2 , 3 )
397409 test_error_message = "OSError: Permission denied creating directory"
@@ -671,7 +683,7 @@ def test_exception_state_cleared_and_storage_recovery(self):
671683 with LocalFileStorage (os .path .join (TEST_FOLDER , "recovery_test2" )) as stor2 :
672684 if stor2 ._enabled : # Storage should be enabled now
673685 result = stor2 .put (test_input , lease_period = 0 )
674- self .assertIsInstance (result , LocalFileBlob )
686+ self .assertIsInstance (result , StorageExportResult )
675687 retrieved_data = stor2 .get ().get ()
676688 self .assertEqual (retrieved_data , test_input )
677689
@@ -740,6 +752,17 @@ def test_readonly_state_interaction_with_storage_put_method(self):
740752 # When storage is disabled and readonly state is set, put() should return CLIENT_READONLY
741753 result = stor .put (test_input )
742754 self .assertEqual (result , StorageExportResult .CLIENT_READONLY )
755+
756+ def test_storage_put_invalid_return_type (self ):
757+ test_input = (1 , 2 , 3 )
758+
759+ with LocalFileStorage (os .path .join (TEST_FOLDER , "invalid_return_test" )) as stor :
760+ # Mock _check_storage_size to return a non-boolean value
761+ with mock .patch .object (stor , '_check_storage_size' , return_value = 42 ):
762+ result = stor .put (test_input )
763+ # Should maintain return type contract despite invalid internal return
764+ self .assertTrue (isinstance (result , (StorageExportResult , str )),
765+ f"Expected StorageExportResult or str, got { type (result )} " )
743766
744767 def test_readonly_state_priority_over_exception_state (self ):
745768 test_input = (1 , 2 , 3 )
0 commit comments