Exemple #1
0
    def test_reset(self):
        """Assert reset empties totals, history and latest"""

        tracker = Tracker()

        tracker.totals = {"a": 1}
        tracker.history = {"a": [1]}
        tracker.latest = {"a": 1}

        tracker.reset()

        assert tracker.totals == dict()
        assert tracker.history == dict()
        assert tracker.latest == dict()
Exemple #2
0
    def test_enter_and_exit(self):
        """Assert entering and exit work as expected"""

        tracker = Tracker()
        tracker.totals = {"a": 1}
        tracker.history = {"a": [1]}
        tracker.latest = {"a": 1}

        returned = tracker.__enter__()

        assert id(tracker) == id(returned)
        assert tracker.active == True

        assert tracker.totals == dict()
        assert tracker.history == dict()
        assert tracker.latest == dict()

        tracker.__exit__(None, None, None)

        assert tracker.active == False
Exemple #3
0
    def test_record_callback(self, mocker):
        class callback_wrapper:
            @staticmethod
            def callback(totals, history, latest):
                pass

        wrapper = callback_wrapper()
        spy = mocker.spy(wrapper, "callback")

        tracker = Tracker(callback=wrapper.callback)

        tracker.totals = {"a": 1, "b": 2}
        tracker.history = {"a": [1], "b": [1, 1]}
        tracker.latest = {"a": 1, "b": 1}

        tracker.record()

        _, kwargs_called = spy.call_args_list[-1]

        assert kwargs_called["totals"] == tracker.totals
        assert kwargs_called["history"] == tracker.history
        assert kwargs_called["latest"] == tracker.latest