1 | import unittest |
---|
2 | |
---|
3 | # Tested module |
---|
4 | import sas.qtgui.Plotting.PlotHelper as PlotHelper |
---|
5 | |
---|
6 | class PlotHelperTest(unittest.TestCase): |
---|
7 | '''Test the Plot helper functions''' |
---|
8 | def setUp(self): |
---|
9 | '''Empty''' |
---|
10 | pass |
---|
11 | |
---|
12 | def tearDown(self): |
---|
13 | '''Empty''' |
---|
14 | pass |
---|
15 | |
---|
16 | def testDefaults(self): |
---|
17 | """ default method variables values """ |
---|
18 | self.assertIsInstance(PlotHelper._plots, dict) |
---|
19 | self.assertEqual(PlotHelper._plots, {}) |
---|
20 | self.assertEqual(PlotHelper._plot_id, 0) |
---|
21 | |
---|
22 | def testFunctions(self): |
---|
23 | """ Adding a plot """ |
---|
24 | plot = "I am a plot. Really." |
---|
25 | PlotHelper.addPlot(plot) |
---|
26 | plot_id = PlotHelper.idOfPlot(plot) |
---|
27 | |
---|
28 | # We can't guarantee unique values for plot_id, as |
---|
29 | # the tests are executed in random order, so just |
---|
30 | # make sure we get consecutive values for 2 plots |
---|
31 | plot2 = "I am also a plot." |
---|
32 | PlotHelper.addPlot(plot2) |
---|
33 | plot_id_2 = PlotHelper.idOfPlot(plot2) |
---|
34 | id1 = int(plot_id[-1]) |
---|
35 | id2 = int(plot_id_2[-1]) |
---|
36 | self.assertEqual(id2 - id1, 1) |
---|
37 | |
---|
38 | # Other properties |
---|
39 | #self.assertEqual(PlotHelper.currentPlots(), [plot_id, plot_id_2]) |
---|
40 | self.assertTrue(set(PlotHelper.currentPlots()).issubset([plot_id, plot_id_2])) |
---|
41 | self.assertEqual(PlotHelper.plotById(plot_id), plot) |
---|
42 | self.assertEqual(PlotHelper.plotById(plot_id_2), plot2) |
---|
43 | |
---|
44 | # Delete a graph |
---|
45 | PlotHelper.deletePlot(plot_id) |
---|
46 | self.assertEqual(PlotHelper.currentPlots(), [plot_id_2]) |
---|
47 | |
---|
48 | # Add another graph to see the counter |
---|
49 | plot3 = "Just another plot. Move along." |
---|
50 | PlotHelper.addPlot(plot3) |
---|
51 | #self.assertEqual(PlotHelper.idOfPlot(plot3), plot_id_2 + 1) |
---|
52 | |
---|
53 | if __name__ == "__main__": |
---|
54 | unittest.main() |
---|