Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import unittest |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 4 | import matplotlib |
| 5 | import pandas as pd |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 6 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 7 | from test_thermal import BaseTestThermal |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 8 | import cr2 |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 9 | import plot_utils |
| 10 | |
| 11 | class TestPlotUtils(unittest.TestCase): |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 12 | 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 16 | |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 17 | 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 | |
| 49 | ax = plot_utils.pre_plot_setup() |
| 50 | |
| 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 | |
| 57 | ax = plot_utils.pre_plot_setup() |
| 58 | |
| 59 | plot_utils.set_xlim(ax, "default") |
| 60 | plot_utils.set_xlim(ax, (0, 5)) |
| 61 | |
Javi Merino | f9ac578 | 2014-06-21 19:02:50 +0100 | [diff] [blame] | 62 | 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 69 | def test_post_plot_setup(self): |
| 70 | """Test that post_plot_setup() doesn't bomb""" |
| 71 | |
| 72 | ax = plot_utils.pre_plot_setup() |
| 73 | |
| 74 | plot_utils.post_plot_setup(ax) |
| 75 | plot_utils.post_plot_setup(ax, title="Foo") |
| 76 | plot_utils.post_plot_setup(ax, ylim=(0, 72)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 77 | plot_utils.post_plot_setup(ax, ylim="range") |
Javi Merino | f9d43af | 2014-06-21 16:32:04 +0100 | [diff] [blame] | 78 | plot_utils.post_plot_setup(ax, xlabel="Bar") |
Javi Merino | d04643f | 2014-06-21 17:00:16 +0100 | [diff] [blame] | 79 | plot_utils.post_plot_setup(ax, xlim=(0, 100)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 80 | plot_utils.post_plot_setup(ax, xlim="default") |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 81 | |
Javi Merino | ed977c1 | 2014-06-25 17:46:17 +0100 | [diff] [blame] | 82 | def test_plot_hist(self): |
| 83 | """Test that plost_hist doesn't bomb""" |
| 84 | data = pd.Series([1, 1, 2, 4]) |
| 85 | |
| 86 | plot_utils.plot_hist(data, "Foo", 20, "numbers", (0, 4), "default") |
| 87 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 88 | class TestPlotUtilsNeedTrace(BaseTestThermal): |
Javi Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 89 | def test_plot_temperature(self): |
| 90 | """Test that plot_utils.plot_temperature() doesn't bomb""" |
| 91 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame^] | 92 | run1 = cr2.Run(name="first") |
| 93 | run2 = cr2.Run(name="second") |
| 94 | runs = [run1, run2] |
Javi Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 95 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame^] | 96 | plot_utils.plot_temperature(runs, ylim="default") |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 97 | matplotlib.pyplot.close('all') |