Coverage for mlos_bench/mlos_bench/tests/storage/trial_data_test.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-21 01:50 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Unit tests for loading the trial metadata.""" 

6 

7from datetime import datetime 

8 

9import pytest 

10 

11from mlos_bench.environments.status import Status 

12from mlos_bench.storage.base_experiment_data import ExperimentData 

13 

14 

15def test_exp_trial_data(exp_data: ExperimentData) -> None: 

16 """Check expected return values for TrialData.""" 

17 trial_id = 1 

18 expected_config_id = 1 

19 expected_runner_id = 1 

20 expected_repeat_num = 1 

21 trial = exp_data.trials[trial_id] 

22 assert trial.trial_id == trial_id 

23 assert trial.tunable_config_id == expected_config_id 

24 assert trial.status == Status.SUCCEEDED 

25 assert trial.metadata_dict["repeat_i"] == expected_repeat_num 

26 assert trial.trial_runner_id == expected_runner_id 

27 assert list(trial.results_dict.keys()) == ["score"] 

28 assert trial.results_dict["score"] == pytest.approx(73.27, 0.01) 

29 assert isinstance(trial.ts_start, datetime) 

30 assert isinstance(trial.ts_end, datetime) 

31 # Note: tests for telemetry are in test_update_telemetry()