File: test_lib_pubsub_notify2_2.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (59 lines) | stat: -rw-r--r-- 1,617 bytes parent folder | download | duplicates (4)
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
"""

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


"""

import unittest

from unittests import wtc



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


class lib_pubsub_Notify2_2(wtc.PubsubTestCase):

    def test2_SendNotify(self):
        from wx.lib.pubsub.utils.notification import useNotifyByPubsubMessage

        useNotifyByPubsubMessage()

        # trap the pubsub.sendMessage topic:
        class SendHandler:
            def __init__(self):
                self.pre = self.post = 0

            def __call__(self, topic=None, stage=None, listener=None,
                         msgTopic=self.pub.AUTO_TOPIC):
                if stage == 'pre':
                    self.pre += 1
                else:
                    self.post += 1
                self.assertEqual(msgTopic.getName(), 'pubsub.sendMessage')
                self.assertEqual(topic.getName(), 'testSendNotify')

        sh = SendHandler()
        sh.assertEqual = self.assertEqual

        self.pub.subscribe(sh, 'pubsub.sendMessage')
        self.pub.setNotificationFlags(sendMessage=True)

        # generate a message that will cause pubsub.sendMessage to be generated too
        assert sh.pre == 0
        assert sh.post == 0
        self.pub.getDefaultTopicMgr().getOrCreateTopic('testSendNotify')
        self.pub.sendMessage('testSendNotify')
        assert sh.pre == 1
        assert sh.post == 1



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


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