@@ -75,8 +75,38 @@ def lookup_bucket(self, name):
75
75
else :
76
76
return self .create_bucket (name )
77
77
78
- def batch (self ):
79
- pass
78
+ def batch (self , raise_exception = True ):
79
+ # Return a mock object configured to act as a context manager
80
+ # and provide the necessary _responses attribute after __exit__.
81
+ # test_delete performs 3 deletions.
82
+ num_expected_responses = 3
83
+ mock_batch = mock .Mock ()
84
+
85
+ # Configure the mock responses (assuming success for test_delete)
86
+ # These need to be available *after* the 'with' block finishes.
87
+ # We'll store them temporarily and assign in __exit__.
88
+ successful_responses = [
89
+ mock .Mock (status_code = 204 ) for _ in range (num_expected_responses )
90
+ ]
91
+
92
+ # Define the exit logic
93
+ def mock_exit_logic (exc_type , exc_val , exc_tb ):
94
+ # Assign responses to the mock instance itself
95
+ # so they are available after the 'with' block.
96
+ mock_batch ._responses = successful_responses
97
+
98
+ # Configure the mock to behave like a context manager
99
+ mock_batch .configure_mock (
100
+ __enter__ = mock .Mock (return_value = mock_batch ),
101
+ __exit__ = mock .Mock (side_effect = mock_exit_logic ))
102
+
103
+ # The loop inside _batch_with_retry calls fn(request) for each item.
104
+ # The real batch object might have methods like add() or similar,
105
+ # but the core logic in gcsio.py calls the passed function `fn` directly
106
+ # within the `with` block. So, no specific action methods seem needed
107
+ # on the mock_batch itself for this test case.
108
+
109
+ return mock_batch
80
110
81
111
def add_file (self , bucket , blob , contents ):
82
112
folder = self .lookup_bucket (bucket )
0 commit comments