def test_complete(self): ''' Make sure it works with both readable and writable streams ''' poller = Poller(1) result = [] # # Insert a number of streams, make all of them readable # and just a subset writable. The partial overlap is to # make sure that readable, writable and read-writable # streams are all processed correctly. # for i in range(256): stream = TestCheckTimeoutStream(result, i) poller.readset[i] = stream if i > 14 and i < 128: poller.writeset[i] = stream # This should close odd streams only poller.check_timeout() # Check we have closed the right streams self.assertEqual(sorted(result), range(1, 256, 2)) # Make sure the readable set is consistent self.assertEqual(sorted(poller.readset), range(0, 256, 2)) # Make sure the writable set is consistent self.assertEqual(sorted(poller.writeset), range(16, 128, 2))
def test_writable(self): ''' Make sure it runs when there's only writable stuff ''' poller = Poller(1) result = [] stream = TestCheckTimeoutStream(result, 1) poller.writeset[1] = stream poller.check_timeout() self.assertEqual(result, [1])
def test_empty(self): ''' Invoked without nothing to do ''' poller = Poller(1) poller.check_timeout() # # There are two pending check_timeout() invokations here # one because we've just created the poller and the other # because we've just invoked check_timeout(). # self.assertEqual(len(poller.pending), 2) self.assertEqual(poller.pending[0].func, poller.check_timeout) self.assertEqual(poller.pending[1].func, poller.check_timeout)