[Python-checkins] r74638 - in python/branches/py3k: Lib/test/test_telnetlib.py Misc/ACKS

jack.diederich python-checkins at python.org
Thu Sep 3 22:37:58 CEST 2009


Author: jack.diederich
Date: Thu Sep  3 22:37:58 2009
New Revision: 74638

Log:
- apply issue 6582 to test all the write methods of telnetlib
- add patch author to ACKS
- possibly fix test timeouts on non-linux platforms


Modified:
   python/branches/py3k/Lib/test/test_telnetlib.py
   python/branches/py3k/Misc/ACKS

Modified: python/branches/py3k/Lib/test/test_telnetlib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_telnetlib.py	(original)
+++ python/branches/py3k/Lib/test/test_telnetlib.py	Thu Sep  3 22:37:58 2009
@@ -305,6 +305,48 @@
             sb_data = self.sb_getter()
             self.sb_seen += sb_data
 
+class SocketProxy(object):
+    ''' a socket proxy that re-defines sendall() '''
+    def __init__(self, real_sock):
+        self.socket = real_sock
+        self._raw_sent = b''
+    def __getattr__(self, k):
+        return getattr(self.socket, k)
+    def sendall(self, data):
+        self._raw_sent += data
+        self.socket.sendall(data)
+
+class TelnetSockSendall(telnetlib.Telnet):
+    def open(self, *args, **opts):
+        telnetlib.Telnet.open(self, *args, **opts)
+        self.sock = SocketProxy(self.sock)
+
+class WriteTests(TestCase):
+    '''The only thing that write does is replace each tl.IAC for
+    tl.IAC+tl.IAC'''
+    setUp = _read_setUp
+    tearDown = _read_tearDown
+
+    def _test_write(self, data):
+        self.telnet.sock._raw_sent = b''
+        self.telnet.write(data)
+        after_write = self.telnet.sock._raw_sent
+        self.assertEqual(data.replace(tl.IAC,tl.IAC+tl.IAC),
+                         after_write)
+
+    def test_write(self):
+        self.telnet = TelnetSockSendall()
+        data_sample = [b'data sample without IAC',
+                       b'data sample with' + tl.IAC + b' one IAC',
+                       b'a few' + tl.IAC + tl.IAC + b' iacs' + tl.IAC,
+                       tl.IAC,
+                       b'']
+        self.telnet.open(HOST, self.port)
+        for d in data_sample:
+            self.dataq.put([b''])
+            self._test_write(d)
+        self.telnet.close()
+
 tl = telnetlib
 
 class TelnetDebuglevel(tl.Telnet):
@@ -382,16 +424,17 @@
     def _test_debuglevel(self, data, expected_msg):
         """ helper for testing debuglevel messages """
         self.setUp()
-        self.dataq.put(data)
+        self.dataq.put(data + [EOF_sigil])
         telnet = TelnetDebuglevel(HOST, self.port)
         telnet.set_debuglevel(1)
         self.dataq.join()
         txt = telnet.read_all()
         self.assertTrue(expected_msg in telnet._messages,
                         msg=(telnet._messages, expected_msg))
+        telnet.close()
         self.tearDown()
 
-    def test_debuglevel(self):
+    def test_debuglevel_reads(self):
         # test all the various places that self.msg(...) is called
         given_a_expect_b = [
             # Telnet.fill_rawq
@@ -402,15 +445,26 @@
             (tl.IAC + tl.DONT + bytes([1]), ": IAC DONT 1\n"),
             (tl.IAC + tl.WILL + bytes([1]), ": IAC WILL 1\n"),
             (tl.IAC + tl.WONT + bytes([1]), ": IAC WONT 1\n"),
-            # Telnet.write
-            # XXX, untested
            ]
         for a, b in given_a_expect_b:
             self._test_debuglevel([a, EOF_sigil], b)
         return
 
+    def test_debuglevel_write(self):
+        self.setUp()
+        telnet = TelnetDebuglevel(HOST, self.port)
+        telnet.set_debuglevel(1)
+        self.dataq.put([b'', EOF_sigil])
+        self.dataq.join()
+        telnet.write(b'xxx')
+        expected = "send b'xxx'\n"
+        self.assertTrue(expected in telnet._messages,
+                        msg=(telnet._messages, expected))
+        telnet.close()
+        self.tearDown()
+
 def test_main(verbose=None):
-    support.run_unittest(GeneralTests, ReadTests, OptionTests)
+    support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Thu Sep  3 22:37:58 2009
@@ -772,6 +772,7 @@
 Charles Waldman
 Richard Walker
 Larry Wall
+Rodrigo Steinmuller Wanderley
 Greg Ward
 Barry Warsaw
 Steve Waterbury


More information about the Python-checkins mailing list