Exemple #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)
Exemple #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)
Exemple #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()
Exemple #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()
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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
        )