added test of len() method for SQLTable
[pygr.git] / tests / translationDB_test.py
blob0aa4c71ffbbb228befaf898064ef475c72781a20
1 import unittest
3 from testlib import testutil, PygrTestProgram
4 from pygr import translationDB, seqdb
6 class TranslationDB_Test(unittest.TestCase):
7 def setUp(self):
8 hbb1_mouse = testutil.datafile('hbb1_mouse.fa')
9 self.dna = seqdb.SequenceFileDB(hbb1_mouse)
10 self.tdb = translationDB.get_translation_db(self.dna)
12 def test_basic_slice(self):
13 id = 'gi|171854975|dbj|AB364477.1|'
14 tseq = self.tdb[id][0:99]
15 assert str(tseq)[0:10] == 'MVHLTDAEKA'
17 tseq = self.tdb[id][1:100]
18 assert str(tseq)[0:10] == 'WCT*LMLRRL'
20 def test_slice_empty_stop(self):
21 id = 'gi|171854975|dbj|AB364477.1|'
22 tseq = self.tdb[id][0:]
23 assert str(tseq)[0:10] == 'MVHLTDAEKA'
25 tseq = self.tdb[id][1:]
26 assert str(tseq)[0:10] == 'WCT*LMLRRL'
28 def test_slice_empty_start(self):
29 id = 'gi|171854975|dbj|AB364477.1|'
30 tseq = self.tdb[id][:99]
31 assert str(tseq)[0:10] == 'MVHLTDAEKA'
33 def test_repr_ne(self):
34 """
35 Make sure there's some way to distinguish translated seqs from
36 regular, visually!
37 """
38 id = 'gi|171854975|dbj|AB364477.1|'
40 seq = self.dna[id]
41 tseq = self.tdb[id]
43 assert repr(seq) != repr(tseq)
45 def test_invalid_annodb_key_str(self):
46 """
47 The invalid key should be mentioned in the KeyError...
48 """
49 try:
50 self.tdb.annodb['fooBar']
51 assert 0, "should not reach this point"
52 except KeyError, e:
53 assert 'fooBar' in str(e)
55 if __name__ == '__main__':
56 PygrTestProgram(verbosity=2)