Example #1
0
    def test__disable_events__all(self, init_manager, mocker):
        """Test disabling all events."""
        mock_events = mocker.patch.object(
            ht.events.manager.HoudiniEventManager,
            "events",
            new_callable=mocker.PropertyMock,
        )

        mock_event1 = mocker.MagicMock(spec=HoudiniEvent)

        mock_enabled1 = mocker.PropertyMock(return_value=False)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = mocker.MagicMock(spec=HoudiniEvent)

        mock_enabled2 = mocker.PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = init_manager()
        manager._event_states = {}

        manager._disable_events()

        # Each event should have it's enabled property accessed twice:
        # once to store the current value and then to set the value to False
        mock_enabled1.assert_has_calls([mocker.call(), mocker.call(False)])
        mock_enabled2.assert_has_calls([mocker.call(), mocker.call(False)])

        assert not manager._event_states[mock_event1.name]
        assert manager._event_states[mock_event2.name]
    def test__disable_events__specific_names(self, mock_events):
        """Test disabling specific events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertTrue(manager._event_states[mock_event2.name])
        self.assertEqual(len(manager._event_states), 1)
    def test__disable_events__all(self, mock_events):
        """Test disabling all events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=False)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events()

        # Each event should have it's enabled property accessed twice:
        # once to store the current value and then to set the value to False
        mock_enabled1.assert_has_calls([call(), call(False)])
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertFalse(manager._event_states[mock_event1.name])
        self.assertTrue(manager._event_states[mock_event2.name])
    def test__disable_events__specific_names(self, mock_events):
        """Test disabling specific events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertTrue(manager._event_states[mock_event2.name])
        self.assertEqual(len(manager._event_states), 1)
    def test__disable_events__all(self, mock_events):
        """Test disabling all events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=False)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events()

        # Each event should have it's enabled property accessed twice:
        # once to store the current value and then to set the value to False
        mock_enabled1.assert_has_calls([call(), call(False)])
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertFalse(manager._event_states[mock_event1.name])
        self.assertTrue(manager._event_states[mock_event2.name])
Example #6
0
    def test__disable_events__specific_names(self, init_manager, mocker):
        """Test disabling specific events."""
        mock_events = mocker.patch.object(
            ht.events.manager.HoudiniEventManager,
            "events",
            new_callable=mocker.PropertyMock,
        )

        mock_event1 = mocker.MagicMock(spec=HoudiniEvent)

        mock_enabled1 = mocker.PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = mocker.MagicMock(spec=HoudiniEvent)

        mock_enabled2 = mocker.PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = init_manager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([mocker.call(), mocker.call(False)])

        assert manager._event_states[mock_event2.name]
        assert len(manager._event_states) == 1