Turn on bufferring for the test suite

Allows for more verbose server logging
This commit is contained in:
Kovid Goyal 2020-12-08 09:23:32 +05:30
parent beadc4384f
commit 1ee3c0fdd6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 46 additions and 43 deletions

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import unittest, time, shutil, gc, tempfile, atexit, os
import unittest, time, shutil, gc, tempfile, atexit, os, sys
from io import BytesIO
from functools import partial
from threading import Thread
@ -86,10 +86,11 @@ class TestServer(Thread):
create_http_handler(handler),
opts=Options(**kwargs),
plugins=plugins,
log=ServerLog(level=ServerLog.WARN),
log=ServerLog(level=ServerLog.DEBUG),
)
self.log = self.loop.log
self.silence_log = self.log
# allow unittest's bufferring to work
self.log.outputs[0].stream = sys.stdout
specialize(self)
def setup_defaults(self, kwargs):
@ -145,8 +146,10 @@ class LibraryServer(TestServer):
create_http_handler(self.handler.dispatch),
opts=opts,
plugins=plugins,
log=ServerLog(level=ServerLog.WARN),
log=ServerLog(level=ServerLog.DEBUG),
)
# allow unittest's bufferring to work
self.loop.log.outputs[0].stream = sys.stdout
self.handler.set_log(self.loop.log)
specialize(self)

View File

@ -222,7 +222,6 @@ class WebSocketTest(BaseTest):
for payload in [b'', b'ping', b'\x00\xff\xfe\xfd\xfc\xfb\x00\xff', b"\xfe" * 125]:
simple_test([(PING, payload)], [(PONG, payload)])
with server.silence_log:
simple_test([(PING, 'a'*126)], close_code=PROTOCOL_ERROR, send_close=False)
for payload in (b'', b'pong'):
@ -231,7 +230,6 @@ class WebSocketTest(BaseTest):
fragments = 'Hello-µ@ßöä üàá-UTF-8!!'.split()
nc = struct.pack(b'!H', NORMAL_CLOSE)
with server.silence_log:
# It can happen that the server detects bad data and closes the
# connection before the client has finished sending all
# messages, so ignore failures to send packets.

View File

@ -26,7 +26,6 @@ class Stream(object):
stream = io.StringIO()
self.stream = stream
self.encoding = getattr(self.stream, 'encoding', None) or 'utf-8'
self._prints = partial(prints, file=self.stream)
def write(self, text):
self._prints(text, end='')
@ -37,6 +36,9 @@ class Stream(object):
def prints(self, level, *args, **kwargs):
self._prints(*args, **kwargs)
def _prints(self, *args, **kwargs):
prints(*args, file=self.stream, **kwargs)
class ANSIStream(Stream):

View File

@ -142,10 +142,10 @@ def run_tests(find_tests, verbosity=4):
run_cli(tests, verbosity)
def run_cli(suite, verbosity=4):
def run_cli(suite, verbosity=4, buffer=True):
r = unittest.TextTestRunner
r.resultclass = unittest.TextTestResult if verbosity < 2 else TestResult
init_env()
result = r(verbosity=verbosity).run(suite)
result = r(verbosity=verbosity, buffer=buffer).run(suite)
if not result.wasSuccessful():
raise SystemExit(1)