def test_time_function_existing(self, mock_time, mock_item_stats): mock_time.side_effect = (1, 2, 5, 8) mock_func1 = MagicMock() mock_func1.__name__ = MagicMock(spec=str) mock_func2 = MagicMock() mock_func2.__name__ = MagicMock(spec=str) odict = OrderedDict() odict[mock_func1.__name__] = 1 mock_item_stats.return_value = odict stats = ht.events.stats.HoudiniEventItemStats(None) with stats.time_function(mock_func1): pass with stats.time_function(mock_func2): pass expected = OrderedDict() expected[mock_func1.__name__] = 2 expected[mock_func2.__name__] = 3 self.assertEqual(stats.item_stats, expected)
def test_time_function_existing(self, init_item_stats, mocker): mock_item_stats = mocker.patch.object( ht.events.stats.HoudiniEventItemStats, "item_stats", new_callable=mocker.PropertyMock) mock_time = mocker.patch("time.time") mock_start1 = mocker.MagicMock(spec=int) mock_start2 = mocker.MagicMock(spec=int) mock_end1 = mocker.MagicMock(spec=int) mock_end2 = mocker.MagicMock(spec=int) mock_time.side_effect = (mock_start1, mock_end1, mock_start2, mock_end2) mock_func1 = mocker.MagicMock() mock_func1.__name__ = mocker.MagicMock(spec=str) mock_func2 = mocker.MagicMock() mock_func2.__name__ = mocker.MagicMock(spec=str) odict = OrderedDict() odict[mock_func1.__name__] = 1 mock_item_stats.return_value = odict stats = init_item_stats() with stats.time_function(mock_func1): pass with stats.time_function(mock_func2): pass expected = OrderedDict() expected[mock_func1.__name__] = 0 + (mock_end1 - mock_start1) expected[mock_func2.__name__] = 0 + (mock_end2 - mock_start2) assert stats.item_stats == expected