From 3cd4d31c0b6ca5fae63b0146bf5a2440895cbbb0 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 6 Apr 2017 12:07:31 -0700 Subject: [PATCH] journal: add test coverage --- src/wormhole/journal.py | 2 ++ src/wormhole/test/test_journal.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/wormhole/test/test_journal.py diff --git a/src/wormhole/journal.py b/src/wormhole/journal.py index 61d1694..f7bf0f3 100644 --- a/src/wormhole/journal.py +++ b/src/wormhole/journal.py @@ -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 diff --git a/src/wormhole/test/test_journal.py b/src/wormhole/test/test_journal.py new file mode 100644 index 0000000..96b9319 --- /dev/null +++ b/src/wormhole/test/test_journal.py @@ -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"])