summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_selectors.py
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2013-10-30 19:31:04 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2013-10-30 19:31:04 (GMT)
commit4574b49703785081262f65df59c1a630242e506f (patch)
treea6a9414b36943ae5608096e441a09c74d09e5f6a /Lib/test/test_selectors.py
parent7613542a27a03b7ade40e298aed6b3115dcad0df (diff)
downloadcpython-4574b49703785081262f65df59c1a630242e506f.zip
cpython-4574b49703785081262f65df59c1a630242e506f.tar.gz
cpython-4574b49703785081262f65df59c1a630242e506f.tar.bz2
Issue #19172: Add a get_map() method to selectors.
Diffstat (limited to 'Lib/test/test_selectors.py')
-rw-r--r--Lib/test/test_selectors.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py
index a2ffd62..fd0481d 100644
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -153,6 +153,33 @@ class BaseSelectorTestCase(unittest.TestCase):
# unknown file obj
self.assertRaises(KeyError, s.get_key, 999999)
+ def test_get_map(self):
+ s = self.SELECTOR()
+ self.addCleanup(s.close)
+
+ rd, wr = socketpair()
+ self.addCleanup(rd.close)
+ self.addCleanup(wr.close)
+
+ keys = s.get_map()
+ self.assertFalse(keys)
+ self.assertEqual(len(keys), 0)
+ self.assertEqual(list(keys), [])
+ key = s.register(rd, selectors.EVENT_READ, "data")
+ self.assertIn(rd, keys)
+ self.assertEqual(key, keys[rd])
+ self.assertEqual(len(keys), 1)
+ self.assertEqual(list(keys), [rd.fileno()])
+ self.assertEqual(list(keys.values()), [key])
+
+ # unknown file obj
+ with self.assertRaises(KeyError):
+ keys[999999]
+
+ # Read-only mapping
+ with self.assertRaises(TypeError):
+ del keys[rd]
+
def test_select(self):
s = self.SELECTOR()
self.addCleanup(s.close)