File: signals_test.py

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (38 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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.assertEqual('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.assertEqual('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.assertEqual('event fired', latch.get())
        self.assertEqual('event fired', latch2.get())
        self.assertTrue(latch.empty())
        self.assertTrue(latch2.empty())