annotate Lib/test/test_select.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 02a5322b0cee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
1 from test import test_support
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
2 import unittest
4691
8015c5549309 A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents: 1416
diff changeset
3 import select
8015c5549309 A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents: 1416
diff changeset
4 import os
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
5 import sys
4691
8015c5549309 A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents: 1416
diff changeset
6
61258
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60422
diff changeset
7 @unittest.skipIf(sys.platform[:3] in ('win', 'os2', 'riscos'),
60421
9ba8c6e52fa0 use skip decorator
Benjamin Peterson <benjamin@python.org>
parents: 45751
diff changeset
8 "can't easily test on this system")
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
9 class SelectTestCase(unittest.TestCase):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
10
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
11 class Nope:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
12 pass
4691
8015c5549309 A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents: 1416
diff changeset
13
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
14 class Almost:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
15 def fileno(self):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
16 return 'fileno'
4691
8015c5549309 A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents: 1416
diff changeset
17
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
18 def test_error_conditions(self):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
19 self.assertRaises(TypeError, select.select, 1, 2, 3)
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
20 self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
21 self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
22 self.assertRaises(TypeError, select.select, [], [], [], "not a number")
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 13707
diff changeset
23
60424
eec2db09a6c1 Merged revisions 79866-79867 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45751
diff changeset
24 def test_returned_list_identity(self):
eec2db09a6c1 Merged revisions 79866-79867 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45751
diff changeset
25 # See issue #8329
eec2db09a6c1 Merged revisions 79866-79867 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45751
diff changeset
26 r, w, x = select.select([], [], [], 1)
60422
be044b8c343a remove a optimization that resulted in unexpected behavior #8929
Benjamin Peterson <benjamin@python.org>
parents: 60421
diff changeset
27 self.assertIsNot(r, w)
be044b8c343a remove a optimization that resulted in unexpected behavior #8929
Benjamin Peterson <benjamin@python.org>
parents: 60421
diff changeset
28 self.assertIsNot(r, x)
be044b8c343a remove a optimization that resulted in unexpected behavior #8929
Benjamin Peterson <benjamin@python.org>
parents: 60421
diff changeset
29 self.assertIsNot(w, x)
60424
eec2db09a6c1 Merged revisions 79866-79867 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45751
diff changeset
30
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
31 def test_select(self):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
32 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
33 p = os.popen(cmd, 'r')
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
34 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
35 if test_support.verbose:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
36 print 'timeout =', tout
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
37 rfd, wfd, xfd = select.select([p], [], [], tout)
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
38 if (rfd, wfd, xfd) == ([], [], []):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
39 continue
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
40 if (rfd, wfd, xfd) == ([p], [], []):
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
41 line = p.readline()
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
42 if test_support.verbose:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
43 print repr(line)
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
44 if not line:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
45 if test_support.verbose:
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
46 print 'EOF'
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
47 break
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
48 continue
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
49 self.fail('Unexpected return values from select():', rfd, wfd, xfd)
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
50 p.close()
23846
beb699e10b29 Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents: 15966
diff changeset
51
80164
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
52 # Issue 16230: Crash on select resized list
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
53 def test_select_mutated(self):
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
54 a = []
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
55 class F:
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
56 def fileno(self):
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
57 del a[-1]
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
58 return sys.__stdout__.fileno()
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
59 a[:] = [F()] * 10
02a5322b0cee Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Antoine Pitrou <solipsis@pitrou.net>
parents: 68256
diff changeset
60 self.assertEqual(select.select([], a, []), ([], a[:5], []))
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
62 def test_main():
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
63 test_support.run_unittest(SelectTestCase)
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
64 test_support.reap_children()
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
45751
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
66 if __name__ == "__main__":
49dc9af90b3d Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents: 38961
diff changeset
67 test_main()