mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 23:02:25 +00:00
Merge pull request #934 from tahoe-lafs/3564.eliot-log-testing-python-3
Re-enable logging validation on Python 3. Fixes ticket:3564
This commit is contained in:
commit
f9ee4b239f
0
newsfragments/3564.minor
Normal file
0
newsfragments/3564.minor
Normal file
4
setup.py
4
setup.py
@ -111,7 +111,9 @@ install_requires = [
|
||||
|
||||
# Eliot is contemplating dropping Python 2 support. Stick to a version we
|
||||
# know works on Python 2.7.
|
||||
"eliot ~= 1.7",
|
||||
"eliot ~= 1.7 ; python_version < '3.0'",
|
||||
# On Python 3, we want a new enough version to support custom JSON encoders.
|
||||
"eliot >= 1.13.0 ; python_version > '3.0'",
|
||||
|
||||
# Pyrsistent 0.17.0 (which we use by way of Eliot) has dropped
|
||||
# Python 2 entirely; stick to the version known to work for us.
|
||||
|
@ -113,4 +113,5 @@ if sys.platform == "win32":
|
||||
initialize()
|
||||
|
||||
from eliot import to_file
|
||||
to_file(open("eliot.log", "w"))
|
||||
from allmydata.util.jsonbytes import BytesJSONEncoder
|
||||
to_file(open("eliot.log", "w"), encoder=BytesJSONEncoder)
|
||||
|
@ -31,6 +31,9 @@ from twisted.internet.defer import (
|
||||
maybeDeferred,
|
||||
)
|
||||
|
||||
from ..util.jsonbytes import BytesJSONEncoder
|
||||
|
||||
|
||||
_NAME = Field.for_types(
|
||||
u"name",
|
||||
[str],
|
||||
@ -61,6 +64,14 @@ def eliot_logged_test(f):
|
||||
class storage(object):
|
||||
pass
|
||||
|
||||
|
||||
# On Python 3, we want to use our custom JSON encoder when validating
|
||||
# messages can be encoded to JSON:
|
||||
if PY3:
|
||||
capture = lambda f : capture_logging(None, encoder_=BytesJSONEncoder)(f)
|
||||
else:
|
||||
capture = lambda f : capture_logging(None)(f)
|
||||
|
||||
@wraps(f)
|
||||
def run_and_republish(self, *a, **kw):
|
||||
# Unfortunately the only way to get at the global/default logger...
|
||||
@ -85,7 +96,7 @@ def eliot_logged_test(f):
|
||||
# can finish the test's action.
|
||||
storage.action.finish()
|
||||
|
||||
@capture_logging(None)
|
||||
@capture
|
||||
def run(self, logger):
|
||||
# Record the MemoryLogger for later message extraction.
|
||||
storage.logger = logger
|
||||
@ -165,9 +176,6 @@ class EliotLoggedRunTest(object):
|
||||
|
||||
@eliot_logged_test
|
||||
def run(self, result=None):
|
||||
# Workaround for https://github.com/itamarst/eliot/issues/456
|
||||
if PY3:
|
||||
self.case.eliot_logger._validate_message = lambda *args, **kwargs: None
|
||||
return self._run_tests_with_factory(
|
||||
self.case,
|
||||
self.handlers,
|
||||
|
@ -57,11 +57,14 @@ from ..util.eliotutil import (
|
||||
_parse_destination_description,
|
||||
_EliotLogging,
|
||||
)
|
||||
from ..util.jsonbytes import BytesJSONEncoder
|
||||
|
||||
from .common import (
|
||||
SyncTestCase,
|
||||
AsyncTestCase,
|
||||
)
|
||||
|
||||
|
||||
class EliotLoggedTestTests(AsyncTestCase):
|
||||
def test_returns_none(self):
|
||||
Message.log(hello="world")
|
||||
@ -94,7 +97,7 @@ class ParseDestinationDescriptionTests(SyncTestCase):
|
||||
reactor = object()
|
||||
self.assertThat(
|
||||
_parse_destination_description("file:-")(reactor),
|
||||
Equals(FileDestination(stdout)),
|
||||
Equals(FileDestination(stdout, encoder=BytesJSONEncoder)),
|
||||
)
|
||||
|
||||
|
||||
|
@ -86,6 +86,9 @@ from twisted.internet.defer import (
|
||||
)
|
||||
from twisted.application.service import Service
|
||||
|
||||
from .jsonbytes import BytesJSONEncoder
|
||||
|
||||
|
||||
def validateInstanceOf(t):
|
||||
"""
|
||||
Return an Eliot validator that requires values to be instances of ``t``.
|
||||
@ -302,7 +305,7 @@ class _DestinationParser(object):
|
||||
rotateLength=rotate_length,
|
||||
maxRotatedFiles=max_rotated_files,
|
||||
)
|
||||
return lambda reactor: FileDestination(get_file())
|
||||
return lambda reactor: FileDestination(get_file(), BytesJSONEncoder)
|
||||
|
||||
|
||||
_parse_destination_description = _DestinationParser().parse
|
||||
|
Loading…
Reference in New Issue
Block a user