Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_telnetlib.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | e2c5ae30cffe |
| children | e363958fcd70 |
| rev | line source |
|---|---|
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
1 import socket |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
2 import threading |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
3 import telnetlib |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
4 import time |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
5 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
6 from unittest import TestCase |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
7 from test import test_support |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
8 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
9 HOST = test_support.HOST |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
10 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
11 def server(evt, serv): |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
12 serv.listen(5) |
|
44983
dca3f646e8a1
Reduce the race condition by signalling when the server is ready
Neal Norwitz <nnorwitz@gmail.com>
parents:
41532
diff
changeset
|
13 evt.set() |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
14 try: |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
15 conn, addr = serv.accept() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
16 except socket.timeout: |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
17 pass |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
18 finally: |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
19 serv.close() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
20 evt.set() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
21 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
22 class GeneralTests(TestCase): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41323
diff
changeset
|
23 |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
24 def setUp(self): |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
25 self.evt = threading.Event() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
26 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
27 self.sock.settimeout(3) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
28 self.port = test_support.bind_port(self.sock) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
29 threading.Thread(target=server, args=(self.evt,self.sock)).start() |
|
44983
dca3f646e8a1
Reduce the race condition by signalling when the server is ready
Neal Norwitz <nnorwitz@gmail.com>
parents:
41532
diff
changeset
|
30 self.evt.wait() |
|
dca3f646e8a1
Reduce the race condition by signalling when the server is ready
Neal Norwitz <nnorwitz@gmail.com>
parents:
41532
diff
changeset
|
31 self.evt.clear() |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
32 time.sleep(.1) |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
33 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
34 def tearDown(self): |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
35 self.evt.wait() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
36 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
37 def testBasic(self): |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
38 # connects |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
39 telnet = telnetlib.Telnet(HOST, self.port) |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
40 telnet.sock.close() |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41323
diff
changeset
|
41 |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
42 def testTimeoutDefault(self): |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
43 self.assertTrue(socket.getdefaulttimeout() is None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
44 socket.setdefaulttimeout(30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
45 try: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
46 telnet = telnetlib.Telnet("localhost", self.port) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
47 finally: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
48 socket.setdefaulttimeout(None) |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
49 self.assertEqual(telnet.sock.gettimeout(), 30) |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
50 telnet.sock.close() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
51 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
52 def testTimeoutNone(self): |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
53 # None, having other default |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
54 self.assertTrue(socket.getdefaulttimeout() is None) |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
55 socket.setdefaulttimeout(30) |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
56 try: |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46147
diff
changeset
|
57 telnet = telnetlib.Telnet(HOST, self.port, timeout=None) |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
58 finally: |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
59 socket.setdefaulttimeout(None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
60 self.assertTrue(telnet.sock.gettimeout() is None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
61 telnet.sock.close() |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
62 |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
63 def testTimeoutValue(self): |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
64 telnet = telnetlib.Telnet("localhost", self.port, timeout=30) |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
65 self.assertEqual(telnet.sock.gettimeout(), 30) |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
66 telnet.sock.close() |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
67 |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
68 def testTimeoutOpen(self): |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
69 telnet = telnetlib.Telnet() |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
70 telnet.open("localhost", self.port, timeout=30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
71 self.assertEqual(telnet.sock.gettimeout(), 30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
46362
diff
changeset
|
72 telnet.sock.close() |
|
41323
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
73 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
74 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
75 def test_main(verbose=None): |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
76 test_support.run_unittest(GeneralTests) |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
77 |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
78 if __name__ == '__main__': |
|
3fd8f06577ff
Added timout parameter to telnetlib.Telnet. Also created
Facundo Batista <facundobatista@gmail.com>
parents:
diff
changeset
|
79 test_main() |
