File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -423,9 +423,8 @@ def flush(self):
423
423
)
424
424
425
425
def close (self ):
426
- self ._checkClosed () # Raises ValueError if closed.
427
-
428
- self ._upload_chunks_from_buffer (1 )
426
+ if not self ._buffer .closed :
427
+ self ._upload_chunks_from_buffer (1 )
429
428
self ._buffer .close ()
430
429
431
430
def _checkClosed (self ):
Original file line number Diff line number Diff line change @@ -402,6 +402,23 @@ def test_write(self, mock_warn):
402
402
stacklevel = 2 ,
403
403
)
404
404
405
+ def test_close_errors (self ):
406
+ blob = mock .Mock (chunk_size = None )
407
+
408
+ upload = mock .Mock ()
409
+ transport = mock .Mock ()
410
+
411
+ blob ._initiate_resumable_upload .return_value = (upload , transport )
412
+
413
+ writer = self ._make_blob_writer (blob )
414
+
415
+ writer .close ()
416
+ # Close a second time to verify it successfully does nothing.
417
+ writer .close ()
418
+ # Try to write to closed file.
419
+ with self .assertRaises (ValueError ):
420
+ writer .write (TEST_BINARY_DATA )
421
+
405
422
def test_flush_fails (self ):
406
423
blob = mock .Mock (chunk_size = None )
407
424
writer = self ._make_blob_writer (blob )
You can’t perform that action at this time.
0 commit comments