def test_dictionarize(self): """Make sure we dictionarize to the expected format""" thestate = state.State(publish=lambda e, t: None, time=lambda: 42) thestate.update("foobar", {"a": True, "b": 1.7, "c": 13}) thestate.update("since", 1234567890) thestate.update("xo") thestate.update("idle") self.assertEquals( thestate.dictionarize(), { "current": "idle", "events": { "since": 1234567890, "pid": os.getpid(), "foobar": { "a": True, "b": 1.7, "c": 13, }, "xo": {}, "idle": {}, }, "t": 42, })
def test_dont_publish(self): """Make sure we DON'T publish when not requested to do so""" count = [-1] def do_publish(event, timestamp): ''' convenience function ''' count[0] = count[0] + 1 thestate = state.State(publish=do_publish) thestate.update("foobar", publish=False) self.assertEquals(count[0], 1)
def test_publish(self): """Make sure we publish when requested to do so""" count = [-1] def do_publish(event, timestamp): ''' convenience function ''' count[0] = count[0] + 1 thestate = state.State(publish=do_publish) thestate.update("foobar") # Because the ctor performs two internal update()s self.assertEquals(count[0], 2)
def test_current(self): """Make sure we honour current""" thestate = state.State(publish=lambda e, t: None) thestate.update("idle") self.assertEquals(thestate.current, "idle")
def test_update_event(self): """Make sure we correctly set the empty event""" thestate = state.State(publish=lambda e, t: None) thestate.update("foobar") self.assertEquals(thestate.events["foobar"], {})