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