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

Delta Between Two Patch Sets: Lib/test/test_epoll.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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_dbm.py ('k') | Lib/test/test_faulthandler.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
1 # Copyright (c) 2001-2006 Twisted Matrix Laboratories. 1 # Copyright (c) 2001-2006 Twisted Matrix Laboratories.
2 # 2 #
3 # Permission is hereby granted, free of charge, to any person obtaining 3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the 4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, 6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Software, and to 7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to 8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions: 9 # the following conditions:
10 # 10 #
11 # The above copyright notice and this permission notice shall be 11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Software. 12 # included in all copies or substantial portions of the Software.
13 # 13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 """ 21 """
22 Tests for epoll wrapper. 22 Tests for epoll wrapper.
23 """ 23 """
24 import errno
25 import os
26 import select
24 import socket 27 import socket
25 import errno
26 import time 28 import time
27 import select
28 import unittest 29 import unittest
29 30
30 from test import support 31 from test import support
31 if not hasattr(select, "epoll"): 32 if not hasattr(select, "epoll"):
32 raise unittest.SkipTest("test works only on Linux 2.6") 33 raise unittest.SkipTest("test works only on Linux 2.6")
33 34
34 try: 35 try:
35 select.epoll() 36 select.epoll()
36 except OSError as e: 37 except OSError as e:
37 if e.errno == errno.ENOSYS: 38 if e.errno == errno.ENOSYS:
38 raise unittest.SkipTest("kernel doesn't support epoll()") 39 raise unittest.SkipTest("kernel doesn't support epoll()")
39 raise 40 raise
40 41
41 class TestEPoll(unittest.TestCase): 42 class TestEPoll(unittest.TestCase):
42 43
43 def setUp(self): 44 def setUp(self):
44 self.serverSocket = socket.socket() 45 self.serverSocket = socket.socket()
45 self.serverSocket.bind(('127.0.0.1', 0)) 46 self.serverSocket.bind(('127.0.0.1', 0))
46 self.serverSocket.listen(1) 47 self.serverSocket.listen(1)
47 self.connections = [self.serverSocket] 48 self.connections = [self.serverSocket]
48
49 49
50 def tearDown(self): 50 def tearDown(self):
51 for skt in self.connections: 51 for skt in self.connections:
52 skt.close() 52 skt.close()
53 53
54 def _connected_pair(self): 54 def _connected_pair(self):
55 client = socket.socket() 55 client = socket.socket()
56 client.setblocking(False) 56 client.setblocking(False)
57 try: 57 try:
58 client.connect(('127.0.0.1', self.serverSocket.getsockname()[1])) 58 client.connect(('127.0.0.1', self.serverSocket.getsockname()[1]))
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ep.register(server) 218 ep.register(server)
219 219
220 now = time.time() 220 now = time.time()
221 events = ep.poll(1, 4) 221 events = ep.poll(1, 4)
222 then = time.time() 222 then = time.time()
223 self.assertFalse(then - now > 0.01) 223 self.assertFalse(then - now > 0.01)
224 224
225 server.close() 225 server.close()
226 ep.unregister(fd) 226 ep.unregister(fd)
227 227
228 def test_close(self):
229 open_file = open(__file__, "rb")
230 self.addCleanup(open_file.close)
231 fd = open_file.fileno()
232 epoll = select.epoll()
233
234 # test fileno() method and closed attribute
235 self.assertIsInstance(epoll.fileno(), int)
236 self.assertFalse(epoll.closed)
237
238 # test close()
239 epoll.close()
240 self.assertTrue(epoll.closed)
241 self.assertRaises(ValueError, epoll.fileno)
242
243 # close() can be called more than once
244 epoll.close()
245
246 # operations must fail with ValueError("I/O operation on closed ...")
247 self.assertRaises(ValueError, epoll.modify, fd, select.EPOLLIN)
248 self.assertRaises(ValueError, epoll.poll, 1.0)
249 self.assertRaises(ValueError, epoll.register, fd, select.EPOLLIN)
250 self.assertRaises(ValueError, epoll.unregister, fd)
251
252 def test_fd_non_inheritable(self):
253 epoll = select.epoll()
254 self.addCleanup(epoll.close)
255 self.assertEqual(os.get_inheritable(epoll.fileno()), False)
256
257
228 def test_main(): 258 def test_main():
229 support.run_unittest(TestEPoll) 259 support.run_unittest(TestEPoll)
230 260
231 if __name__ == "__main__": 261 if __name__ == "__main__":
232 test_main() 262 test_main()
LEFTRIGHT

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