def test_register_item__existing_event(self, init_manager, mocker): """Test registering an item to an existing event.""" mock_events = mocker.patch.object( ht.events.manager.HoudiniEventManager, "events", new_callable=mocker.PropertyMock, ) mock_create = mocker.patch.object( ht.events.manager.HoudiniEventManager, "create_event" ) mock_event_name = mocker.MagicMock(spec=str) mock_event = mocker.MagicMock(spec=HoudiniEvent) mock_events.return_value = {mock_event_name: mock_event} mock_item = mocker.MagicMock(spec=HoudiniEventItem) manager = init_manager() manager.register_item(mock_item, mock_event_name) mock_create.assert_not_called() mock_event.register_item.assert_called_with(mock_item)
def test_register_item__invalid_type(self, init_manager, mocker): """Test registering an invalid type.""" # Don't spec so it will fail isinstance(HoudiniEventItem) manager = init_manager() with pytest.raises(TypeError): manager.register_item(None, mocker.MagicMock(spec=str))
def test_register_item__new_event(self, init_manager, mocker): """Test registering an item whose event does not exist yet.""" mock_events = mocker.patch.object( ht.events.manager.HoudiniEventManager, "events", new_callable=mocker.PropertyMock, ) mock_create = mocker.patch.object( ht.events.manager.HoudiniEventManager, "create_event" ) mock_event_name = mocker.MagicMock(spec=str) mock_event = mocker.MagicMock(spec=HoudiniEvent) events = {} mock_events.return_value = events mock_create.side_effect = lambda name: events.setdefault(name, mock_event) mock_item = mocker.MagicMock(spec=HoudiniEventItem) manager = init_manager() manager.register_item(mock_item, mock_event_name) mock_create.assert_called_with(mock_event_name) mock_event.register_item.assert_called_with(mock_item)
def test_register_item__existing_event(self, mock_events, mock_create): mock_event_name = MagicMock(spec=str) mock_event = MagicMock(spec=HoudiniEvent) mock_events.return_value = {mock_event_name: mock_event} mock_item = MagicMock(spec=HoudiniEventItem) manager = ht.events.manager.HoudiniEventManager() manager.register_item(mock_item, mock_event_name) mock_create.assert_not_called() mock_event.register_item.assert_called_with(mock_item)
def test_register_item__existing_event(self, mock_events, mock_create): mock_event_name = MagicMock(spec=str) mock_event = MagicMock(spec=HoudiniEvent) mock_events.return_value = {mock_event_name: mock_event} mock_item = MagicMock(spec=HoudiniEventItem) manager = ht.events.manager.HoudiniEventManager() manager.register_item(mock_item, mock_event_name) mock_create.assert_not_called() mock_event.register_item.assert_called_with(mock_item)
def test_register_item__new_event(self, mock_events, mock_create): mock_event_name = MagicMock(spec=str) mock_event = MagicMock(spec=HoudiniEvent) events = {} mock_events.return_value = events mock_create.side_effect = lambda name: events.setdefault(name, mock_event) mock_item = MagicMock(spec=HoudiniEventItem) manager = ht.events.manager.HoudiniEventManager() manager.register_item(mock_item, mock_event_name) mock_create.assert_called_with(mock_event_name) mock_event.register_item.assert_called_with(mock_item)
def test_register_item__invalid_type(self): # Don't spec so it will fail isinstance(HoudiniEventItem) manager = ht.events.manager.HoudiniEventManager() with self.assertRaises(TypeError): manager.register_item(None, MagicMock(spec=str))
def test_register_item__invalid_type(self): # Don't spec so it will fail isinstance(HoudiniEventItem) manager = ht.events.manager.HoudiniEventManager() with self.assertRaises(TypeError): manager.register_item(None, MagicMock(spec=str))