Changeset 234:1be67b3e0445
- Timestamp:
- 05/06/11 15:58:26 (12 months ago)
- Author:
- Menno Smits <menno@…>
- Branch:
- default
- Message:
-
Updated idle related unit tests to match current implementation
These had been broken for a while now. All unit tests pass again.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r226
|
r234
|
|
| 181 | 181 | self.assertEqual(self.client._idle_tag, sentinel.tag) |
| 182 | 182 | |
| 183 | | def test_idle_check_blocking(self): |
| 184 | | self.client._imap.sock = Mock() |
| | 183 | @patch('imapclient.imapclient.select.select') |
| | 184 | def test_idle_check_blocking(self, mock_select): |
| | 185 | mock_sock = Mock() |
| | 186 | self.client._imap.sock = mock_sock |
| | 187 | mock_select.return_value = ([True], [], []) |
| 185 | 188 | counter = itertools.count() |
| 186 | 189 | def fake_get_line(): |
| … |
… |
|
| 195 | 198 | |
| 196 | 199 | responses = self.client.idle_check() |
| | 200 | |
| | 201 | mock_select.assert_called_once_with([mock_sock], [], [], None) |
| | 202 | self.assertListEqual(mock_sock.method_calls, |
| | 203 | [('setblocking', (0,), {}), |
| | 204 | ('setblocking', (1,), {})]) |
| 197 | 205 | self.assertListEqual([(1, 'EXISTS'), (0, 'EXPUNGE')], responses) |
| 198 | 206 | |
| 199 | | def test_idle_check_timeout(self): |
| 200 | | self.client._imap.sock = Mock() |
| 201 | | def fake_get_line(): |
| 202 | | time.sleep(0.1) |
| 203 | | raise socket.timeout |
| 204 | | self.client._imap._get_line = fake_get_line |
| 205 | | |
| 206 | | t0 = time.time() |
| | 207 | @patch('imapclient.imapclient.select.select') |
| | 208 | def test_idle_check_timeout(self, mock_select): |
| | 209 | mock_sock = Mock() |
| | 210 | self.client._imap.sock = mock_sock |
| | 211 | mock_select.return_value = ([], [], []) |
| | 212 | |
| 207 | 213 | responses = self.client.idle_check(timeout=0.5) |
| 208 | | t1 = time.time() |
| 209 | | |
| | 214 | |
| | 215 | mock_select.assert_called_once_with([mock_sock], [], [], 0.5) |
| | 216 | self.assertListEqual(mock_sock.method_calls, |
| | 217 | [('setblocking', (0,), {}), |
| | 218 | ('setblocking', (1,), {})]) |
| 210 | 219 | self.assertListEqual([], responses) |
| 211 | | self.assertLess(t1 - t0, 0.8) |
| 212 | | |
| 213 | | def test_idle_check_with_data(self): |
| 214 | | self.client._imap.sock = Mock() |
| 215 | | |
| | 220 | |
| | 221 | @patch('imapclient.imapclient.select.select') |
| | 222 | def test_idle_check_with_data(self, mock_select): |
| | 223 | mock_sock = Mock() |
| | 224 | self.client._imap.sock = mock_sock |
| | 225 | mock_select.return_value = ([True], [], []) |
| 216 | 226 | counter = itertools.count() |
| 217 | 227 | def fake_get_line(): |
| … |
… |
|
| 223 | 233 | self.client._imap._get_line = fake_get_line |
| 224 | 234 | |
| 225 | | t0 = time.time() |
| 226 | 235 | responses = self.client.idle_check() |
| 227 | | t1 = time.time() |
| 228 | | |
| | 236 | |
| | 237 | mock_select.assert_called_once_with([mock_sock], [], [], None) |
| | 238 | self.assertListEqual(mock_sock.method_calls, |
| | 239 | [('setblocking', (0,), {}), |
| | 240 | ('setblocking', (1,), {})]) |
| 229 | 241 | self.assertListEqual([(99, 'EXISTS')], responses) |
| 230 | | self.assertLess(t1 - t0, 0.4) |
| 231 | 242 | |
| 232 | 243 | def test_idle_done(self): |