blob: 597cb6d47292cd91d4b2c66ed66b80bcea5e5dc2 [file] [log] [blame]
Javi Merino7f3c8a62014-06-13 11:38:58 +01001#!/usr/bin/python
2
3import unittest
Javi Merino8e8e3212014-06-26 15:24:34 +01004import matplotlib
5import pandas as pd
Javi Merino7f3c8a62014-06-13 11:38:58 +01006
Javi Merino076277d2014-07-02 18:48:18 +01007from test_thermal import BaseTestThermal
Javi Merino6a5c88d2014-06-19 09:43:18 +01008import cr2
Javi Merino7f3c8a62014-06-13 11:38:58 +01009import plot_utils
10
11class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010012 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 Merino3a736552014-06-19 19:22:44 +010016
Javi Merinoa1561272014-06-21 17:49:02 +010017 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 Merino5981ee82014-08-11 17:45:38 +010049 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010050
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 Merino5981ee82014-08-11 17:45:38 +010057 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010058
59 plot_utils.set_xlim(ax, "default")
60 plot_utils.set_xlim(ax, (0, 5))
61
Javi Merinof9ac5782014-06-21 19:02:50 +010062 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 Merino7f88ae32014-08-11 16:53:35 +010069 axis = plot_utils.pre_plot_setup(ncols=2)
70 self.assertEquals(len(axis), 2)
71
Javi Merino270caac2014-08-12 10:41:38 +010072 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 Merino3a736552014-06-19 19:22:44 +010077 def test_post_plot_setup(self):
78 """Test that post_plot_setup() doesn't bomb"""
79
Javi Merino5981ee82014-08-11 17:45:38 +010080 _, ax = matplotlib.pyplot.subplots()
Javi Merino3a736552014-06-19 19:22:44 +010081
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 Merinoa1561272014-06-21 17:49:02 +010085 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010086 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +010087 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +010088 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +010089
Javi Merinoed977c12014-06-25 17:46:17 +010090 def test_plot_hist(self):
91 """Test that plost_hist doesn't bomb"""
92 data = pd.Series([1, 1, 2, 4])
93
Javi Merinoe5ea60a2014-08-12 16:41:42 +010094 _, ax = matplotlib.pyplot.subplots()
Javi Merino23dff5d2015-03-09 19:05:46 +000095 plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default")
Javi Merinoed977c12014-06-25 17:46:17 +010096
Javi Merino076277d2014-07-02 18:48:18 +010097class TestPlotUtilsNeedTrace(BaseTestThermal):
Javi Merino6bf48832014-08-11 17:15:35 +010098 def __init__(self, *args, **kwargs):
99 super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs)
Javi Merinod721b272015-04-20 15:37:53 +0100100 self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
101 self.actor_order = ["GPU", "A57", "A53"]
Javi Merino6bf48832014-08-11 17:15:35 +0100102
Javi Merino2919e8d2014-06-26 15:16:05 +0100103 def test_plot_temperature(self):
104 """Test that plot_utils.plot_temperature() doesn't bomb"""
105
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100106 run1 = cr2.Run(name="first")
107 run2 = cr2.Run(name="second")
108 runs = [run1, run2]
Javi Merino2919e8d2014-06-26 15:16:05 +0100109
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100110 plot_utils.plot_temperature(runs, ylim="default")
Javi Merino8e8e3212014-06-26 15:24:34 +0100111 matplotlib.pyplot.close('all')
Javi Merino6bf48832014-08-11 17:15:35 +0100112
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 Merinoaf05f312014-08-11 17:47:59 +0100122
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 Merino0c484262014-08-12 11:55:04 +0100129
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 Merino114c9cb2014-08-12 14:47:09 +0100140 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 Merino0c484262014-08-12 11:55:04 +0100145 matplotlib.pyplot.close('all')
Javi Merino38fd12d2014-08-12 15:02:47 +0100146
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 Merinof5cd04b2014-08-12 15:26:22 +0100156
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 Merino9fde2152014-08-12 15:34:24 +0100166
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 Merinoe5ea60a2014-08-12 16:41:42 +0100176
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')