blob: 31b70941fec1a65309660fb20ddb52908e2d6e74 [file] [log] [blame]
Javi Merino7f3c8a62014-06-13 11:38:58 +01001#!/usr/bin/python
2
3import unittest
4
Javi Merino6a5c88d2014-06-19 09:43:18 +01005from test_thermal import TestThermalBase
6import cr2
Javi Merino7f3c8a62014-06-13 11:38:58 +01007import plot_utils
8
9class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010010 def test_normalize_title(self):
11 """Test normalize_title"""
12 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
13 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010014
Javi Merinoa1561272014-06-21 17:49:02 +010015 def test_set_lim(self):
16 """Test set_lim()"""
17
18 class GetSet(object):
19 def __init__(self):
20 self.min = 1
21 self.max = 2
22
23 def get(self):
24 return (self.min, self.max)
25
26 def set(self, minimum, maximum):
27 self.min = minimum
28 self.max = maximum
29
30 gs = GetSet()
31
32 plot_utils.set_lim("default", gs.get, gs.set)
33 self.assertEquals(gs.min, 1)
34 self.assertEquals(gs.max, 2)
35
36 plot_utils.set_lim("range", gs.get, gs.set)
37 self.assertEquals(gs.min, 0.9)
38 self.assertEquals(gs.max, 2.1)
39
40 plot_utils.set_lim((0, 100), gs.get, gs.set)
41 self.assertEquals(gs.min, 0)
42 self.assertEquals(gs.max, 100)
43
44 def test_set_ylim(self):
45 """Test that set_ylim() doesn't bomb"""
46
47 ax = plot_utils.pre_plot_setup()
48
49 plot_utils.set_ylim(ax, "default")
50 plot_utils.set_ylim(ax, (0, 5))
51
52 def test_set_xlim(self):
53 """Test that set_xlim() doesn't bomb"""
54
55 ax = plot_utils.pre_plot_setup()
56
57 plot_utils.set_xlim(ax, "default")
58 plot_utils.set_xlim(ax, (0, 5))
59
Javi Merinof9ac5782014-06-21 19:02:50 +010060 def test_pre_plot_setup(self):
61 """Test that plot_utils.pre_plot_setup() doesn't bomb"""
62 plot_utils.pre_plot_setup(None, None)
63 plot_utils.pre_plot_setup(height=9, width=None)
64 plot_utils.pre_plot_setup(height=None, width=9)
65 plot_utils.pre_plot_setup(3, 9)
66
Javi Merino3a736552014-06-19 19:22:44 +010067 def test_post_plot_setup(self):
68 """Test that post_plot_setup() doesn't bomb"""
69
70 ax = plot_utils.pre_plot_setup()
71
72 plot_utils.post_plot_setup(ax)
73 plot_utils.post_plot_setup(ax, title="Foo")
74 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010075 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010076 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +010077 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +010078 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +010079
80class TestPlotUtilsNeedTrace(TestThermalBase):
81 def test_plot_allfreqs(self):
82 """Test that plot_allfreqs() doesn't bomb"""
83
84 inp = cr2.InPower()
85 outp = cr2.OutPower()
86 map_label = {"0000000f": "A7", "000000f0": "A15"}
87
88 plot_utils.plot_allfreqs(inp, outp, map_label)
Javi Merino63197d72014-06-21 18:11:02 +010089
90 def test_plot_power_hists(self):
91 """Test that plot_power_hists() doesn't bomb"""
92
93 inp = cr2.InPower()
94 outp = cr2.OutPower()
95 map_label = {"0000000f": "A7", "000000f0": "A15"}
96
97 plot_utils.plot_power_hists(inp, outp, map_label)