[8cb6cd6] | 1 | import unittest |
---|
| 2 | |
---|
| 3 | # Tested module |
---|
[83eb5208] | 4 | import sas.qtgui.Plotting.PlotHelper as PlotHelper |
---|
[8cb6cd6] | 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, {}) |
---|
[573c383] | 20 | # could have leftovers from previous tests |
---|
| 21 | #self.assertEqual(PlotHelper._plot_id, 0) |
---|
[8cb6cd6] | 22 | |
---|
| 23 | def testFunctions(self): |
---|
| 24 | """ Adding a plot """ |
---|
| 25 | plot = "I am a plot. Really." |
---|
| 26 | PlotHelper.addPlot(plot) |
---|
| 27 | plot_id = PlotHelper.idOfPlot(plot) |
---|
| 28 | |
---|
| 29 | # We can't guarantee unique values for plot_id, as |
---|
| 30 | # the tests are executed in random order, so just |
---|
| 31 | # make sure we get consecutive values for 2 plots |
---|
| 32 | plot2 = "I am also a plot." |
---|
| 33 | PlotHelper.addPlot(plot2) |
---|
| 34 | plot_id_2 = PlotHelper.idOfPlot(plot2) |
---|
[0268aed] | 35 | id1 = int(plot_id[-1]) |
---|
| 36 | id2 = int(plot_id_2[-1]) |
---|
| 37 | self.assertEqual(id2 - id1, 1) |
---|
[8cb6cd6] | 38 | |
---|
| 39 | # Other properties |
---|
[0268aed] | 40 | #self.assertEqual(PlotHelper.currentPlots(), [plot_id, plot_id_2]) |
---|
| 41 | self.assertTrue(set(PlotHelper.currentPlots()).issubset([plot_id, plot_id_2])) |
---|
[8cb6cd6] | 42 | self.assertEqual(PlotHelper.plotById(plot_id), plot) |
---|
| 43 | self.assertEqual(PlotHelper.plotById(plot_id_2), plot2) |
---|
| 44 | |
---|
| 45 | # Delete a graph |
---|
| 46 | PlotHelper.deletePlot(plot_id) |
---|
| 47 | self.assertEqual(PlotHelper.currentPlots(), [plot_id_2]) |
---|
| 48 | |
---|
| 49 | # Add another graph to see the counter |
---|
| 50 | plot3 = "Just another plot. Move along." |
---|
| 51 | PlotHelper.addPlot(plot3) |
---|
[0268aed] | 52 | #self.assertEqual(PlotHelper.idOfPlot(plot3), plot_id_2 + 1) |
---|
[8cb6cd6] | 53 | |
---|
| 54 | if __name__ == "__main__": |
---|
| 55 | unittest.main() |
---|