33import os
44import python_codon_tables as pct
55
6+
67def test_basics ():
78
89 # LOAD ONE TABLE BY NAME
910 table = pct .get_codons_table ("b_subtilis_1423" )
10- assert table ['T' ][ ' ACA' ] == 0.4
11- assert table ['*' ][ ' TAA' ] == 0.61
11+ assert table ["T" ][ " ACA" ] == 0.4
12+ assert table ["*" ][ " TAA" ] == 0.61
1213
1314 # LOAD ALL TABLES AT ONCE
1415 codon_tables = pct .get_all_available_codons_tables ()
15- assert codon_tables ['c_elegans_6239' ]['L' ]['CTA' ] == 0.09
16+ assert codon_tables ["c_elegans_6239" ]["L" ]["CTA" ] == 0.09
17+
1618
1719def test_download_codon_table (tmpdir ):
1820 table = pct .download_codons_table (taxid = 316407 )
19- assert table ['*' ][ ' UAG' ] == 0.07
20- target = os .path .join (str (tmpdir ), ' test.csv' )
21+ assert table ["*" ][ " UAG" ] == 0.07
22+ target = os .path .join (str (tmpdir ), " test.csv" )
2123 table = pct .download_codons_table (taxid = 316407 , target_file = target )
2224
25+
2326def test_readme_example ():
2427 table = pct .get_codons_table ("b_subtilis_1423" )
25- assert table ['T' ][ ' ACA' ] == 0.4
26- assert table ['*' ][ ' TAA' ] == 0.61
28+ assert table ["T" ][ " ACA" ] == 0.4
29+ assert table ["*" ][ " TAA" ] == 0.61
2730
2831 # LOAD ALL TABLES AT ONCE
2932 codons_tables = pct .get_all_available_codons_tables ()
30- assert codons_tables [' c_elegans_6239' ][ 'L' ][ ' CTA' ] == 0.09
33+ assert codons_tables [" c_elegans_6239" ][ "L" ][ " CTA" ] == 0.09
3134
3235 # GET A TABLE DIRECTLY FROM THE INTERNET
3336 table = pct .download_codons_table (taxid = 316407 )
34- assert table ['*' ]['TGA' ] == 0.29
37+ assert table ["*" ]["TGA" ] == 0.29
38+
39+ with pytest .raises (RuntimeError ):
40+ table = pct .download_codons_table (taxid = 000000000 ) # does not exist
41+
3542
3643def test_readme_example ():
3744 table = pct .get_codons_table ("b_subtilis_1423" )
38- assert table ['T' ][ ' ACA' ] == 0.4
39- assert table ['*' ][ ' TAA' ] == 0.61
45+ assert table ["T" ][ " ACA" ] == 0.4
46+ assert table ["*" ][ " TAA" ] == 0.61
4047
4148 # LOAD ALL TABLES AT ONCE
4249 codons_tables = pct .get_all_available_codons_tables ()
43- assert codons_tables [' c_elegans_6239' ][ 'L' ][ ' CTA' ] == 0.09
50+ assert codons_tables [" c_elegans_6239" ][ "L" ][ " CTA" ] == 0.09
4451
4552 # GET A TABLE DIRECTLY FROM THE INTERNET
4653 table = pct .download_codons_table (taxid = 316407 )
47- assert table ['*' ]['UGA' ] == 0.29
54+ assert table ["*" ]["UGA" ] == 0.29
55+
4856
4957def test_get_codons_table ():
5058 for table_name in (1423 , "1423" , "b_subtilis" , "b_subtilis_1423" ):
5159 table = pct .get_codons_table (table_name )
52- assert table ['T' ]['ACA' ] == 0.4
53- assert table ['*' ]['TAA' ] == 0.61
60+ assert table ["T" ]["ACA" ] == 0.4
61+ assert table ["*" ]["TAA" ] == 0.61
62+
5463
5564def test_replace_U_by_T ():
5665 table = pct .get_codons_table ("b_subtilis_1423" , replace_U_by_T = False )
57- assert table ['*' ]['UAA' ] == 0.61
66+ assert table ["*" ]["UAA" ] == 0.61
67+
0 commit comments