diff --git a/tests/call_error_test.py b/tests/call_error_test.py index 72d3c46e..baebd1eb 100644 --- a/tests/call_error_test.py +++ b/tests/call_error_test.py @@ -1,4 +1,3 @@ -import os import pickle import sys diff --git a/tests/error_test.py b/tests/error_test.py index 7f890875..2eefd567 100644 --- a/tests/error_test.py +++ b/tests/error_test.py @@ -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): diff --git a/tests/router_test.py b/tests/router_test.py index 351d7ace..51035d54 100644 --- a/tests/router_test.py +++ b/tests/router_test.py @@ -1,5 +1,3 @@ -import logging -import subprocess import time import zlib diff --git a/tests/serialization_test.py b/tests/serialization_test.py index d8c54c59..ffbdf694 100644 --- a/tests/serialization_test.py +++ b/tests/serialization_test.py @@ -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 diff --git a/tests/signals_test.py b/tests/signals_test.py new file mode 100644 index 00000000..5957d3fa --- /dev/null +++ b/tests/signals_test.py @@ -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() diff --git a/tests/types_test.py b/tests/types_test.py index 2f0b1306..bd243949 100644 --- a/tests/types_test.py +++ b/tests/types_test.py @@ -26,14 +26,14 @@ class BlobTest(testlib.TestCase): def test_decays_on_constructor(self): blob = self.make() - self.assertEquals(b('x')*128, mitogen.core.BytesType(blob)) + self.assertEquals(b('x') * 128, mitogen.core.BytesType(blob)) def test_decays_on_write(self): blob = self.make() io = BytesIO() io.write(blob) self.assertEquals(128, io.tell()) - self.assertEquals(b('x')*128, io.getvalue()) + self.assertEquals(b('x') * 128, io.getvalue()) def test_message_roundtrip(self): blob = self.make()