@@ -159,7 +159,9 @@ class CloudbaseInitTestBase(unittest.TestCase):
159159 @contextlib .contextmanager
160160 def assert_raises_windows_message (
161161 self , expected_msg , error_code ,
162- exc = exception .WindowsCloudbaseInitException ):
162+ exc = exception .WindowsCloudbaseInitException ,
163+ get_last_error_called_times = 1 ,
164+ format_error_called_times = 1 ):
163165 """Helper method for testing raised error messages
164166
165167 This assert method is similar to :meth:`~assertRaises`, but
@@ -188,11 +190,16 @@ def assert_raises_windows_message(
188190 # This can be called when the error code is not given,
189191 # but we don't have control over that, so test that
190192 # it's actually called only once.
191- mock_get_last_error .assert_called_once_with ()
192- mock_format_error .assert_called_once_with (
193+ mock_get_last_error .assert_called ()
194+ self .assertEqual (mock_get_last_error .call_count ,
195+ get_last_error_called_times )
196+ mock_format_error .assert_called_with (
193197 mock_get_last_error .return_value )
194198 else :
195- mock_format_error .assert_called_once_with (error_code )
199+ mock_format_error .assert_called_with (error_code )
200+
201+ self .assertEqual (mock_format_error .call_count ,
202+ format_error_called_times )
196203
197204 expected_msg = expected_msg % mock_format_error .return_value
198205 self .assertEqual (expected_msg , cm .exception .args [0 ])
0 commit comments