blob: ef6f470d2f03285d10bd63f4a44660fa588dc0bf [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 Merino3a736552014-06-19 19:22:44 +010072 def test_post_plot_setup(self):
73 """Test that post_plot_setup() doesn't bomb"""
74
Javi Merino5981ee82014-08-11 17:45:38 +010075 _, ax = matplotlib.pyplot.subplots()
Javi Merino3a736552014-06-19 19:22:44 +010076
77 plot_utils.post_plot_setup(ax)
78 plot_utils.post_plot_setup(ax, title="Foo")
79 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010080 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010081 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +010082 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +010083 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +010084
Javi Merinoed977c12014-06-25 17:46:17 +010085 def test_plot_hist(self):
86 """Test that plost_hist doesn't bomb"""
87 data = pd.Series([1, 1, 2, 4])
88
89 plot_utils.plot_hist(data, "Foo", 20, "numbers", (0, 4), "default")
90
Javi Merino076277d2014-07-02 18:48:18 +010091class TestPlotUtilsNeedTrace(BaseTestThermal):
Javi Merino6bf48832014-08-11 17:15:35 +010092 def __init__(self, *args, **kwargs):
93 super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs)
94 self.map_label = {"0000000f": "A7", "000000f0": "A15"}
95
Javi Merino2919e8d2014-06-26 15:16:05 +010096 def test_plot_temperature(self):
97 """Test that plot_utils.plot_temperature() doesn't bomb"""
98
Javi Merino1cc4bfc2014-08-11 16:29:11 +010099 run1 = cr2.Run(name="first")
100 run2 = cr2.Run(name="second")
101 runs = [run1, run2]
Javi Merino2919e8d2014-06-26 15:16:05 +0100102
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100103 plot_utils.plot_temperature(runs, ylim="default")
Javi Merino8e8e3212014-06-26 15:24:34 +0100104 matplotlib.pyplot.close('all')
Javi Merino6bf48832014-08-11 17:15:35 +0100105
106 def test_plot_load(self):
107 """Test that plot_utils.plot_load() doesn't bomb"""
108
109 run1 = cr2.Run(name="first")
110 run2 = cr2.Run(name="second")
111 runs = [run1, run2]
112
113 plot_utils.plot_load(runs, self.map_label, height=5)
114 matplotlib.pyplot.close('all')