Exemple #1
0
    def test_value_averaged_within_scope(self, mocker):
        logger = TrainingLogger()
        handler_mock = mocker.Mock()
        logger.register_handler('handler', handler_mock)
        logger.register_value('value', ['handler'], average=True)

        logger.log_value('value', 1)
        assert logger.get_value('value') == 1
        logger.log_value('value', 2)
        assert logger.get_value('value') == 1.5
        logger.log_value('value', 3)
        assert logger.get_value('value') == 2
Exemple #2
0
    def test_saves_instant_values(self, mocker):
        logger = TrainingLogger()
        handler_mock = mocker.Mock()
        logger.register_handler('handler', handler_mock)
        logger.register_value('value', ['handler'], average=True)

        logger.log_value('value', 1)
        assert logger.get_value('value') == 1
        assert handler_mock.write.call_args_list[0][0][0].instant_value == 1
        logger.log_value('value', 2)
        assert logger.get_value('value') == 1.5
        assert handler_mock.write.call_args_list[1][0][0].instant_value == 2
        logger.log_value('value', 3)
        assert logger.get_value('value') == 2
        assert handler_mock.write.call_args_list[2][0][0].instant_value == 3
Exemple #3
0
    def test_value_resets(self, periodic_handler_mock):
        logger = TrainingLogger()
        logger.register_handler('handler', periodic_handler_mock)
        logger.register_value('scope/value', ['handler'], average=True)

        with logger.scope(scope='test_scope'):
            logger.log_value('scope/value', 1)
            logger.log_value('scope/value', 2)
            logger.log_value('scope/value', 3)
        assert logger.get_value('scope/value') == 2

        logger.reset_values('scope')

        with logger.scope(scope='test_scope'):
            logger.log_value('scope/value', 5)
            logger.log_value('scope/value', 10)
            logger.log_value('scope/value', 15)
        assert logger.get_value('scope/value') == 10