File: test_lib_pubsub_notify.py

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (69 lines) | stat: -rw-r--r-- 1,918 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""

:copyright: Copyright 2006-2009 by Oliver Schoenborn, all rights reserved.
:license: BSD, see LICENSE.txt for details.


"""

import unittest
from unittests import wtc

from difflib import ndiff, unified_diff, context_diff


#---------------------------------------------------------------------------


class lib_pubsub_Notify(wtc.PubsubTestCase):


    def testNotifyByPrint(self):
        from wx.lib.pubsub.utils.notification import useNotifyByWriteFile

        def captureStdout():
            from six import StringIO
            capture = StringIO()
            useNotifyByWriteFile( fileObj = capture )
            return capture
        capture = captureStdout()


        def listener1(arg1):
            pass
        self.pub.subscribe(listener1, 'baz')
        self.pub.sendMessage('baz', arg1=123)
        self.pub.unsubscribe(listener1, 'baz')

        def doa():
            def listener2():
                pass
            self.pub.subscribe(listener2, 'bar')
        doa()

        self.pub.getDefaultTopicMgr().delTopic('baz')

        expect = '''\
PUBSUB: New topic "baz" created
PUBSUB: Subscribed listener "listener1" to topic "baz"
PUBSUB: Start sending message of topic "baz"
PUBSUB: Sending message of topic "baz" to listener listener1
PUBSUB: Done sending message of topic "baz"
PUBSUB: Unsubscribed listener "listener1" from topic "baz"
PUBSUB: New topic "bar" created
PUBSUB: Subscribed listener "listener2" to topic "bar"
PUBSUB: Listener "listener2" of Topic "bar" has died
PUBSUB: Topic "baz" destroyed
    '''.strip()
        captured = capture.getvalue().strip()
        # strip as other wise one has \n, at least on windows
        assert captured == expect, \
            '\n'.join( unified_diff(expect.splitlines(), captured.splitlines(), n=0) )



#---------------------------------------------------------------------------


if __name__ == '__main__':
    unittest.main()