示例#1
0
    def setUp(self):
        self.gdk_patcher = GtkGdkPatch()
        self.gdk_patcher.patch_in_setup(test_case=self)

        from mousetrap.core import Observable
        self.observable = Observable()
        self.client1 = Client()
        self.client2 = Client()
示例#2
0
class test_Observable(unittest.TestCase):

    def setUp(self):
        self.gdk_patcher = GtkGdkPatch()
        self.gdk_patcher.patch_in_setup(test_case=self)

        from mousetrap.core import Observable
        self.observable = Observable()
        self.client1 = Client()
        self.client2 = Client()

    def test_observable_callback_noArguments_success(self):
        self.observable.subscribe(self.client1)
        self.observable._fire('callback')
        self.assertTrue(
            len(self.client1.callback_params) == 1,
            msg="callback not called."
        )

    def test_observable_callback_withArguments_success(self):
        self.observable._add_argument('param', 'param')
        self.observable.subscribe(self.client1)
        self.observable._fire('callback')
        self.assertEquals(
            'param',
            self.client1.callback_params[0]['param'],
            msg="param not passed correctly."
        )

    def test_multiple_subscribers(self):
        self.observable.subscribe(self.client1)
        self.observable.subscribe(self.client2)
        self.observable._fire('callback')
        self.assertEqual(
            len(self.client1.callback_params),
            1,
            msg="callback not called on client1."
        )
        self.assertEqual(
            len(self.client2.callback_params),
            1,
            msg="callback not called on client2."
        )