0
|
1 __license__ = "MIT"
|
|
2
|
|
3 import unittest
|
|
4 import rename_kcf as rk
|
|
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_simple_kcf(self):
|
|
18 import StringIO
|
|
19
|
|
20 kcinput = """ENTRY ((A??)AN) Glycan
|
|
21 NODE 2
|
|
22 1 galnac 0 0
|
|
23 2 gal -8 0
|
|
24 EDGE 1
|
|
25 1 2:1 1
|
|
26 ///
|
|
27 """
|
|
28
|
|
29 kchandle = StringIO.StringIO(''.join(kcinput))
|
|
30 h = rk.read_meta_kcf(kchandle)
|
|
31 i = rk.flatten_meta_kcf_list(h)
|
|
32 self.assertIn("ENTRY GLY0 Glycan\n", i)
|
|
33
|
|
34 def test_simple_kcf_rename_newcount(self):
|
|
35 import StringIO
|
|
36
|
|
37 kcinput = """ENTRY ((A??)AN) Glycan
|
|
38 NODE 2
|
|
39 1 galnac 0 0
|
|
40 2 gal -8 0
|
|
41 EDGE 1
|
|
42 1 2:1 1
|
|
43 ///
|
|
44 """
|
|
45
|
|
46 kchandle = StringIO.StringIO(''.join(kcinput))
|
|
47 h = rk.read_meta_kcf(kchandle, "FLY", 15)
|
|
48 i = rk.flatten_meta_kcf_list(h)
|
|
49 self.assertIn("ENTRY FLY15 Glycan\n", i)
|
|
50
|
|
51 def test_initial_newline_simple_kcf(self):
|
|
52 import StringIO
|
|
53
|
|
54 kcinput = """
|
|
55 ENTRY ((A??)AN) Glycan
|
|
56 NODE 2
|
|
57 1 galnac 0 0
|
|
58 2 gal -8 0
|
|
59 EDGE 1
|
|
60 1 2:1 1
|
|
61 ///
|
|
62 """
|
|
63
|
|
64 kchandle = StringIO.StringIO(''.join(kcinput))
|
|
65 h = rk.read_meta_kcf(kchandle)
|
|
66 i = rk.flatten_meta_kcf_list(h)
|
|
67 self.assertIn("ENTRY GLY0 Glycan\n", i)
|
|
68
|
|
69 def test_multiple_kcf(self):
|
|
70 import StringIO
|
|
71
|
|
72 kcinput = """ENTRY ((A??)AN) Glycan
|
|
73 NODE 2
|
|
74 1 galnac 0 0
|
|
75 2 gal -8 0
|
|
76 EDGE 1
|
|
77 1 2:1 1
|
|
78 ///
|
|
79 ENTRY ((A??)AN) Glycan
|
|
80 NODE 2
|
|
81 1 galnac 0 0
|
|
82 2 gal -8 0
|
|
83 EDGE 1
|
|
84 1 2:1 1
|
|
85 ///
|
|
86 ENTRY G00005 Glycan
|
|
87 NODE 6
|
|
88 1 PP-Dol 15 1
|
|
89 2 GlcNAc 8 1
|
|
90 3 GlcNAc 0 1
|
|
91 4 Man -9 1
|
|
92 5 Man -16 7
|
|
93 6 Man -16 -6
|
|
94 EDGE 5
|
|
95 1 2:a1 1
|
|
96 2 3:b1 2:4
|
|
97 3 4:b1 3:4
|
|
98 4 5:a1 4:6
|
|
99 5 6:a1 4:3
|
|
100 ///
|
|
101 """
|
|
102 kchandle = StringIO.StringIO(''.join(kcinput))
|
|
103 h = rk.read_meta_kcf(kchandle)
|
|
104 i = rk.flatten_meta_kcf_list(h)
|
|
105 self.assertIn("ENTRY GLY0 Glycan\n", i)
|
|
106 self.assertIn("ENTRY GLY1 Glycan\n", i)
|
|
107 self.assertIn("ENTRY GLY2 Glycan\n", i)
|
|
108
|
|
109 def test_empty_stream(self):
|
|
110 with self.assertRaises(IOError):
|
|
111 m = rk.read_meta_kcf(None)
|
|
112 with self.assertRaises(IOError):
|
|
113 m = rk.read_meta_kcf([])
|
|
114 with self.assertRaises(IOError):
|
|
115 m = rk.read_meta_kcf("")
|
|
116
|
|
117 def test_non_integer_counter(self):
|
|
118 import StringIO
|
|
119
|
|
120 kcinput = """ENTRY ((A??)AN) Glycan
|
|
121 NODE 2
|
|
122 1 galnac 0 0
|
|
123 2 gal -8 0
|
|
124 EDGE 1
|
|
125 1 2:1 1
|
|
126 ///
|
|
127 """
|
|
128
|
|
129 kchandle = StringIO.StringIO(''.join(kcinput))
|
|
130 with self.assertRaises(TypeError):
|
|
131 h = rk.read_meta_kcf(kchandle, "FLY", "abc")
|
|
132
|
|
133
|
|
134 def run_tests():
|
|
135 unittest.main()
|
|
136
|
|
137
|
|
138 if __name__ == '__main__':
|
|
139 run_tests()
|
|
140
|
|
141
|