• Home
  • Raw
  • Download

Lines Matching refs:mock

5 from unittest.mock import MagicMock, Mock, patch, sentinel, mock_open, call
68 mock = Mock()
69 mock.__enter__ = Mock()
70 mock.__exit__ = Mock()
71 mock.__exit__.return_value = False
73 with mock as m:
74 self.assertEqual(m, mock.__enter__.return_value)
75 mock.__enter__.assert_called_with()
76 mock.__exit__.assert_called_with(None, None, None)
80 mock = MagicMock()
83 with mock:
85 mock.__enter__.assert_called_with()
86 self.assertTrue(mock.__exit__.called)
145 mock = mock_open()
146 with patch('%s.open' % __name__, mock, create=True) as patched:
147 self.assertIs(patched, mock)
150 mock.assert_called_once_with('foo')
154 mock = mock_open()
155 handle = mock.return_value
156 with patch('%s.open' % __name__, mock, create=True):
162 self.assertEqual(mock.mock_calls, expected_calls)
166 mock = mock_open()
167 with patch('%s.open' % __name__, mock, create=True):
178 self.assertEqual(mock.mock_calls, expected_calls)
181 mock = MagicMock()
182 mock_open(mock)
184 with patch('%s.open' % __name__, mock, create=True) as patched:
185 self.assertIs(patched, mock)
188 mock.assert_called_once_with('foo')
192 mock = mock_open(read_data='foo')
193 with patch('%s.open' % __name__, mock, create=True):
203 mock = mock_open(read_data='foo\nbar\nbaz\n')
204 with patch('%s.open' % __name__, mock, create=True):
215 mock = mock_open(read_data='foo')
216 with patch('%s.open' % __name__, mock, create=True):
225 mock = mock_open(read_data='foo\nbar\nbaz\n')
226 with patch('%s.open' % __name__, mock, create=True):
239 mock = mock_open(read_data='foo\nbar\nbaz\n')
240 with patch('%s.open' % __name__, mock, create=True):
252 mock = mock_open(read_data='foo\nbar\nbaz\n')
253 with patch('%s.open' % __name__, mock, create=True):
260 mock = mock_open(read_data='foo\nbar\nbaz')
261 with patch('%s.open' % __name__, mock, create=True):
269 mock = mock_open(read_data=b'\xc6')
270 with patch('%s.open' % __name__, mock, create=True):
300 mock = mock_open(read_data=some_data)
301 self.assertEqual(mock().read(10), some_data[:10])
302 self.assertEqual(mock().read(10), some_data[:10])
304 f = mock()
312 mock = mock_open(read_data='foo\nbar\nbaz\n')
313 with patch('%s.open' % __name__, mock, create=True):
320 mock = mock_open(read_data='foo\nbar\nbaz\n')
321 with patch('%s.open' % __name__, mock, create=True):
330 mock = mock_open(read_data='foo')
331 handle = mock()