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