tests: some more utility function tests + flake8.

issue510
David Wilson 6 years ago
parent 0ba8cc7b61
commit f5d9af80ef

@ -1,4 +1,3 @@
import os
import pickle
import sys

@ -1,15 +1,8 @@
import logging
import subprocess
import time
import zlib
import unittest2
import testlib
import mitogen.master
import mitogen.parent
import mitogen.utils
import mitogen.core
class ConstructorTest(testlib.TestCase):

@ -1,5 +1,3 @@
import logging
import subprocess
import time
import zlib

@ -1,11 +1,4 @@
try:
from io import StringIO
from io import BytesIO
except ImportError:
from StringIO import StringIO as StringIO
from StringIO import StringIO as BytesIO
import pickle
import unittest2

@ -0,0 +1,45 @@
import unittest2
import testlib
import mitogen.core
class Thing():
pass
class ListenFireTest(testlib.TestCase):
def test_no_args(self):
thing = Thing()
latch = mitogen.core.Latch()
mitogen.core.listen(thing, 'event',
lambda: latch.put('event fired'))
mitogen.core.fire(thing, 'event')
self.assertEquals('event fired', latch.get())
self.assertTrue(latch.empty())
def test_with_args(self):
thing = Thing()
latch = mitogen.core.Latch()
mitogen.core.listen(thing, 'event', latch.put)
mitogen.core.fire(thing, 'event', 'event fired')
self.assertEquals('event fired', latch.get())
self.assertTrue(latch.empty())
def test_two_listeners(self):
thing = Thing()
latch = mitogen.core.Latch()
latch2 = mitogen.core.Latch()
mitogen.core.listen(thing, 'event', latch.put)
mitogen.core.listen(thing, 'event', latch2.put)
mitogen.core.fire(thing, 'event', 'event fired')
self.assertEquals('event fired', latch.get())
self.assertEquals('event fired', latch2.get())
self.assertTrue(latch.empty())
self.assertTrue(latch2.empty())
if __name__ == '__main__':
unittest2.main()
Loading…
Cancel
Save