blob: 4013c3df1702bf8c8b647354a43072ad92722824 [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 Merino6a5c88d2014-06-19 09:43:18 +01007from test_thermal import TestThermalBase
8import 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
49 ax = plot_utils.pre_plot_setup()
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
57 ax = plot_utils.pre_plot_setup()
58
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 Merino3a736552014-06-19 19:22:44 +010069 def test_post_plot_setup(self):
70 """Test that post_plot_setup() doesn't bomb"""
71
72 ax = plot_utils.pre_plot_setup()
73
74 plot_utils.post_plot_setup(ax)
75 plot_utils.post_plot_setup(ax, title="Foo")
76 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010077 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010078 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +010079 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +010080 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +010081
Javi Merinoed977c12014-06-25 17:46:17 +010082 def test_plot_hist(self):
83 """Test that plost_hist doesn't bomb"""
84 data = pd.Series([1, 1, 2, 4])
85
86 plot_utils.plot_hist(data, "Foo", 20, "numbers", (0, 4), "default")
87
Javi Merino6a5c88d2014-06-19 09:43:18 +010088class TestPlotUtilsNeedTrace(TestThermalBase):
89 def test_plot_allfreqs(self):
90 """Test that plot_allfreqs() doesn't bomb"""
91
92 inp = cr2.InPower()
93 outp = cr2.OutPower()
94 map_label = {"0000000f": "A7", "000000f0": "A15"}
95
96 plot_utils.plot_allfreqs(inp, outp, map_label)
Javi Merino8e8e3212014-06-26 15:24:34 +010097 matplotlib.pyplot.close('all')
Javi Merino63197d72014-06-21 18:11:02 +010098
Javi Merino2919e8d2014-06-26 15:16:05 +010099 def test_plot_temperature(self):
100 """Test that plot_utils.plot_temperature() doesn't bomb"""
101
102 thrm = cr2.Thermal()
103 gov = cr2.ThermalGovernor()
104
105 plot_utils.plot_temperature(thrm, gov, title="Foo")
Javi Merino8e8e3212014-06-26 15:24:34 +0100106 matplotlib.pyplot.close('all')
Javi Merino2919e8d2014-06-26 15:16:05 +0100107
Javi Merino63197d72014-06-21 18:11:02 +0100108 def test_plot_power_hists(self):
109 """Test that plot_power_hists() doesn't bomb"""
110
111 inp = cr2.InPower()
112 outp = cr2.OutPower()
113 map_label = {"0000000f": "A7", "000000f0": "A15"}
114
115 plot_utils.plot_power_hists(inp, outp, map_label)
Javi Merino8e8e3212014-06-26 15:24:34 +0100116 matplotlib.pyplot.close('all')
Javi Merino7d6bbd32014-06-25 18:00:31 +0100117
118 def test_plot_temperature_hist(self):
119 """Test that plot_temperature_hist() doesn't bomb"""
120
121 therm = cr2.Thermal()
122
123 plot_utils.plot_temperature_hist(therm, "Foo")
Javi Merino8e8e3212014-06-26 15:24:34 +0100124 matplotlib.pyplot.close('all')