annotate get_data/kegg_glycan/test_getkcfKEGG.py @ 1:0a5e0df17054 draft default tip

Uploaded
author chrisb
date Fri, 06 May 2016 08:05:48 -0400
parents 89592faa2875
children
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 getkcfKEGG as gk
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_empty_stream(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
18 """ if empty stream then should return None"""
89592faa2875 Uploaded
chrisb
parents:
diff changeset
19 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
20 m = gk.get_kcf_from_kegg(None)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
21 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
22 m = gk.get_kcf_from_kegg([])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
23
89592faa2875 Uploaded
chrisb
parents:
diff changeset
24 def test_no_matching_entry(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
25 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
26 if non G* entry then return empty lists
89592faa2875 Uploaded
chrisb
parents:
diff changeset
27 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
28 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
29 import urllib2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
30
89592faa2875 Uploaded
chrisb
parents:
diff changeset
31 glycanindex = "X00092"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
32 handle = StringIO.StringIO(''.join(glycanindex))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
33 m, n = gk.get_kcf_from_kegg(handle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
34 self.assertEqual(m, [])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
35 self.assertEqual(n, [])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
36
89592faa2875 Uploaded
chrisb
parents:
diff changeset
37 def test_malformed_entry(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
38 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
39 if malformed entry that looks like "G*" then return HTTPError
89592faa2875 Uploaded
chrisb
parents:
diff changeset
40 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
41 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
42 import urllib2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
43
89592faa2875 Uploaded
chrisb
parents:
diff changeset
44 glycanindex = "GL00092"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
45 handle = StringIO.StringIO(''.join(glycanindex))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
46 with self.assertRaises(urllib2.HTTPError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
47 m, n = gk.get_kcf_from_kegg(handle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
48
89592faa2875 Uploaded
chrisb
parents:
diff changeset
49 def test_glycan(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
50 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
51 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
52 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
53
89592faa2875 Uploaded
chrisb
parents:
diff changeset
54 glycanindex = "G00092"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
55 handle = StringIO.StringIO(''.join(glycanindex))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
56 m, n = gk.get_kcf_from_kegg(handle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
57 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
58 self.assertIsNotNone(n)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
59 self.assertEqual(1, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
60 self.assertEqual(1, len(n))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
61
89592faa2875 Uploaded
chrisb
parents:
diff changeset
62 def test_several_glycans(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
63 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
64 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
65 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
66
89592faa2875 Uploaded
chrisb
parents:
diff changeset
67 glycanindex = "G00092\nG00091\nG00093"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
68 handle = StringIO.StringIO(''.join(glycanindex))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
69 m, n = gk.get_kcf_from_kegg(handle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
70 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
71 self.assertIsNotNone(n)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
72 self.assertEqual(3, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
73 self.assertEqual(3, len(n))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
74