Skip to content

Commit afb5736

Browse files
authored
Use assert(mock.called) (#33194)
The `mock.assert_called()` method was added in Python 3.6, so fails on some of our older CI machines that use Python 3.5. `assert(mock.called)` is precisely equivalent and works with older versions of the Python unittest.mock library.
1 parent 9fe0ed2 commit afb5736

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

utils/build_swift/tests/build_swift/test_cache_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_replaced_with_functools_lru_cache_python_3_2(self):
4949
def func():
5050
return None
5151

52-
mock_lru_cache.assert_called()
52+
assert(mock_lru_cache.called)
5353

5454
def test_call_with_no_args(self):
5555
# Increments the counter once per unique call.

utils/build_swift/tests/build_swift/test_shell.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_echo_command(self):
118118

119119
mock_stream.write.assert_called_with(
120120
'>>> {}\n'.format(shell.quote(test_command)))
121-
mock_stream.flush.assert_called()
121+
assert(mock_stream.flush.called)
122122

123123
@utils.requires_module('unittest.mock')
124124
def test_echo_command_custom_prefix(self):
@@ -127,7 +127,7 @@ def test_echo_command_custom_prefix(self):
127127
shell._echo_command('ls', mock_stream, prefix='$ ')
128128

129129
mock_stream.write.assert_called_with('$ ls\n')
130-
mock_stream.flush.assert_called()
130+
assert(mock_stream.flush.called)
131131

132132
# -------------------------------------------------------------------------
133133
# _normalize_args
@@ -208,8 +208,8 @@ def func(command, **kwargs):
208208
self.assertEqual(kwargs['stdout'], mock_file)
209209

210210
func('', stdout=shell.DEVNULL)
211-
mock_open.return_value.__enter__.assert_called()
212-
mock_open.return_value.__exit__.assert_called()
211+
assert(mock_open.return_value.__enter__.called)
212+
assert(mock_open.return_value.__exit__.called)
213213

214214
@utils.requires_module('unittest.mock')
215215
@patch(_OPEN_NAME, new_callable=mock_open)
@@ -223,8 +223,8 @@ def func(command, **kwargs):
223223
self.assertEqual(kwargs['stderr'], mock_file)
224224

225225
func('', stderr=shell.DEVNULL)
226-
mock_open.return_value.__enter__.assert_called()
227-
mock_open.return_value.__exit__.assert_called()
226+
assert(mock_open.return_value.__enter__.called)
227+
assert(mock_open.return_value.__exit__.called)
228228

229229
@utils.requires_module('unittest.mock')
230230
@patch(_OPEN_NAME, new_callable=mock_open)

0 commit comments

Comments
 (0)