Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import unittest |
| 4 | |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 5 | from test_thermal import TestThermalBase |
| 6 | import cr2 |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 7 | import plot_utils |
| 8 | |
| 9 | class 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 21 | |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 22 | 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 67 | 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 Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 75 | plot_utils.post_plot_setup(ax, ylim="range") |
Javi Merino | f9d43af | 2014-06-21 16:32:04 +0100 | [diff] [blame] | 76 | plot_utils.post_plot_setup(ax, xlabel="Bar") |
Javi Merino | d04643f | 2014-06-21 17:00:16 +0100 | [diff] [blame] | 77 | plot_utils.post_plot_setup(ax, xlim=(0, 100)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 78 | plot_utils.post_plot_setup(ax, xlim="default") |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 79 | |
| 80 | class 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 Merino | 63197d7 | 2014-06-21 18:11:02 +0100 | [diff] [blame^] | 89 | |
| 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) |