mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-01 08:48:01 +00:00
convert some tests over to the new base class
in support of better logging
This commit is contained in:
parent
29e3390fb9
commit
1d0c862c54
@ -2,6 +2,10 @@ __all__ = [
|
||||
"SyncTestCase",
|
||||
"AsyncTestCase",
|
||||
"AsyncBrokenTestCase",
|
||||
|
||||
"flush_logged_errors",
|
||||
"skip",
|
||||
"skipIf",
|
||||
]
|
||||
|
||||
import os, random, struct
|
||||
@ -16,11 +20,14 @@ from zope.interface import implementer
|
||||
|
||||
from testtools import (
|
||||
TestCase,
|
||||
skip,
|
||||
skipIf,
|
||||
)
|
||||
from testtools.twistedsupport import (
|
||||
SynchronousDeferredRunTest,
|
||||
AsynchronousDeferredRunTest,
|
||||
AsynchronousDeferredRunTestForBrokenTwisted,
|
||||
flush_logged_errors,
|
||||
)
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -57,22 +57,23 @@ def eliot_logged_test(f):
|
||||
|
||||
@wraps(f)
|
||||
def run_and_republish(self, *a, **kw):
|
||||
# Unfortunately the only way to get at the global/default logger...
|
||||
# This import is delayed here so that we get the *current* default
|
||||
# logger at the time the decorated function is run.
|
||||
from eliot._output import _DEFAULT_LOGGER as default_logger
|
||||
|
||||
def republish():
|
||||
# This is called as a cleanup function after capture_logging has
|
||||
# restored the global/default logger to its original state. We
|
||||
# can now emit messages that go to whatever global destinations
|
||||
# are installed.
|
||||
|
||||
# Unfortunately the only way to get at the global/default
|
||||
# logger...
|
||||
from eliot._output import _DEFAULT_LOGGER as logger
|
||||
|
||||
# storage.logger.serialize() seems like it would make more sense
|
||||
# than storage.logger.messages here. However, serialize()
|
||||
# explodes, seemingly as a result of double-serializing the logged
|
||||
# messages. I don't understand this.
|
||||
for msg in storage.logger.messages:
|
||||
logger.write(msg)
|
||||
default_logger.write(msg)
|
||||
|
||||
# And now that we've re-published all of the test's messages, we
|
||||
# can finish the test's action.
|
||||
|
@ -12,21 +12,22 @@ import sys
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
from twisted.python import filepath, runtime
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.frontends.magic_folder import get_inotify_module
|
||||
|
||||
from .common import (
|
||||
AsyncTestCase,
|
||||
skip,
|
||||
skipIf,
|
||||
)
|
||||
inotify = get_inotify_module()
|
||||
|
||||
|
||||
class INotifyTests(unittest.TestCase):
|
||||
@skipIf(runtime.platformType == "win32", "inotify does not yet work on windows")
|
||||
class INotifyTests(AsyncTestCase):
|
||||
"""
|
||||
Define all the tests for the basic functionality exposed by
|
||||
L{inotify.INotify}.
|
||||
"""
|
||||
if runtime.platformType == "win32":
|
||||
skip = "inotify does not yet work on windows"
|
||||
|
||||
def setUp(self):
|
||||
self.ignore_count = 0
|
||||
self.dirname = filepath.FilePath(self.mktemp())
|
||||
@ -34,6 +35,7 @@ class INotifyTests(unittest.TestCase):
|
||||
self.inotify = inotify.INotify()
|
||||
self.inotify.startReading()
|
||||
self.addCleanup(self.inotify.stopReading)
|
||||
return super(INotifyTests, self).setUp()
|
||||
|
||||
|
||||
def _notificationTest(self, mask, operation, expectedPath=None, ignore_count=0):
|
||||
@ -215,6 +217,7 @@ class INotifyTests(unittest.TestCase):
|
||||
set(['close_write', 'access', 'open']))
|
||||
|
||||
|
||||
@skip("not relevant")
|
||||
def test_recursiveWatch(self):
|
||||
"""
|
||||
L{inotify.INotify.watch} with recursive==True will add all the
|
||||
@ -230,9 +233,9 @@ class INotifyTests(unittest.TestCase):
|
||||
self.inotify.watch(self.dirname, recursive=True)
|
||||
for d in dirs:
|
||||
self.assertTrue(self.inotify._isWatched(d))
|
||||
test_recursiveWatch.skip = "not relevant"
|
||||
|
||||
|
||||
@skip("Based on Twisted implementation details; not relevant")
|
||||
def test_connectionLostError(self):
|
||||
"""
|
||||
L{inotify.INotify.connectionLost} if there's a problem while closing
|
||||
@ -243,7 +246,7 @@ class INotifyTests(unittest.TestCase):
|
||||
os.close(in_._fd)
|
||||
in_.loseConnection()
|
||||
self.flushLoggedErrors()
|
||||
test_connectionLostError.skip = "Based on Twisted implementation details; not relevant"
|
||||
|
||||
|
||||
def test_noAutoAddSubdirectory(self):
|
||||
"""
|
||||
|
@ -9,9 +9,6 @@ from twisted.internet import defer, task, reactor
|
||||
from twisted.python.runtime import platform
|
||||
from twisted.python.filepath import FilePath
|
||||
|
||||
from testtools import (
|
||||
skipIf,
|
||||
)
|
||||
from testtools.matchers import (
|
||||
Not,
|
||||
Is,
|
||||
@ -41,6 +38,7 @@ from .common import (
|
||||
ShouldFailMixin,
|
||||
SyncTestCase,
|
||||
AsyncTestCase,
|
||||
skipIf,
|
||||
)
|
||||
from .cli.test_magic_folder import MagicFolderCLITestMixin
|
||||
|
||||
|
@ -361,6 +361,7 @@ class _EliotLogging(Service):
|
||||
self.twisted_observer = _TwistedLoggerToEliotObserver()
|
||||
globalLogPublisher.addObserver(self.twisted_observer)
|
||||
add_destinations(*self.destinations)
|
||||
return Service.startService(self)
|
||||
|
||||
|
||||
def stopService(self):
|
||||
@ -368,7 +369,7 @@ class _EliotLogging(Service):
|
||||
remove_destination(dest)
|
||||
globalLogPublisher.removeObserver(self.twisted_observer)
|
||||
self.stdlib_cleanup()
|
||||
|
||||
return Service.stopService(self)
|
||||
|
||||
|
||||
@implementer(ILogObserver)
|
||||
|
Loading…
x
Reference in New Issue
Block a user