Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 120 lines (87 sloc) 4.728 kB
fbd115f @peterjc =Standardising shebang lines, see bug 2269
peterjc authored
1 #!/usr/bin/env python
2 # This code is part of the Biopython distribution and governed by its
3 # license. Please see the LICENSE file that should have been included
4 # as part of this package.
3a5d550 Adding Bio.Wise to the distribution
grouse authored
5
536cc0e @cbrueffer Avoid multiple imports on one line.
cbrueffer authored
6 import doctest
7 import unittest
3a5d550 Adding Bio.Wise to the distribution
grouse authored
8 import random
9 import sys
10
07a43ad @peterjc Fixed a few more examples of 'd.has_key(k)' to use 'k in d' instead.
peterjc authored
11 if 'requires_wise' in sys.modules:
7b6f966 Updates to tests to make them both Python 2.2 compatible and fix some…
chapmanb authored
12 del sys.modules['requires_wise']
3a5d550 Adding Bio.Wise to the distribution
grouse authored
13 import requires_wise
14
15 from Bio.Wise import psw
16
fd82a0a @cbrueffer Add blank lines where needed (PEP8 E302).
cbrueffer authored
17
3a5d550 Adding Bio.Wise to the distribution
grouse authored
18 class TestPSW(unittest.TestCase):
19 def test_Alignment_normal(self):
20 a = psw.Alignment()
21
22 a.append(psw.ColumnUnit(0, 98, "SEQUENCE"))
23 a.append(psw.ColumnUnit(1, 200, "SEQUENCE"))
24 a.append(psw.ColumnUnit(0, 98, "INSERT"))
25 a.append(psw.ColumnUnit(1, 201, "SEQUENCE"))
26 a.append(psw.ColumnUnit(0, 98, "END"))
27 a.append(psw.ColumnUnit(1, 201, "END"))
28
29 self.assertEqual(str(a), "[SEQUENCE(98, 200), INSERT(98, 201), END(98, 201)]")
30
31 def test_Alignment_assertions(self):
32 a = psw.Alignment()
33
34 self.assertRaises(AssertionError, a.append, psw.ColumnUnit(1, 200, "SEQUENCE"))
35 a.append(psw.ColumnUnit(0, 98, "SEQUENCE"))
36 self.assertRaises(AssertionError, a.append, psw.ColumnUnit(0, 200, "SEQUENCE"))
37 a.append(psw.ColumnUnit(1, 200, "SEQUENCE"))
38 self.assertRaises(AssertionError, a.append, psw.ColumnUnit(1, 200, "SEQUENCE"))
39
40 def test_AlignmentColumn_kinds(self):
41 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
42 ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "INSERT"))
43 self.assertEqual(ac.kind, "INSERT")
44
45 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "INSERT"))
46 ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
47 self.assertEqual(ac.kind, "INSERT")
48
49 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
50 ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
51 self.assertEqual(ac.kind, "SEQUENCE")
52
53 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
54 ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "END"))
55 self.assertEqual(ac.kind, "END")
56
57 def test_AlignmentColumn_repr(self):
58 ac = psw.AlignmentColumn(psw.ColumnUnit(0, 34, "SEQUENCE"))
59 ac.append(psw.ColumnUnit(1, 55, "END"))
60 self.assertEqual(repr(ac), "END(34, 55)")
61
62 def test_AlignmentColumn_full(self):
63 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
64 ac.append(psw.ColumnUnit(1, random.randint(0, 9999), "END"))
65 self.assertRaises(psw.AlignmentColumnFullException, ac.append, psw.ColumnUnit(1, random.randint(0, 9999), "END"))
66
67 def test_AlignmentColumn_assertions(self):
68 self.assertRaises(AssertionError, psw.AlignmentColumn, psw.ColumnUnit(1, random.randint(0, 9999), "SEQUENCE"))
69
70 ac = psw.AlignmentColumn(psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
71 self.assertRaises(AssertionError, ac.append, psw.ColumnUnit(0, random.randint(0, 9999), "SEQUENCE"))
72
73 def test_ColumnUnit(self):
74 self.assertEqual(repr(psw.ColumnUnit(0, 33, "SEQUENCE")),
75 "ColumnUnit(unit=0, column=33, SEQUENCE)")
76
77 self.assertEqual(repr(psw.ColumnUnit(1, 33, "INSERT")),
78 "ColumnUnit(unit=1, column=33, INSERT)")
79
80 self.assertEqual(repr(psw.ColumnUnit(1, 33, "END")),
81 "ColumnUnit(unit=1, column=33, END)")
82
83 PARSED = "[SEQUENCE(39, 22), SEQUENCE(40, 23), SEQUENCE(41, 24), SEQUENCE(42, 25), SEQUENCE(43, 26), SEQUENCE(44, 27), END(0, 27)]"
84
85 # def test_align(self):
86 # 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)
87
fd82a0a @cbrueffer Add blank lines where needed (PEP8 E302).
cbrueffer authored
88
3a5d550 Adding Bio.Wise to the distribution
grouse authored
89 def run_tests(argv):
90 test_suite = testing_suite()
b67cebf @peterjc Fix common PEP8 violation in unittest verbosity argument
peterjc authored
91 runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
3a5d550 Adding Bio.Wise to the distribution
grouse authored
92 runner.run(test_suite)
93
fd82a0a @cbrueffer Add blank lines where needed (PEP8 E302).
cbrueffer authored
94
3a5d550 Adding Bio.Wise to the distribution
grouse authored
95 def testing_suite():
96 """Generate the suite of tests.
97 """
98 unittest_suite = unittest.TestSuite()
99
100 test_loader = unittest.TestLoader()
101 test_loader.testMethodPrefix = 'test_'
102 tests = [TestPSW]
b1c8597 @cbrueffer Trim EOL whitespace (PEP8 W291, W293), batch 3.
cbrueffer authored
103
3a5d550 Adding Bio.Wise to the distribution
grouse authored
104 for test in tests:
105 cur_suite = test_loader.loadTestsFromTestCase(test)
106 unittest_suite.addTest(cur_suite)
107
108 doctest_suite = doctest.DocTestSuite(psw)
109
110 big_suite = unittest.TestSuite((unittest_suite, doctest_suite))
111
112 return big_suite
113
114 if __name__ == "__main__":
f7bc466 Simplifying these tests.
mdehoon authored
115 unittest_suite = unittest.TestLoader().loadTestsFromName("test_psw")
116 doctest_suite = doctest.DocTestSuite(psw)
117 suite = unittest.TestSuite((unittest_suite, doctest_suite))
b67cebf @peterjc Fix common PEP8 violation in unittest verbosity argument
peterjc authored
118 runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
f7bc466 Simplifying these tests.
mdehoon authored
119 runner.run(suite)
Something went wrong with that request. Please try again.