journal: add test coverage
This commit is contained in:
parent
df1b2338b1
commit
3cd4d31c0b
|
@ -29,6 +29,8 @@ class Journal(object):
|
|||
|
||||
@implementer(IJournal)
|
||||
class ImmediateJournal(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
def queue_outbound(self, fn, *args, **kwargs):
|
||||
fn(*args, **kwargs)
|
||||
@contextlib.contextmanager
|
||||
|
|
28
src/wormhole/test/test_journal.py
Normal file
28
src/wormhole/test/test_journal.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from __future__ import print_function, absolute_import, unicode_literals
|
||||
from twisted.trial import unittest
|
||||
from .. import journal
|
||||
from .._interfaces import IJournal
|
||||
|
||||
class Journal(unittest.TestCase):
|
||||
def test_journal(self):
|
||||
events = []
|
||||
j = journal.Journal(lambda: events.append("checkpoint"))
|
||||
self.assert_(IJournal.providedBy(j))
|
||||
|
||||
with j.process():
|
||||
j.queue_outbound(events.append, "message1")
|
||||
j.queue_outbound(events.append, "message2")
|
||||
self.assertEqual(events, [])
|
||||
self.assertEqual(events, ["checkpoint", "message1", "message2"])
|
||||
|
||||
def test_immediate(self):
|
||||
events = []
|
||||
j = journal.ImmediateJournal()
|
||||
self.assert_(IJournal.providedBy(j))
|
||||
|
||||
with j.process():
|
||||
j.queue_outbound(events.append, "message1")
|
||||
self.assertEqual(events, ["message1"])
|
||||
j.queue_outbound(events.append, "message2")
|
||||
self.assertEqual(events, ["message1", "message2"])
|
||||
self.assertEqual(events, ["message1", "message2"])
|
Loading…
Reference in New Issue
Block a user