def test_getitem(self): s = FakeSelector() map = selectors._SelectorMapping(s) f = unittest.mock.Mock() f.fileno.return_value = 10 s.register(f, selectors.EVENT_READ, None) attended = selectors.SelectorKey(f, 10, selectors.EVENT_READ, None) self.assertEqual(attended, map.__getitem__(f))
def test_getitem_key_error(self): s = FakeSelector() map = selectors._SelectorMapping(s) self.assertTrue(len(map) == 0) f = unittest.mock.Mock() f.fileno.return_value = 10 s.register(f, selectors.EVENT_READ, None) self.assertRaises(KeyError, map.__getitem__, 5)
def test_len(self): s = FakeSelector() map = selectors._SelectorMapping(s) self.assertTrue(map.__len__() == 0) f = unittest.mock.Mock() f.fileno.return_value = 10 s.register(f, selectors.EVENT_READ, None) self.assertTrue(len(map) == 1)
def test_iter(self): s = FakeSelector() map = selectors._SelectorMapping(s) self.assertTrue(len(map) == 0) f = unittest.mock.Mock() f.fileno.return_value = 5 s.register(f, selectors.EVENT_READ, None) counter = 0 for fileno in map.__iter__(): self.assertEqual(5, fileno) counter += 1 for idx in map: self.assertEqual(f, map[idx].fileobj) self.assertEqual(1, counter)