Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import unittest |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 4 | import matplotlib |
| 5 | import pandas as pd |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 6 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 7 | from test_thermal import BaseTestThermal |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 8 | import cr2 |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 9 | import plot_utils |
| 10 | |
| 11 | class TestPlotUtils(unittest.TestCase): |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 12 | def test_normalize_title(self): |
| 13 | """Test normalize_title""" |
| 14 | self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo") |
| 15 | self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo") |
Javi Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 16 | |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 17 | def test_set_lim(self): |
| 18 | """Test set_lim()""" |
| 19 | |
| 20 | class GetSet(object): |
| 21 | def __init__(self): |
| 22 | self.min = 1 |
| 23 | self.max = 2 |
| 24 | |
| 25 | def get(self): |
| 26 | return (self.min, self.max) |
| 27 | |
| 28 | def set(self, minimum, maximum): |
| 29 | self.min = minimum |
| 30 | self.max = maximum |
| 31 | |
| 32 | gs = GetSet() |
| 33 | |
| 34 | plot_utils.set_lim("default", gs.get, gs.set) |
| 35 | self.assertEquals(gs.min, 1) |
| 36 | self.assertEquals(gs.max, 2) |
| 37 | |
| 38 | plot_utils.set_lim("range", gs.get, gs.set) |
| 39 | self.assertEquals(gs.min, 0.9) |
| 40 | self.assertEquals(gs.max, 2.1) |
| 41 | |
| 42 | plot_utils.set_lim((0, 100), gs.get, gs.set) |
| 43 | self.assertEquals(gs.min, 0) |
| 44 | self.assertEquals(gs.max, 100) |
| 45 | |
| 46 | def test_set_ylim(self): |
| 47 | """Test that set_ylim() doesn't bomb""" |
| 48 | |
Javi Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 49 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 50 | |
| 51 | plot_utils.set_ylim(ax, "default") |
| 52 | plot_utils.set_ylim(ax, (0, 5)) |
| 53 | |
| 54 | def test_set_xlim(self): |
| 55 | """Test that set_xlim() doesn't bomb""" |
| 56 | |
Javi Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 57 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 58 | |
| 59 | plot_utils.set_xlim(ax, "default") |
| 60 | plot_utils.set_xlim(ax, (0, 5)) |
| 61 | |
Javi Merino | f9ac578 | 2014-06-21 19:02:50 +0100 | [diff] [blame] | 62 | def test_pre_plot_setup(self): |
| 63 | """Test that plot_utils.pre_plot_setup() doesn't bomb""" |
| 64 | plot_utils.pre_plot_setup(None, None) |
| 65 | plot_utils.pre_plot_setup(height=9, width=None) |
| 66 | plot_utils.pre_plot_setup(height=None, width=9) |
| 67 | plot_utils.pre_plot_setup(3, 9) |
| 68 | |
Javi Merino | 7f88ae3 | 2014-08-11 16:53:35 +0100 | [diff] [blame] | 69 | axis = plot_utils.pre_plot_setup(ncols=2) |
| 70 | self.assertEquals(len(axis), 2) |
| 71 | |
Javi Merino | 270caac | 2014-08-12 10:41:38 +0100 | [diff] [blame] | 72 | axis = plot_utils.pre_plot_setup(nrows=2, ncols=3) |
| 73 | self.assertEquals(len(axis), 2) |
| 74 | self.assertEquals(len(axis[0]), 3) |
| 75 | self.assertEquals(len(axis[1]), 3) |
| 76 | |
Javi Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 77 | def test_post_plot_setup(self): |
| 78 | """Test that post_plot_setup() doesn't bomb""" |
| 79 | |
Javi Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 80 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 81 | |
| 82 | plot_utils.post_plot_setup(ax) |
| 83 | plot_utils.post_plot_setup(ax, title="Foo") |
| 84 | plot_utils.post_plot_setup(ax, ylim=(0, 72)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 85 | plot_utils.post_plot_setup(ax, ylim="range") |
Javi Merino | f9d43af | 2014-06-21 16:32:04 +0100 | [diff] [blame] | 86 | plot_utils.post_plot_setup(ax, xlabel="Bar") |
Javi Merino | d04643f | 2014-06-21 17:00:16 +0100 | [diff] [blame] | 87 | plot_utils.post_plot_setup(ax, xlim=(0, 100)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 88 | plot_utils.post_plot_setup(ax, xlim="default") |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 89 | |
Javi Merino | ed977c1 | 2014-06-25 17:46:17 +0100 | [diff] [blame] | 90 | def test_plot_hist(self): |
| 91 | """Test that plost_hist doesn't bomb""" |
| 92 | data = pd.Series([1, 1, 2, 4]) |
| 93 | |
Javi Merino | e5ea60a | 2014-08-12 16:41:42 +0100 | [diff] [blame] | 94 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | 23dff5d | 2015-03-09 19:05:46 +0000 | [diff] [blame] | 95 | plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default") |
Javi Merino | ed977c1 | 2014-06-25 17:46:17 +0100 | [diff] [blame] | 96 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 97 | class TestPlotUtilsNeedTrace(BaseTestThermal): |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 98 | def __init__(self, *args, **kwargs): |
| 99 | super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs) |
| 100 | self.map_label = {"0000000f": "A7", "000000f0": "A15"} |
Javi Merino | f5cd04b | 2014-08-12 15:26:22 +0100 | [diff] [blame] | 101 | self.actor_order = ["GPU", "A15", "A7"] |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 102 | |
Javi Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 103 | def test_plot_temperature(self): |
| 104 | """Test that plot_utils.plot_temperature() doesn't bomb""" |
| 105 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame] | 106 | run1 = cr2.Run(name="first") |
| 107 | run2 = cr2.Run(name="second") |
| 108 | runs = [run1, run2] |
Javi Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 109 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame] | 110 | plot_utils.plot_temperature(runs, ylim="default") |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 111 | matplotlib.pyplot.close('all') |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 112 | |
| 113 | def test_plot_load(self): |
| 114 | """Test that plot_utils.plot_load() doesn't bomb""" |
| 115 | |
| 116 | run1 = cr2.Run(name="first") |
| 117 | run2 = cr2.Run(name="second") |
| 118 | runs = [run1, run2] |
| 119 | |
| 120 | plot_utils.plot_load(runs, self.map_label, height=5) |
| 121 | matplotlib.pyplot.close('all') |
Javi Merino | af05f31 | 2014-08-11 17:47:59 +0100 | [diff] [blame] | 122 | |
| 123 | def test_plot_load_single_run(self): |
| 124 | """plot_utils.plot_load() can be used with a single run""" |
| 125 | run = cr2.Run() |
| 126 | |
| 127 | plot_utils.plot_load([run], self.map_label) |
| 128 | matplotlib.pyplot.close('all') |
Javi Merino | 0c48426 | 2014-08-12 11:55:04 +0100 | [diff] [blame] | 129 | |
| 130 | def test_plot_allfreqs(self): |
| 131 | """Test that plot_utils.plot_allfreqs() doesn't bomb""" |
| 132 | |
| 133 | run1 = cr2.Run(name="first") |
| 134 | run2 = cr2.Run(name="second") |
| 135 | runs = [run1, run2] |
| 136 | |
| 137 | plot_utils.plot_allfreqs(runs, self.map_label, width=20) |
| 138 | matplotlib.pyplot.close('all') |
| 139 | |
Javi Merino | 114c9cb | 2014-08-12 14:47:09 +0100 | [diff] [blame] | 140 | def test_plot_allfreqs_single_run(self): |
| 141 | """plot_utils.plot_allfreqs() can be used with a single run""" |
| 142 | run = cr2.Run() |
| 143 | |
| 144 | plot_utils.plot_allfreqs([run], self.map_label) |
Javi Merino | 0c48426 | 2014-08-12 11:55:04 +0100 | [diff] [blame] | 145 | matplotlib.pyplot.close('all') |
Javi Merino | 38fd12d | 2014-08-12 15:02:47 +0100 | [diff] [blame] | 146 | |
| 147 | def test_plot_controller(self): |
| 148 | """plot_utils.plot_controller() doesn't bomb""" |
| 149 | |
| 150 | run1 = cr2.Run(name="first") |
| 151 | run2 = cr2.Run(name="second") |
| 152 | runs = [run1, run2] |
| 153 | |
| 154 | plot_utils.plot_controller(runs, height=5) |
| 155 | matplotlib.pyplot.close('all') |
Javi Merino | f5cd04b | 2014-08-12 15:26:22 +0100 | [diff] [blame] | 156 | |
| 157 | def test_plot_input_power(self): |
| 158 | """plot_utils.plot_input_power() doesn't bomb""" |
| 159 | |
| 160 | run1 = cr2.Run(name="first") |
| 161 | run2 = cr2.Run(name="second") |
| 162 | runs = [run1, run2] |
| 163 | |
| 164 | plot_utils.plot_input_power(runs, self.actor_order, width=20) |
| 165 | matplotlib.pyplot.close('all') |
Javi Merino | 9fde215 | 2014-08-12 15:34:24 +0100 | [diff] [blame] | 166 | |
| 167 | def test_plot_output_power(self): |
| 168 | """plot_utils.plot_output_power() doesn't bomb""" |
| 169 | |
| 170 | run1 = cr2.Run(name="first") |
| 171 | run2 = cr2.Run(name="second") |
| 172 | runs = [run1, run2] |
| 173 | |
| 174 | plot_utils.plot_output_power(runs, self.actor_order, width=20) |
| 175 | matplotlib.pyplot.close('all') |
Javi Merino | e5ea60a | 2014-08-12 16:41:42 +0100 | [diff] [blame] | 176 | |
| 177 | def test_plot_freq_hists(self): |
| 178 | """plot_utils.plot_freq_hists() doesn't bomb""" |
| 179 | |
| 180 | run1 = cr2.Run(name="first") |
| 181 | run2 = cr2.Run(name="second") |
| 182 | runs = [run1, run2] |
| 183 | |
| 184 | plot_utils.plot_freq_hists(runs, self.map_label) |
| 185 | matplotlib.pyplot.close('all') |
| 186 | |
| 187 | def test_plot_freq_hists_single_run(self): |
| 188 | """plot_utils.plot_freq_hists() works with a single run""" |
| 189 | |
| 190 | run = cr2.Run() |
| 191 | |
| 192 | plot_utils.plot_freq_hists([run], self.map_label) |
| 193 | matplotlib.pyplot.close('all') |
| 194 | |
| 195 | def test_plot_temperature_hist(self): |
| 196 | """plot_utils.plot_temperature_hist() doesn't bomb""" |
| 197 | |
| 198 | run1 = cr2.Run(name="first") |
| 199 | run2 = cr2.Run(name="second") |
| 200 | runs = [run1, run2] |
| 201 | |
| 202 | plot_utils.plot_temperature_hist(runs) |
| 203 | matplotlib.pyplot.close('all') |