|
1 |
| -from unittest.mock import Mock |
| 1 | +from unittest.mock import ANY, Mock |
2 | 2 |
|
3 | 3 | import pandas as pd
|
4 | 4 | import pytest
|
5 | 5 | from matplotlib.figure import Figure
|
6 | 6 |
|
| 7 | +import ert |
7 | 8 | from ert.gui.tools.plot.plot_api import EnsembleObject
|
8 | 9 | from ert.gui.tools.plot.plottery import PlotConfig, PlotContext
|
9 | 10 | from ert.gui.tools.plot.plottery.plots import HistogramPlot
|
@@ -70,3 +71,42 @@ def test_histogram(plot_context: PlotContext, ensemble_to_data_map):
|
70 | 71 | {},
|
71 | 72 | )
|
72 | 73 | return figure
|
| 74 | + |
| 75 | + |
| 76 | +def test_histogram_plot_for_constant_distribution(monkeypatch): |
| 77 | + # test that the histogram plot is called with the correct min and max values |
| 78 | + # when all the parameter values are the same |
| 79 | + context = Mock(spec=PlotContext) |
| 80 | + context.log_scale = False |
| 81 | + context.ensembles.return_value = [ |
| 82 | + EnsembleObject("ensemble_1", "id", False, "experiment_1") |
| 83 | + ] |
| 84 | + title = "Histogram with same values" |
| 85 | + context.plotConfig.return_value = PlotConfig(title=title) |
| 86 | + value = 0 |
| 87 | + data_map = dict.fromkeys(context.ensembles(), pd.DataFrame([10 * [value]])) |
| 88 | + min_value = value - 0.1 |
| 89 | + max_value = value + 0.1 |
| 90 | + figure = Figure() |
| 91 | + mock_plot_histogram = Mock() |
| 92 | + monkeypatch.setattr( |
| 93 | + ert.gui.tools.plot.plottery.plots.histogram, |
| 94 | + "_plotHistogram", |
| 95 | + mock_plot_histogram, |
| 96 | + ) |
| 97 | + HistogramPlot().plot( |
| 98 | + figure, |
| 99 | + context, |
| 100 | + data_map, |
| 101 | + pd.DataFrame(), |
| 102 | + {}, |
| 103 | + ) |
| 104 | + mock_plot_histogram.assert_called_once_with( |
| 105 | + ANY, |
| 106 | + ANY, |
| 107 | + ANY, |
| 108 | + ANY, |
| 109 | + ANY, |
| 110 | + min_value, |
| 111 | + max_value, |
| 112 | + ) |
0 commit comments