Example #1
0
    def test__run(self, init_exclusive_item, mocker):
        mocker.patch("ht.events.item.ExclusiveHoudiniEventItem.__eq__",
                     return_value=True)
        mock_super_run = mocker.patch.object(ht.events.item.HoudiniEventItem,
                                             "run")
        mock_map = mocker.patch.object(
            ht.events.item.ExclusiveHoudiniEventItem,
            "_exclusive_map",
            new_callable=mocker.PropertyMock,
        )
        mock_name = mocker.patch.object(
            ht.events.item.ExclusiveHoudiniEventItem,
            "name",
            new_callable=mocker.PropertyMock,
        )

        item = init_exclusive_item()

        mock_map.return_value = {mock_name.return_value: item}

        mock_scriptargs = mocker.MagicMock(spec=dict)

        item.run(mock_scriptargs)

        mock_super_run.assert_called_with(mock_scriptargs)
Example #2
0
    def test_run__no_run(self, init_exclusive_item, mocker):
        """Test when the event item is not the exclusive item."""
        mocker.patch("ht.events.item.ExclusiveHoudiniEventItem.__eq__",
                     return_value=False)
        mock_super_run = mocker.patch.object(ht.events.item.HoudiniEventItem,
                                             "run")
        mock_map = mocker.patch.object(
            ht.events.item.ExclusiveHoudiniEventItem,
            "_exclusive_map",
            new_callable=mocker.PropertyMock,
        )
        mock_name = mocker.patch.object(
            ht.events.item.ExclusiveHoudiniEventItem,
            "name",
            new_callable=mocker.PropertyMock,
        )

        item = init_exclusive_item()

        mock_map.return_value = {mock_name.return_value: item}

        scriptargs = {"key": "value"}

        item.run(scriptargs)
        mock_super_run.assert_not_called()
Example #3
0
    def test_run__no_run(self, mock_eq, mock_super_run, mock_map, mock_name):
        mock_eq.return_value = False

        item = ht.events.item.ExclusiveHoudiniEventItem(None, None, None, None)

        mock_map.return_value = {mock_name.return_value: item}

        scriptargs = {"key": "value"}

        item.run(scriptargs)
        mock_super_run.assert_not_called()
Example #4
0
    def test_run(self, init_item, mocker):
        """Test running an item."""
        mock_stats = mocker.patch.object(ht.events.item.HoudiniEventItem,
                                         "stats",
                                         new_callable=mocker.PropertyMock)
        mock_callables = mocker.patch.object(
            ht.events.item.HoudiniEventItem,
            "callables",
            new_callable=mocker.PropertyMock,
        )

        item = init_item()

        stats = mocker.MagicMock(spec=ht.events.stats.HoudiniEventItemStats)

        mock_stats.return_value = stats

        # To ensure that the callables are called with the HoudiniEventItem in the scriptargs
        # as _item_ we need to record the call data ourselves because Mock just
        # stores a reference and since we add/del the item into the dict it won't
        # be there inside the data that it thinks the functions were called with.
        real_call_args = []

        mock_func1 = mocker.MagicMock()
        mock_func1.side_effect = lambda sa: real_call_args.append(copy.copy(sa)
                                                                  )

        mock_func2 = mocker.MagicMock()
        mock_func2.side_effect = lambda sa: real_call_args.append(copy.copy(sa)
                                                                  )

        mock_callables.return_value = [mock_func1, mock_func2]

        scriptargs = {"key": "value"}
        run_args = {"key": "value", "_item_": item}

        item.run(scriptargs)

        # Ensure the context manager was called.
        stats.__enter__.assert_called_once()
        stats.__exit__.assert_called_once()

        # Ensure time_child was called with the functions.  Do it this way since
        # the calls list is confusing due to the contextmanager decorator.
        stats.time_function.assert_any_call(mock_func1)
        stats.time_function.assert_any_call(mock_func2)

        # Ensure the functions were called with the real args.
        assert real_call_args[0] == run_args
        assert real_call_args[1] == run_args

        # Ensure we removed the item.
        assert scriptargs == {"key": "value"}
Example #5
0
    def test__run(self, mock_eq, mock_super_run, mock_map, mock_name):
        mock_eq.return_value = True

        item = ht.events.item.ExclusiveHoudiniEventItem(None, None, None, None)

        mock_map.return_value = {mock_name.return_value: item}

        mock_scriptargs = MagicMock(spec=dict)

        item.run(mock_scriptargs)

        mock_super_run.assert_called_with(mock_scriptargs)
    def test_run(self, mock_stats, mock_callables):
        """Test running an item."""
        item = ht.events.item.HoudiniEventItem(None, None, None, None)

        stats = MagicMock(spec=ht.events.stats.HoudiniEventItemStats)

        mock_stats.return_value = stats

        # To ensure that the callables are called with the HoudiniEventItem in the scriptargs
        # as _item_ we need to record the call data ourselves because Mock just
        # stores a reference and since we add/del the item into the dict it won't
        # be there inside the data that it thinks the functions were called with.
        real_call_args = []

        mock_func1 = MagicMock()
        mock_func1.side_effect = lambda sa: real_call_args.append(copy.copy(sa))

        mock_func2 = MagicMock()
        mock_func2.side_effect = lambda sa: real_call_args.append(copy.copy(sa))

        mock_callables.return_value = [mock_func1, mock_func2]

        scriptargs = {"key": "value"}
        run_args = {"key": "value", "_item_": item}

        item.run(scriptargs)

        # Ensure the context manager was called.
        stats.__enter__.assert_called_once()
        stats.__exit__.assert_called_once()

        # Ensure time_child was called with the functions.  Do it this way since
        # the calls list is confusing due to the contextmanager decorator.
        stats.time_function.assert_any_call(mock_func1)
        stats.time_function.assert_any_call(mock_func2)

        # Ensure the functions were called with the real args.
        self.assertEqual(real_call_args[0], run_args)
        self.assertEqual(real_call_args[1], run_args)

        # Ensure we removed the item.
        self.assertEqual(scriptargs, {"key": "value"})