diff options
author | Georg Brandl <georg@python.org> | 2009-08-13 08:39:33 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-08-13 08:39:33 (GMT) |
commit | e6700e9a0435df5de59eed27fa072caf320e7ebd (patch) | |
tree | fad4a06f18cc3ad533726cfe4c43e99e9a02c7ae /Lib/test | |
parent | 01a30523f9782f9e8b8f49efc3b2a703b94394f3 (diff) | |
download | cpython-e6700e9a0435df5de59eed27fa072caf320e7ebd.zip cpython-e6700e9a0435df5de59eed27fa072caf320e7ebd.tar.gz cpython-e6700e9a0435df5de59eed27fa072caf320e7ebd.tar.bz2 |
Merged revisions 74217,74224 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
........
r74217 | jack.diederich | 2009-07-27 00:23:04 +0200 (Mo, 27 Jul 2009) | 1 line
- fix issue #6106, Telnet.process_rawq default handling of WILL/WONT/DO/DONT
........
r74224 | jack.diederich | 2009-07-27 11:03:14 +0200 (Mo, 27 Jul 2009) | 1 line
- belated ACK for issue #6106
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_telnetlib.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py index bad2819..662c715 100644 --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -3,6 +3,8 @@ import threading import telnetlib import time import queue +import sys +import io from unittest import TestCase from test import support @@ -304,6 +306,20 @@ class nego_collector(object): self.sb_seen += sb_data tl = telnetlib + +class TelnetDebuglevel(tl.Telnet): + ''' Telnet-alike that captures messages written to stdout when + debuglevel > 0 + ''' + _messages = '' + def msg(self, msg, *args): + orig_stdout = sys.stdout + sys.stdout = fake_stdout = io.StringIO() + tl.Telnet.msg(self, msg, *args) + self._messages += fake_stdout.getvalue() + sys.stdout = orig_stdout + return + class OptionTests(TestCase): setUp = _read_setUp tearDown = _read_tearDown @@ -363,6 +379,36 @@ class OptionTests(TestCase): self.assertEqual(b'', telnet.read_sb_data()) nego.sb_getter = None # break the nego => telnet cycle + def _test_debuglevel(self, data, expected_msg): + """ helper for testing debuglevel messages """ + self.setUp() + self.dataq.put(data) + 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)) + self.tearDown() + + def test_debuglevel(self): + # test all the various places that self.msg(...) is called + given_a_expect_b = [ + # Telnet.fill_rawq + (b'a', ": recv b''\n"), + # Telnet.process_rawq + (tl.IAC + bytes([88]), ": IAC 88 not recognized\n"), + (tl.IAC + tl.DO + bytes([1]), ": IAC DO 1\n"), + (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_main(verbose=None): support.run_unittest(GeneralTests, ReadTests, OptionTests) |