Back to index

python-biopython  1.60
test_psw.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 __version__ = "$Revision: 1.6 $"
00007 
00008 import doctest, unittest
00009 import random
00010 import sys
00011 
00012 if 'requires_wise' in sys.modules:
00013     del sys.modules['requires_wise']
00014 import requires_wise
00015 
00016 from Bio.Wise import psw
00017 
00018 class TestPSW(unittest.TestCase):
00019     def test_Alignment_normal(self):
00020         a = psw.Alignment()
00021 
00022         a.append(psw.ColumnUnit(0, 98, "SEQUENCE"))
00023         a.append(psw.ColumnUnit(1, 200, "SEQUENCE"))
00024         a.append(psw.ColumnUnit(0, 98, "INSERT"))
00025         a.append(psw.ColumnUnit(1, 201, "SEQUENCE"))
00026         a.append(psw.ColumnUnit(0, 98, "END"))
00027         a.append(psw.ColumnUnit(1, 201, "END"))
00028 
00029         self.assertEqual(str(a), "[SEQUENCE(98, 200), INSERT(98, 201), END(98, 201)]")
00030 
00031     def test_Alignment_assertions(self):
00032         a = psw.Alignment()
00033 
00034         self.assertRaises(AssertionError, a.append, psw.ColumnUnit(1, 200, "SEQUENCE"))
00035         a.append(psw.ColumnUnit(0, 98, "SEQUENCE"))
00036         self.assertRaises(AssertionError, a.append, psw.ColumnUnit(0, 200, "SEQUENCE"))
00037         a.append(psw.ColumnUnit(1, 200, "SEQUENCE"))
00038         self.assertRaises(AssertionError, a.append, psw.ColumnUnit(1, 200, "SEQUENCE"))
00039 
00040     def test_AlignmentColumn_kinds(self):
00041         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00042         ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "INSERT"))
00043         self.assertEqual(ac.kind, "INSERT")
00044 
00045         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "INSERT"))
00046         ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
00047         self.assertEqual(ac.kind, "INSERT")
00048 
00049         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00050         ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
00051         self.assertEqual(ac.kind, "SEQUENCE")
00052 
00053         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00054         ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "END"))
00055         self.assertEqual(ac.kind, "END")
00056 
00057     def test_AlignmentColumn_repr(self):
00058         ac = psw.AlignmentColumn(psw.ColumnUnit(0, 34, "SEQUENCE"))
00059         ac.append(psw.ColumnUnit(1, 55, "END"))
00060         self.assertEqual(repr(ac), "END(34, 55)")
00061 
00062     def test_AlignmentColumn_full(self):
00063         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00064         ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "END"))
00065         self.assertRaises(psw.AlignmentColumnFullException, ac.append, psw.ColumnUnit(1, random.randint(0, 9999), "END"))
00066 
00067     def test_AlignmentColumn_assertions(self):
00068         self.assertRaises(AssertionError, psw.AlignmentColumn, psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
00069 
00070         ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00071         self.assertRaises(AssertionError, ac.append, psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
00072 
00073 
00074     def test_ColumnUnit(self):
00075         self.assertEqual(repr(psw.ColumnUnit(0, 33, "SEQUENCE")),
00076                          "ColumnUnit(unit=0, column=33, SEQUENCE)")
00077 
00078         self.assertEqual(repr(psw.ColumnUnit(1, 33, "INSERT")),
00079                          "ColumnUnit(unit=1, column=33, INSERT)")
00080 
00081         self.assertEqual(repr(psw.ColumnUnit(1, 33, "END")),
00082                          "ColumnUnit(unit=1, column=33, END)")
00083 
00084     PARSED = "[SEQUENCE(39, 22), SEQUENCE(40, 23), SEQUENCE(41, 24), SEQUENCE(42, 25), SEQUENCE(43, 26), SEQUENCE(44, 27), END(0, 27)]"
00085 
00086 #    def test_align(self):
00087 #        self.assertEqual(repr(psw.align(("Wise/human_114_g01_exons.fna_01", "Wise/human_114_g02_exons.fna_01"), "introns.bla", 23, 5, quiet=True)), self.PARSED)
00088 
00089 def run_tests(argv):
00090     test_suite = testing_suite()
00091     runner = unittest.TextTestRunner(sys.stdout, verbosity = 2)
00092     runner.run(test_suite)
00093 
00094 def testing_suite():
00095     """Generate the suite of tests.
00096     """
00097     unittest_suite = unittest.TestSuite()
00098 
00099     test_loader = unittest.TestLoader()
00100     test_loader.testMethodPrefix = 'test_'
00101     tests = [TestPSW]
00102     
00103     for test in tests:
00104         cur_suite = test_loader.loadTestsFromTestCase(test)
00105         unittest_suite.addTest(cur_suite)
00106 
00107     doctest_suite = doctest.DocTestSuite(psw)
00108 
00109     big_suite = unittest.TestSuite((unittest_suite, doctest_suite))
00110 
00111     return big_suite
00112 
00113 if __name__ == "__main__":
00114     unittest_suite = unittest.TestLoader().loadTestsFromName("test_psw")
00115     doctest_suite = doctest.DocTestSuite(psw)
00116     suite = unittest.TestSuite((unittest_suite, doctest_suite))
00117     runner = unittest.TextTestRunner(sys.stdout, verbosity = 2)
00118     runner.run(suite)