blob: dc60e149239f3082ce31bd659f9045b40db68e5b [file] [log] [blame]
Javi Merino7f3c8a62014-06-13 11:38:58 +01001#!/usr/bin/python
2
Javi Merinoed977c12014-06-25 17:46:17 +01003import pandas as pd
Javi Merino7f3c8a62014-06-13 11:38:58 +01004import unittest
5
Javi Merino6a5c88d2014-06-19 09:43:18 +01006from test_thermal import TestThermalBase
7import cr2
Javi Merino7f3c8a62014-06-13 11:38:58 +01008import plot_utils
9
10class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010011 def test_normalize_title(self):
12 """Test normalize_title"""
13 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
14 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010015
Javi Merinoa1561272014-06-21 17:49:02 +010016 def test_set_lim(self):
17 """Test set_lim()"""
18
19 class GetSet(object):
20 def __init__(self):
21 self.min = 1
22 self.max = 2
23
24 def get(self):
25 return (self.min, self.max)
26
27 def set(self, minimum, maximum):
28 self.min = minimum
29 self.max = maximum
30
31 gs = GetSet()
32
33 plot_utils.set_lim("default", gs.get, gs.set)
34 self.assertEquals(gs.min, 1)
35 self.assertEquals(gs.max, 2)
36
37 plot_utils.set_lim("range", gs.get, gs.set)
38 self.assertEquals(gs.min, 0.9)
39 self.assertEquals(gs.max, 2.1)
40
41 plot_utils.set_lim((0, 100), gs.get, gs.set)
42 self.assertEquals(gs.min, 0)
43 self.assertEquals(gs.max, 100)
44
45 def test_set_ylim(self):
46 """Test that set_ylim() doesn't bomb"""
47
48 ax = plot_utils.pre_plot_setup()
49
50 plot_utils.set_ylim(ax, "default")
51 plot_utils.set_ylim(ax, (0, 5))
52
53 def test_set_xlim(self):
54 """Test that set_xlim() doesn't bomb"""
55
56 ax = plot_utils.pre_plot_setup()
57
58 plot_utils.set_xlim(ax, "default")
59 plot_utils.set_xlim(ax, (0, 5))
60
Javi Merinof9ac5782014-06-21 19:02:50 +010061 def test_pre_plot_setup(self):
62 """Test that plot_utils.pre_plot_setup() doesn't bomb"""
63 plot_utils.pre_plot_setup(None, None)
64 plot_utils.pre_plot_setup(height=9, width=None)
65 plot_utils.pre_plot_setup(height=None, width=9)
66 plot_utils.pre_plot_setup(3, 9)
67
Javi Merino3a736552014-06-19 19:22:44 +010068 def test_post_plot_setup(self):
69 """Test that post_plot_setup() doesn't bomb"""
70
71 ax = plot_utils.pre_plot_setup()
72
73 plot_utils.post_plot_setup(ax)
74 plot_utils.post_plot_setup(ax, title="Foo")
75 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010076 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010077 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +010078 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +010079 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +010080
Javi Merinoed977c12014-06-25 17:46:17 +010081 def test_plot_hist(self):
82 """Test that plost_hist doesn't bomb"""
83 data = pd.Series([1, 1, 2, 4])
84
85 plot_utils.plot_hist(data, "Foo", 20, "numbers", (0, 4), "default")
86
Javi Merino6a5c88d2014-06-19 09:43:18 +010087class TestPlotUtilsNeedTrace(TestThermalBase):
88 def test_plot_allfreqs(self):
89 """Test that plot_allfreqs() doesn't bomb"""
90
91 inp = cr2.InPower()
92 outp = cr2.OutPower()
93 map_label = {"0000000f": "A7", "000000f0": "A15"}
94
95 plot_utils.plot_allfreqs(inp, outp, map_label)
Javi Merino63197d72014-06-21 18:11:02 +010096
Javi Merino2919e8d2014-06-26 15:16:05 +010097 def test_plot_temperature(self):
98 """Test that plot_utils.plot_temperature() doesn't bomb"""
99
100 thrm = cr2.Thermal()
101 gov = cr2.ThermalGovernor()
102
103 plot_utils.plot_temperature(thrm, gov, title="Foo")
104
Javi Merino63197d72014-06-21 18:11:02 +0100105 def test_plot_power_hists(self):
106 """Test that plot_power_hists() doesn't bomb"""
107
108 inp = cr2.InPower()
109 outp = cr2.OutPower()
110 map_label = {"0000000f": "A7", "000000f0": "A15"}
111
112 plot_utils.plot_power_hists(inp, outp, map_label)
Javi Merino7d6bbd32014-06-25 18:00:31 +0100113
114 def test_plot_temperature_hist(self):
115 """Test that plot_temperature_hist() doesn't bomb"""
116
117 therm = cr2.Thermal()
118
119 plot_utils.plot_temperature_hist(therm, "Foo")