0
|
1 __license__ = "MIT"
|
|
2
|
|
3 import unittest
|
|
4 import findKEGG as fk
|
|
5
|
|
6
|
|
7 class SimpleUnitTest(unittest.TestCase):
|
|
8 def setUp(self):
|
|
9 import os
|
|
10
|
|
11 os.environ["http_proxy"] = "" # work around for IOError: [Errno url error] invalid proxy for http:
|
|
12 pass
|
|
13
|
|
14 def tearDown(self):
|
|
15 pass
|
|
16
|
|
17 def test_no_db_specified(self):
|
|
18 """should raise error"""
|
|
19 with self.assertRaises(IOError):
|
|
20 m = fk.find_entries_in_KEGG([], " ")
|
|
21 with self.assertRaises(IOError):
|
|
22 m = fk.find_entries_in_KEGG("", " ")
|
|
23 with self.assertRaises(IOError):
|
|
24 m = fk.find_entries_in_KEGG(None, " ")
|
|
25
|
|
26 def test_no_query_specified(self):
|
|
27 """should raise error"""
|
|
28 with self.assertRaises(IOError):
|
|
29 m = fk.find_entries_in_KEGG("glycan", "")
|
|
30 with self.assertRaises(IOError):
|
|
31 m = fk.find_entries_in_KEGG("glycan", [])
|
|
32 with self.assertRaises(IOError):
|
|
33 m = fk.find_entries_in_KEGG("glycan", None)
|
|
34
|
|
35
|
|
36 def test_bad_db(self):
|
|
37 """should raise error"""
|
|
38 import urllib2
|
|
39
|
|
40 with self.assertRaises(urllib2.HTTPError):
|
|
41 m = fk.find_entries_in_KEGG("john", "glucose")
|
|
42
|
|
43 def test_unfindable_entry(self):
|
1
|
44 """should return an empty string"""
|
0
|
45 m = fk.find_entries_in_KEGG("glycan", "sally")
|
1
|
46 emptystring=""
|
|
47 self.assertItemsEqual(m,emptystring,"Expected Empty String for non-existent entry")
|
0
|
48
|
|
49 def test_find_example(self):
|
|
50 m = fk.find_entries_in_KEGG("glycan", "glucose")
|
|
51 self.assertIsNotNone(m)
|
|
52 self.assertIn("GDP-glucose", m)
|
|
53
|
|
54 def test_query_has_newlines(self):
|
|
55 """
|
1
|
56 Assume a new line query is an AND query.
|
|
57 """
|
|
58 m = fk.find_entries_in_KEGG("glycan", "glucose\nUDP")
|
|
59 self.assertIsNotNone(m)
|
|
60 print m
|
|
61 self.assertIn("UDP-D-glucose", m)
|
|
62
|
|
63 def test_query_has_newlines_and_a_space(self):
|
|
64 """
|
|
65 glucose\\n UDP. OR's should pass
|
0
|
66 """
|
|
67 m = fk.find_entries_in_KEGG("glycan", "glucose\n UDP")
|
|
68 self.assertIsNotNone(m)
|
|
69 self.assertIn("UDP-D-glucose", m)
|
|
70
|
1
|
71 def test_gene_specific_or(self):
|
|
72 """
|
|
73 test "shiga toxin" returns.
|
|
74 /find/genes/"shiga toxin" for keywords "shiga toxin"
|
|
75 """
|
|
76 m = fk.find_entries_in_KEGG("genes","shiga toxin")
|
|
77 self.assertIsNotNone(m)
|
|
78 #. not matching to all entries - that is silly, the db get updated!
|
|
79 self.assertIn("shiga", m)
|
|
80 self.assertIn("toxin", m)
|
|
81 self.assertNotIn("stm:STM0284",m) # should not be found in the OR query
|
|
82
|
|
83 def test_gene_specific_and(self):
|
|
84 """
|
|
85 test "shiga+toxin" returns. it should
|
|
86 /find/genes/shiga+toxin for keywords "shiga" and "toxin"
|
|
87 """
|
|
88 m = fk.find_entries_in_KEGG("genes","shiga+toxin")
|
|
89 self.assertIsNotNone(m)
|
|
90 #. not matching to all entries - that is silly, the db get updated!
|
|
91 self.assertIn("shiga", m)
|
|
92 self.assertIn("toxin", m)
|
|
93 self.assertIn("stm:STM0284",m) # should be found in the AND query
|
|
94
|
|
95 def test_enzyme_specific_1(self):
|
|
96 """
|
|
97 test 2.4.99.1 returns
|
|
98 """
|
|
99 m = fk.find_entries_in_KEGG("enzyme","2.4.99.1")
|
|
100 self.assertIsNotNone(m)
|
|
101 #. not matching to all entries - that is silly, the db get updated!
|
|
102 self.assertIn("2.4.99.1", m)
|
|
103
|
|
104 def test_enzyme_specific_2(self):
|
|
105 """
|
|
106 test 2.4.99.6 returns
|
|
107 """
|
|
108 m = fk.find_entries_in_KEGG("enzyme","2.4.99.6")
|
|
109 self.assertIsNotNone(m)
|
|
110 #. not matching to all entries - that is silly, the db get updated!
|
|
111 self.assertIn("2.4.99.6", m)
|
|
112
|
|
113 def test_enzyme_specific_3(self):
|
|
114 """
|
|
115 test ec: 2.4.99.6 with space (tests stripping space functionality)
|
|
116 """
|
|
117 m = fk.find_entries_in_KEGG("enzyme","ec: 2.4.99.6")
|
|
118 self.assertIsNotNone(m)
|
|
119 #. not matching to all entries - that is silly, the db get updated!
|
|
120 self.assertIn("2.4.99.6", m)
|
|
121
|
|
122 def test_enzyme_specific_4(self):
|
|
123 """
|
|
124 test ec: 2.4.99. , should return 2.4.99.*
|
|
125 """
|
|
126 m = fk.find_entries_in_KEGG("enzyme","ec: 2.4.99.")
|
|
127 self.assertIsNotNone(m)
|
|
128 #. not matching to all entries - that is silly, the db get updated!
|
|
129 self.assertIn("2.4.99.1", m)
|
|
130 self.assertIn("2.4.99.6", m)
|
|
131 self.assertIn("2.4.99.11", m)
|
|
132
|
|
133 def test_enzyme_specific_5(self):
|
|
134 """
|
|
135 test ec: 2.4.99.1+2.4.99.6 . AND function, so returns nothing here. Do not expect an enzyme to be doubly classified.
|
|
136 """
|
|
137 m = fk.find_entries_in_KEGG("enzyme","2.4.99.1+2.4.99.6")
|
|
138 self.assertIsNotNone(m)
|
|
139 emptystring=""
|
|
140 self.assertItemsEqual(m,emptystring,"Expected Empty String for non-existent entry")
|
|
141
|
|
142 def test_enzyme_specific_6(self):
|
|
143 """
|
|
144 test ec: 2.4.99.1 2.4.99.6 . OR function, should return something but does not (KEGG FAILURE?).
|
|
145 note that trying this without "" will return the AND function result which is incorrect.
|
|
146 """
|
|
147 m = fk.find_entries_in_KEGG("enzyme","2.4.99.1 2.4.99.6")
|
|
148 self.assertIsNotNone(m)
|
|
149 #self.assertIn("2.4.99.1", m)
|
|
150 emptystring=""
|
|
151 print m
|
|
152 self.assertItemsEqual(m,emptystring,"Expected Empty String for non-existent entry")
|
|
153
|
|
154
|
|
155 def test_enzyme_specific_7(self):
|
|
156 """
|
|
157 test deoxy+1.1.1. . AND function, that should return something
|
|
158 """
|
|
159 m = fk.find_entries_in_KEGG("enzyme","deoxy+1.1.1")
|
|
160 self.assertIsNotNone(m)
|
|
161 print m
|
|
162 self.assertIn("deoxy", m)
|
|
163 self.assertIn("1.1.1", m)
|
|
164
|
|
165 def test_enzyme_specific_8(self):
|
|
166 """
|
|
167 test deoxy 1.1.1. . OR function. should return deoxy or 1.1.1. but does not (KEGG FAILURE?). i
|
|
168 note that trying this without "" will return the AND function result which is incorrect.
|
|
169 """
|
|
170 m = fk.find_entries_in_KEGG("enzyme","deoxy 1.1.1")
|
|
171 self.assertIsNotNone(m)
|
|
172 emptystring=""
|
|
173 print m
|
|
174 self.assertItemsEqual(m,emptystring,"Expected Empty String for non-existent entry")
|
|
175
|