Back to index

python-biopython  1.60
test_GraphicsGeneral.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Copyright 2001 by Brad Chapman.  All rights reserved.
00003 # This code is part of the Biopython distribution and governed by its
00004 # license.  Please see the LICENSE file that should have been included
00005 # as part of this package.
00006 """Test for graphics things that don't really deserve there own test module.
00007 
00008 XXX Right now this test occasionally fails with a trace like:
00009 
00010 File "/usr/local/lib/python2.1/site-packages/reportlab/graphics/
00011 charts/lineplots.py", line 182, in calcPositions
00012     datum = self.data[rowNo][colNo] # x,y value
00013 IndexError: list index out of range
00014 
00015 This appears to be a problem with reportlab, so I'm not worrying about
00016 it right now, unless it starts to happen with real data! If anyone
00017 can figure out the data that causes it so I can avoid it, that'd be much
00018 appreciated.
00019 """
00020 # standard library
00021 import os
00022 import random
00023 import unittest
00024 
00025 from Bio import MissingExternalDependencyError
00026 try:
00027     # Skip the test if reportlab is not installed
00028     import reportlab as r
00029     del r
00030 except:
00031     raise MissingExternalDependencyError(\
00032         "Install reportlab if you want to use Bio.Graphics.")
00033 
00034 # the stuff we're testing
00035 from Bio.Graphics.Comparative import ComparativeScatterPlot
00036 
00037 
00038 class ComparativeTest(unittest.TestCase):
00039     """Do tests for modules involved with comparing data.
00040     """
00041     def setUp(self):
00042         self.min_two_d_lists = 1
00043         self.max_two_d_lists = 7
00044 
00045         self.min_num_points = 1
00046         self.max_num_points = 500
00047 
00048         self.min_point_num = 0
00049         self.max_point_num = 200
00050 
00051     def _make_random_points(self):
00052         """Make a bunch of random points for testing plots.
00053         """
00054         plot_info = []
00055         num_two_d_lists = random.randrange(self.min_two_d_lists,
00056                                            self.max_two_d_lists)
00057 
00058         for two_d_list in range(num_two_d_lists):
00059             cur_list = []
00060             num_points = random.randrange(self.min_num_points,
00061                                           self.max_num_points)
00062             for point in range(num_points):
00063                 x_point = random.randrange(self.min_point_num,
00064                                            self.max_point_num)
00065                 y_point = random.randrange(self.min_point_num,
00066                                            self.max_point_num)
00067 
00068                 cur_list.append((x_point, y_point))
00069 
00070             plot_info.append(cur_list)
00071         return plot_info
00072                 
00073     def test_simple_scatter_plot(self):
00074         """Test creation of a simple ScatterPlot.
00075         """
00076         compare_plot = ComparativeScatterPlot()
00077         compare_plot.display_info = self._make_random_points()
00078 
00079         output_file = os.path.join(os.getcwd(), "Graphics", "scatter_test.pdf")
00080         try:
00081             compare_plot.draw_to_file(output_file, "Testing Scatter Plots")
00082         # there is a bug in reportlab which occasionally generates an
00083         # error here.
00084         except IndexError:
00085             pass
00086 
00087 if __name__ == "__main__":
00088     runner = unittest.TextTestRunner(verbosity = 2)
00089     unittest.main(testRunner=runner)