blob: 361477cdee97c370a6887c6566ecda86863b78f5 [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):
10 def test_set_plot_size(self):
11 """Test that plot_utils.set_plot_size() doesn't bomb"""
12 plot_utils.set_plot_size(None, None)
13 plot_utils.set_plot_size(height=9, width=None)
14 plot_utils.set_plot_size(height=None, width=9)
15 plot_utils.set_plot_size(3, 9)
16
17 def test_normalize_title(self):
18 """Test normalize_title"""
19 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
20 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010021
Javi Merinoa1561272014-06-21 17:49:02 +010022 def test_set_lim(self):
23 """Test set_lim()"""
24
25 class GetSet(object):
26 def __init__(self):
27 self.min = 1
28 self.max = 2
29
30 def get(self):
31 return (self.min, self.max)
32
33 def set(self, minimum, maximum):
34 self.min = minimum
35 self.max = maximum
36
37 gs = GetSet()
38
39 plot_utils.set_lim("default", gs.get, gs.set)
40 self.assertEquals(gs.min, 1)
41 self.assertEquals(gs.max, 2)
42
43 plot_utils.set_lim("range", gs.get, gs.set)
44 self.assertEquals(gs.min, 0.9)
45 self.assertEquals(gs.max, 2.1)
46
47 plot_utils.set_lim((0, 100), gs.get, gs.set)
48 self.assertEquals(gs.min, 0)
49 self.assertEquals(gs.max, 100)
50
51 def test_set_ylim(self):
52 """Test that set_ylim() doesn't bomb"""
53
54 ax = plot_utils.pre_plot_setup()
55
56 plot_utils.set_ylim(ax, "default")
57 plot_utils.set_ylim(ax, (0, 5))
58
59 def test_set_xlim(self):
60 """Test that set_xlim() doesn't bomb"""
61
62 ax = plot_utils.pre_plot_setup()
63
64 plot_utils.set_xlim(ax, "default")
65 plot_utils.set_xlim(ax, (0, 5))
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)