Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(263279)

Delta Between Two Patch Sets: Lib/test/test_selectors.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 12 months ago
Right Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_sax.py ('k') | Lib/test/test_shutil.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import errno 1 import errno
2 import os 2 import os
3 import random 3 import random
4 import selectors 4 import selectors
5 import signal 5 import signal
6 import socket 6 import socket
7 from test import support 7 from test import support
8 from time import sleep 8 from time import sleep
9 import unittest 9 import unittest
10 import unittest.mock 10 import unittest.mock
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 s = self.SELECTOR() 230 s = self.SELECTOR()
231 self.addCleanup(s.close) 231 self.addCleanup(s.close)
232 232
233 rd, wr = self.make_socketpair() 233 rd, wr = self.make_socketpair()
234 234
235 s.register(rd, selectors.EVENT_READ) 235 s.register(rd, selectors.EVENT_READ)
236 wr_key = s.register(wr, selectors.EVENT_WRITE) 236 wr_key = s.register(wr, selectors.EVENT_WRITE)
237 237
238 result = s.select() 238 result = s.select()
239 for key, events in result: 239 for key, events in result:
240 self.assertTrue(isinstance(key, selectors.SelectorKey)) 240 self.assertIsInstance(key, selectors.SelectorKey)
241 self.assertTrue(events) 241 self.assertTrue(events)
242 self.assertFalse(events & ~(selectors.EVENT_READ | 242 self.assertFalse(events & ~(selectors.EVENT_READ |
243 selectors.EVENT_WRITE)) 243 selectors.EVENT_WRITE))
244 244
245 self.assertEqual([(wr_key, selectors.EVENT_WRITE)], result) 245 self.assertEqual([(wr_key, selectors.EVENT_WRITE)], result)
246 246
247 def test_context_manager(self): 247 def test_context_manager(self):
248 s = self.SELECTOR() 248 s = self.SELECTOR()
249 self.addCleanup(s.close) 249 self.addCleanup(s.close)
250 250
251 rd, wr = self.make_socketpair() 251 rd, wr = self.make_socketpair()
252 252
253 with s as sel: 253 with s as sel:
254 sel.register(rd, selectors.EVENT_READ) 254 sel.register(rd, selectors.EVENT_READ)
255 sel.register(wr, selectors.EVENT_WRITE) 255 sel.register(wr, selectors.EVENT_WRITE)
256 256
257 self.assertRaises(KeyError, s.get_key, rd) 257 self.assertRaises(KeyError, s.get_key, rd)
258 self.assertRaises(KeyError, s.get_key, wr) 258 self.assertRaises(KeyError, s.get_key, wr)
259 259
260 def test_fileno(self): 260 def test_fileno(self):
261 s = self.SELECTOR() 261 s = self.SELECTOR()
262 self.addCleanup(s.close) 262 self.addCleanup(s.close)
263 263
264 if hasattr(s, 'fileno'): 264 if hasattr(s, 'fileno'):
265 fd = s.fileno() 265 fd = s.fileno()
266 self.assertTrue(isinstance(fd, int)) 266 self.assertIsInstance(fd, int)
267 self.assertGreaterEqual(fd, 0) 267 self.assertGreaterEqual(fd, 0)
268 268
269 def test_selector(self): 269 def test_selector(self):
270 s = self.SELECTOR() 270 s = self.SELECTOR()
271 self.addCleanup(s.close) 271 self.addCleanup(s.close)
272 272
273 NUM_SOCKETS = 12 273 NUM_SOCKETS = 12
274 MSG = b" This is a test." 274 MSG = b" This is a test."
275 MSG_LEN = len(MSG) 275 MSG_LEN = len(MSG)
276 readers = [] 276 readers = []
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 def test_main(): 449 def test_main():
450 tests = [DefaultSelectorTestCase, SelectSelectorTestCase, 450 tests = [DefaultSelectorTestCase, SelectSelectorTestCase,
451 PollSelectorTestCase, EpollSelectorTestCase, 451 PollSelectorTestCase, EpollSelectorTestCase,
452 KqueueSelectorTestCase] 452 KqueueSelectorTestCase]
453 support.run_unittest(*tests) 453 support.run_unittest(*tests)
454 support.reap_children() 454 support.reap_children()
455 455
456 456
457 if __name__ == "__main__": 457 if __name__ == "__main__":
458 test_main() 458 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+