~malept/ubuntu/lucid/python2.6/dev-dependency-fix

« back to all changes in this revision

Viewing changes to Lib/test/test_select.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-13 12:51:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090213125100-uufgcb9yeqzujpqw
Tags: upstream-2.6.1
ImportĀ upstreamĀ versionĀ 2.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from test import test_support
 
2
import unittest
 
3
import select
 
4
import os
 
5
import sys
 
6
 
 
7
class SelectTestCase(unittest.TestCase):
 
8
 
 
9
    class Nope:
 
10
        pass
 
11
 
 
12
    class Almost:
 
13
        def fileno(self):
 
14
            return 'fileno'
 
15
 
 
16
    def test_error_conditions(self):
 
17
        self.assertRaises(TypeError, select.select, 1, 2, 3)
 
18
        self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
 
19
        self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
 
20
        self.assertRaises(TypeError, select.select, [], [], [], "not a number")
 
21
 
 
22
    def test_select(self):
 
23
        if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'):
 
24
            if test_support.verbose:
 
25
                print "Can't test select easily on", sys.platform
 
26
            return
 
27
        cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
 
28
        p = os.popen(cmd, 'r')
 
29
        for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
 
30
            if test_support.verbose:
 
31
                print 'timeout =', tout
 
32
            rfd, wfd, xfd = select.select([p], [], [], tout)
 
33
            if (rfd, wfd, xfd) == ([], [], []):
 
34
                continue
 
35
            if (rfd, wfd, xfd) == ([p], [], []):
 
36
                line = p.readline()
 
37
                if test_support.verbose:
 
38
                    print repr(line)
 
39
                if not line:
 
40
                    if test_support.verbose:
 
41
                        print 'EOF'
 
42
                    break
 
43
                continue
 
44
            self.fail('Unexpected return values from select():', rfd, wfd, xfd)
 
45
        p.close()
 
46
 
 
47
 
 
48
def test_main():
 
49
    test_support.run_unittest(SelectTestCase)
 
50
    test_support.reap_children()
 
51
 
 
52
if __name__ == "__main__":
 
53
    test_main()