mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Turn on bufferring for the test suite
Allows for more verbose server logging
This commit is contained in:
parent
beadc4384f
commit
1ee3c0fdd6
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__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 io import BytesIO
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -86,10 +86,11 @@ class TestServer(Thread):
|
|||||||
create_http_handler(handler),
|
create_http_handler(handler),
|
||||||
opts=Options(**kwargs),
|
opts=Options(**kwargs),
|
||||||
plugins=plugins,
|
plugins=plugins,
|
||||||
log=ServerLog(level=ServerLog.WARN),
|
log=ServerLog(level=ServerLog.DEBUG),
|
||||||
)
|
)
|
||||||
self.log = self.loop.log
|
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)
|
specialize(self)
|
||||||
|
|
||||||
def setup_defaults(self, kwargs):
|
def setup_defaults(self, kwargs):
|
||||||
@ -145,8 +146,10 @@ class LibraryServer(TestServer):
|
|||||||
create_http_handler(self.handler.dispatch),
|
create_http_handler(self.handler.dispatch),
|
||||||
opts=opts,
|
opts=opts,
|
||||||
plugins=plugins,
|
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)
|
self.handler.set_log(self.loop.log)
|
||||||
specialize(self)
|
specialize(self)
|
||||||
|
|
||||||
|
@ -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]:
|
for payload in [b'', b'ping', b'\x00\xff\xfe\xfd\xfc\xfb\x00\xff', b"\xfe" * 125]:
|
||||||
simple_test([(PING, payload)], [(PONG, payload)])
|
simple_test([(PING, payload)], [(PONG, payload)])
|
||||||
|
|
||||||
with server.silence_log:
|
|
||||||
simple_test([(PING, 'a'*126)], close_code=PROTOCOL_ERROR, send_close=False)
|
simple_test([(PING, 'a'*126)], close_code=PROTOCOL_ERROR, send_close=False)
|
||||||
|
|
||||||
for payload in (b'', b'pong'):
|
for payload in (b'', b'pong'):
|
||||||
@ -231,7 +230,6 @@ class WebSocketTest(BaseTest):
|
|||||||
fragments = 'Hello-µ@ßöä üàá-UTF-8!!'.split()
|
fragments = 'Hello-µ@ßöä üàá-UTF-8!!'.split()
|
||||||
nc = struct.pack(b'!H', NORMAL_CLOSE)
|
nc = struct.pack(b'!H', NORMAL_CLOSE)
|
||||||
|
|
||||||
with server.silence_log:
|
|
||||||
# It can happen that the server detects bad data and closes the
|
# It can happen that the server detects bad data and closes the
|
||||||
# connection before the client has finished sending all
|
# connection before the client has finished sending all
|
||||||
# messages, so ignore failures to send packets.
|
# messages, so ignore failures to send packets.
|
||||||
|
@ -26,7 +26,6 @@ class Stream(object):
|
|||||||
stream = io.StringIO()
|
stream = io.StringIO()
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
self.encoding = getattr(self.stream, 'encoding', None) or 'utf-8'
|
self.encoding = getattr(self.stream, 'encoding', None) or 'utf-8'
|
||||||
self._prints = partial(prints, file=self.stream)
|
|
||||||
|
|
||||||
def write(self, text):
|
def write(self, text):
|
||||||
self._prints(text, end='')
|
self._prints(text, end='')
|
||||||
@ -37,6 +36,9 @@ class Stream(object):
|
|||||||
def prints(self, level, *args, **kwargs):
|
def prints(self, level, *args, **kwargs):
|
||||||
self._prints(*args, **kwargs)
|
self._prints(*args, **kwargs)
|
||||||
|
|
||||||
|
def _prints(self, *args, **kwargs):
|
||||||
|
prints(*args, file=self.stream, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ANSIStream(Stream):
|
class ANSIStream(Stream):
|
||||||
|
|
||||||
|
@ -142,10 +142,10 @@ def run_tests(find_tests, verbosity=4):
|
|||||||
run_cli(tests, verbosity)
|
run_cli(tests, verbosity)
|
||||||
|
|
||||||
|
|
||||||
def run_cli(suite, verbosity=4):
|
def run_cli(suite, verbosity=4, buffer=True):
|
||||||
r = unittest.TextTestRunner
|
r = unittest.TextTestRunner
|
||||||
r.resultclass = unittest.TextTestResult if verbosity < 2 else TestResult
|
r.resultclass = unittest.TextTestResult if verbosity < 2 else TestResult
|
||||||
init_env()
|
init_env()
|
||||||
result = r(verbosity=verbosity).run(suite)
|
result = r(verbosity=verbosity, buffer=buffer).run(suite)
|
||||||
if not result.wasSuccessful():
|
if not result.wasSuccessful():
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user