Coverage for mlos_viz/mlos_viz/tests/test_mlos_viz.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-06 00:35 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6Unit tests for mlos_viz. 

7""" 

8 

9import random 

10import warnings 

11 

12from unittest.mock import patch, Mock 

13 

14from mlos_bench.storage.base_experiment_data import ExperimentData 

15 

16from mlos_viz import MlosVizMethod, plot 

17 

18from mlos_viz.tests import BASE_MATPLOTLIB_SHOW_PATCH, SEABORN_BOXPLOT_PATCH 

19 

20 

21def test_auto_method_type() -> None: 

22 """Ensure the AUTO method is what we expect.""" 

23 assert MlosVizMethod.AUTO.value == MlosVizMethod.DABL.value 

24 

25 

26@patch(BASE_MATPLOTLIB_SHOW_PATCH) 

27@patch(SEABORN_BOXPLOT_PATCH) 

28def test_plot(mock_show: Mock, mock_boxplot: Mock, exp_data: ExperimentData) -> None: 

29 """Tests core plot() API.""" 

30 # For now, just ensure that no errors are thrown. 

31 # TODO: Check that a plot was actually produced matching our specifications. 

32 with warnings.catch_warnings(): 

33 warnings.simplefilter("error") 

34 random.seed(42) 

35 plot(exp_data, filter_warnings=True) 

36 assert mock_show.call_count >= 2 # from the two base plots and anything dabl did 

37 assert mock_boxplot.call_count >= 1 # from anything dabl did