journal: add test coverage

This commit is contained in:
Brian Warner 2017-04-06 12:07:31 -07:00
parent df1b2338b1
commit 3cd4d31c0b
2 changed files with 30 additions and 0 deletions

View File

@ -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

View 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"])