ยปCore Development>Code coverage>Lib/test/test_select.py

Python code coverage for Lib/test/test_select.py

#countcontent
1n/aimport errno
2n/aimport os
3n/aimport select
4n/aimport sys
5n/aimport unittest
6n/afrom test import support
7n/a
8n/a@unittest.skipIf((sys.platform[:3]=='win'),
9n/a "can't easily test on this system")
10n/aclass SelectTestCase(unittest.TestCase):
11n/a
12n/a class Nope:
13n/a pass
14n/a
15n/a class Almost:
16n/a def fileno(self):
17n/a return 'fileno'
18n/a
19n/a def test_error_conditions(self):
20n/a self.assertRaises(TypeError, select.select, 1, 2, 3)
21n/a self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
22n/a self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
23n/a self.assertRaises(TypeError, select.select, [], [], [], "not a number")
24n/a self.assertRaises(ValueError, select.select, [], [], [], -1)
25n/a
26n/a # Issue #12367: http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/155606
27n/a @unittest.skipIf(sys.platform.startswith('freebsd'),
28n/a 'skip because of a FreeBSD bug: kern/155606')
29n/a def test_errno(self):
30n/a with open(__file__, 'rb') as fp:
31n/a fd = fp.fileno()
32n/a fp.close()
33n/a try:
34n/a select.select([fd], [], [], 0)
35n/a except OSError as err:
36n/a self.assertEqual(err.errno, errno.EBADF)
37n/a else:
38n/a self.fail("exception not raised")
39n/a
40n/a def test_returned_list_identity(self):
41n/a # See issue #8329
42n/a r, w, x = select.select([], [], [], 1)
43n/a self.assertIsNot(r, w)
44n/a self.assertIsNot(r, x)
45n/a self.assertIsNot(w, x)
46n/a
47n/a def test_select(self):
48n/a cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
49n/a p = os.popen(cmd, 'r')
50n/a for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
51n/a if support.verbose:
52n/a print('timeout =', tout)
53n/a rfd, wfd, xfd = select.select([p], [], [], tout)
54n/a if (rfd, wfd, xfd) == ([], [], []):
55n/a continue
56n/a if (rfd, wfd, xfd) == ([p], [], []):
57n/a line = p.readline()
58n/a if support.verbose:
59n/a print(repr(line))
60n/a if not line:
61n/a if support.verbose:
62n/a print('EOF')
63n/a break
64n/a continue
65n/a self.fail('Unexpected return values from select():', rfd, wfd, xfd)
66n/a p.close()
67n/a
68n/a # Issue 16230: Crash on select resized list
69n/a def test_select_mutated(self):
70n/a a = []
71n/a class F:
72n/a def fileno(self):
73n/a del a[-1]
74n/a return sys.__stdout__.fileno()
75n/a a[:] = [F()] * 10
76n/a self.assertEqual(select.select([], a, []), ([], a[:5], []))
77n/a
78n/adef tearDownModule():
79n/a support.reap_children()
80n/a
81n/aif __name__ == "__main__":
82n/a unittest.main()