예제 #1
0
    def test_add_callback(self):
        mock = unittest.mock.Mock()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        with self.assertRaisesRegex(ValueError,
                                     "only one listener is allowed"):
            nh.add_callback("tag", mock)
예제 #2
0
    def test_add_callback(self):
        mock = unittest.mock.Mock()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        with self.assertRaisesRegex(ValueError,
                                    "only one listener is allowed"):
            nh.add_callback("tag", mock)
예제 #3
0
 def test_remove_listener(self):
     mock = unittest.mock.Mock()
     nh = TagDispatcher()
     nh.add_callback("tag", mock)
     nh.remove_listener("tag")
     with self.assertRaises(KeyError):
         nh.unicast("tag", object())
     mock.assert_not_called()
예제 #4
0
 def test_remove_listener(self):
     mock = unittest.mock.Mock()
     nh = TagDispatcher()
     nh.add_callback("tag", mock)
     nh.remove_listener("tag")
     with self.assertRaises(KeyError):
         nh.unicast("tag", object())
     mock.assert_not_called()
예제 #5
0
    def test_unicast_removes_for_true_result(self):
        mock = unittest.mock.Mock()
        mock.return_value = True
        obj = object()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        nh.unicast("tag", obj)
        with self.assertRaises(KeyError):
            nh.unicast("tag", obj)

        mock.assert_called_once_with(obj)
예제 #6
0
    def test_unicast_removes_for_true_result(self):
        mock = unittest.mock.Mock()
        mock.return_value = True
        obj = object()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        nh.unicast("tag", obj)
        with self.assertRaises(KeyError):
            nh.unicast("tag", obj)

        mock.assert_called_once_with(obj)
예제 #7
0
    def test_unicast(self):
        mock = unittest.mock.Mock()
        mock.return_value = False
        obj = object()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        nh.unicast("tag", obj)
        nh.unicast("tag", obj)

        self.assertSequenceEqual([
            unittest.mock.call(obj),
            unittest.mock.call(obj),
        ], mock.mock_calls)
예제 #8
0
    def test_unicast(self):
        mock = unittest.mock.Mock()
        mock.return_value = False
        obj = object()

        nh = TagDispatcher()
        nh.add_callback("tag", mock)
        nh.unicast("tag", obj)
        nh.unicast("tag", obj)

        self.assertSequenceEqual(
            [
                unittest.mock.call(obj),
                unittest.mock.call(obj),
            ],
            mock.mock_calls
        )