annotate get_data/kegg_glycan/test_findKEGG.py @ 0:89592faa2875 draft

Uploaded
author chrisb
date Wed, 23 Mar 2016 14:35:56 -0400
parents
children 0a5e0df17054
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
1 __license__ = "MIT"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
3 import unittest
89592faa2875 Uploaded
chrisb
parents:
diff changeset
4 import findKEGG as fk
89592faa2875 Uploaded
chrisb
parents:
diff changeset
5
89592faa2875 Uploaded
chrisb
parents:
diff changeset
6
89592faa2875 Uploaded
chrisb
parents:
diff changeset
7 class SimpleUnitTest(unittest.TestCase):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
8 def setUp(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
9 import os
89592faa2875 Uploaded
chrisb
parents:
diff changeset
10
89592faa2875 Uploaded
chrisb
parents:
diff changeset
11 os.environ["http_proxy"] = "" # work around for IOError: [Errno url error] invalid proxy for http:
89592faa2875 Uploaded
chrisb
parents:
diff changeset
12 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
13
89592faa2875 Uploaded
chrisb
parents:
diff changeset
14 def tearDown(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
15 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
16
89592faa2875 Uploaded
chrisb
parents:
diff changeset
17 def test_no_db_specified(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
18 """should raise error"""
89592faa2875 Uploaded
chrisb
parents:
diff changeset
19 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
20 m = fk.find_entries_in_KEGG([], " ")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
21 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
22 m = fk.find_entries_in_KEGG("", " ")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
23 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
24 m = fk.find_entries_in_KEGG(None, " ")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
25
89592faa2875 Uploaded
chrisb
parents:
diff changeset
26 def test_no_query_specified(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
27 """should raise error"""
89592faa2875 Uploaded
chrisb
parents:
diff changeset
28 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
29 m = fk.find_entries_in_KEGG("glycan", "")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
30 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
31 m = fk.find_entries_in_KEGG("glycan", [])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
32 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
33 m = fk.find_entries_in_KEGG("glycan", None)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
34
89592faa2875 Uploaded
chrisb
parents:
diff changeset
35
89592faa2875 Uploaded
chrisb
parents:
diff changeset
36 def test_bad_db(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
37 """should raise error"""
89592faa2875 Uploaded
chrisb
parents:
diff changeset
38 import urllib2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
39
89592faa2875 Uploaded
chrisb
parents:
diff changeset
40 with self.assertRaises(urllib2.HTTPError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
41 m = fk.find_entries_in_KEGG("john", "glucose")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
42
89592faa2875 Uploaded
chrisb
parents:
diff changeset
43 def test_unfindable_entry(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
44 """should return None"""
89592faa2875 Uploaded
chrisb
parents:
diff changeset
45 m = fk.find_entries_in_KEGG("glycan", "sally")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
46 self.assertIsNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
47
89592faa2875 Uploaded
chrisb
parents:
diff changeset
48 def test_find_example(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
49 m = fk.find_entries_in_KEGG("glycan", "glucose")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
50 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
51 self.assertIn("GDP-glucose", m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
52
89592faa2875 Uploaded
chrisb
parents:
diff changeset
53 def test_query_has_newlines(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
54 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
55 should be fine and return entries
89592faa2875 Uploaded
chrisb
parents:
diff changeset
56 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
57 m = fk.find_entries_in_KEGG("glycan", "glucose\n UDP")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
58 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
59 self.assertIn("UDP-D-glucose", m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
60