def test_register_event_group__single_items(self, mock_events, mock_create): """Test registering a group where no event of that name has been created.""" mock_item1 = MagicMock(spec=HoudiniEventItem) mock_item2 = MagicMock(spec=HoudiniEventItem) mock_event_name1 = MagicMock(spec=str) mock_event_name2 = MagicMock(spec=str) event_map = { mock_event_name1: mock_item1, mock_event_name2: mock_item2 } mock_group = MagicMock(spec=HoudiniEventGroup) type(mock_group).event_map = PropertyMock(return_value=event_map) mock_event1 = MagicMock(spec=HoudiniEvent) mock_event2 = MagicMock(spec=HoudiniEvent) events = {mock_event_name2: mock_event2} mock_events.return_value = events mock_create.side_effect = lambda name: events.setdefault( name, mock_event1) manager = ht.events.manager.HoudiniEventManager() manager.register_event_group(mock_group) mock_create.assert_called_with(mock_event_name1) mock_event1.register_item.assert_called_with(mock_item1) mock_event2.register_item.assert_called_with(mock_item2)
def test_register_event_group__item_lists(self, mock_events, mock_create): """Test registering a group where no event of that name has been created.""" mock_item1 = MagicMock(spec=HoudiniEventItem) mock_item2 = MagicMock(spec=HoudiniEventItem) mock_event_name1 = MagicMock(spec=str) mock_event_name2 = MagicMock(spec=str) event_map = { mock_event_name1: [mock_item1], mock_event_name2: [mock_item2] } mock_group = MagicMock(spec=HoudiniEventGroup) type(mock_group).event_map = PropertyMock(return_value=event_map) event_name1 = mock_event_name1 mock_event1 = MagicMock(spec=HoudiniEvent) mock_event2 = MagicMock(spec=HoudiniEvent) events = {mock_event_name2: mock_event2} mock_events.return_value = events mock_create.side_effect = lambda name: events.setdefault(name, mock_event1) manager = ht.events.manager.HoudiniEventManager() manager.register_event_group(mock_group) mock_create.assert_called_with(event_name1) mock_event1.register_item.assert_called_with(mock_item1) mock_event2.register_item.assert_called_with(mock_item2)
def test_register_event_group__invalid_type(self, init_manager, mocker): """Test registering an event group with an invalid object type.""" # Don't spec so it will fail isinstance(EventGroup) mock_group = mocker.MagicMock() manager = init_manager() with pytest.raises(TypeError): manager.register_event_group(mock_group)
def test_register_event_group__invalid_type(self): """Test registering an event group with an invalid object type.""" # Don't spec so it will fail isinstance(EventGroup) mock_group = MagicMock() manager = ht.events.manager.HoudiniEventManager() with self.assertRaises(TypeError): manager.register_event_group(mock_group)
def test_register_event_group__item_lists(self, init_manager, mocker): """Test registering a group where no event of that name has been created.""" 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_item1 = mocker.MagicMock(spec=HoudiniEventItem) mock_item2 = mocker.MagicMock(spec=HoudiniEventItem) mock_event_name1 = mocker.MagicMock(spec=str) mock_event_name2 = mocker.MagicMock(spec=str) event_map = { mock_event_name1: [mock_item1], mock_event_name2: [mock_item2] } mock_group = mocker.MagicMock(spec=HoudiniEventGroup) type(mock_group).event_map = mocker.PropertyMock( return_value=event_map) event_name1 = mock_event_name1 mock_event1 = mocker.MagicMock(spec=HoudiniEvent) mock_event2 = mocker.MagicMock(spec=HoudiniEvent) events = {mock_event_name2: mock_event2} mock_events.return_value = events mock_create.side_effect = lambda name: events.setdefault( name, mock_event1) manager = init_manager() manager.register_event_group(mock_group) mock_create.assert_called_with(event_name1) mock_event1.register_item.assert_called_with(mock_item1) mock_event2.register_item.assert_called_with(mock_item2)
"""Initialize the events package.""" # ============================================================================= # IMPORTS # ============================================================================= # Houdini Toolbox Imports from ht.events.events import rop_render, scene_load from ht.events.manager import register_event_group, register_function, register_item, run_event from ht.events.types import NodeEvents, RopEvents, SceneEvents # ============================================================================= # Register the package's ROP render script events. register_event_group(rop_render.RopRenderEvent()) # Register the package's SceneLoadEvent. register_event_group(scene_load.SceneLoadEvent())
"""Initialize the events package.""" # ============================================================================= # IMPORTS # ============================================================================= # Houdini Toolbox Imports from ht.events.events import rop_render, scene_load from ht.events.manager import register_event_group, register_function, register_item, run_event from ht.events.types import HipFileEvents, NodeEvents, RopEvents, SceneEvents # ============================================================================= # Register the package's ROP render script events. register_event_group(rop_render.RopRenderEvent()) # Register the package's SceneLoadEvent. register_event_group(scene_load.SceneLoadEvent())