0
|
1 __license__ = "MIT"
|
|
2
|
|
3 import unittest
|
|
4 import lc_extend as lc
|
|
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 self.examplelc = """(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)
|
|
13 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)
|
|
14 (GN??Ma3(GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
15 (GN??(GN??)Ma3(GN??Ma6)Mb4GNb4GN)
|
|
16 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)
|
|
17 (A??GN??Ma3(GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
18 (GNb4(GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
19 (GNb4(A??GN??Ma3)(GN??Ma6)Mb4GNb4GN)
|
|
20 (NN??A??GN??Ma3(Ma6)Mb4GNb4(Fa6)GN)
|
|
21 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M,M)
|
|
22 (A??GN??Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
23 (GNb4(A??GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
24 (GNb4(A??GN??Ma3)(A??GN??Ma6)Mb4GNb4GN)
|
|
25 (Ma2Ma2Ma3(Ma2Ma3(Ma2Ma6)Ma6)Mb4GNb4GN)
|
|
26 (NN??A??GN??Ma3(A??GN??Ma6)Mb4GNb4GN)
|
|
27 (GNb4(A??(Fa3)GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
28 (GNb4(A??GN??Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
|
|
29 (A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4GN)
|
|
30 (NN??A??GN??Ma3(A??GN??Ma6)Mb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6)GN,NN,NN,NN,NN,A??GN,A??GN,F)
|
|
64 """
|
|
65 pass
|
|
66
|
|
67 def tearDown(self):
|
|
68 pass
|
|
69
|
|
70
|
|
71 def test_simple_lc(self):
|
|
72 import StringIO
|
|
73
|
|
74 lcinput = ["(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)"]
|
|
75 lchandle = StringIO.StringIO('\n'.join(lcinput))
|
|
76 m = lc.read_linearcode(lchandle, "logging.log")
|
|
77 self.assertIsNotNone(m)
|
|
78 self.assertEqual(1, len(m))
|
|
79
|
|
80 def test_commad_lc_extend(self):
|
|
81 import StringIO
|
|
82
|
|
83 lcinput = ["(Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)"]
|
|
84 lchandle = StringIO.StringIO('\n'.join(lcinput))
|
|
85 m = lc.read_linearcode(lchandle, "logging.log", True)
|
|
86 self.assertIsNotNone(m)
|
|
87 self.assertEqual(3, len(m))
|
|
88 self.assertEqual(['M??Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN', 'Ma2Ma3(M??Ma3(Ma6)Ma6)Mb4GNb4GN', 'Ma2Ma3(Ma3(M??Ma6)Ma6)Mb4GNb4GN'],m)
|
|
89
|
|
90 def test_commad_lc_append(self):
|
|
91 import StringIO
|
|
92
|
|
93 lcinput = ["(Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)"]
|
|
94 lchandle = StringIO.StringIO('\n'.join(lcinput))
|
|
95 m = lc.read_linearcode(lchandle, "logging.log")
|
|
96 self.assertIsNotNone(m)
|
|
97 self.assertEqual(1, len(m))
|
|
98 self.assertEqual("((M??)X??)(Ma2Ma3(Ma3)(Ma6)Ma6)Mb4GNb4GN", m[0])
|
|
99
|
|
100 def test_empty_stream(self):
|
|
101 """
|
|
102 should raise IOError
|
|
103 """
|
|
104 with self.assertRaises(IOError):
|
|
105 m = lc.read_linearcode([], "logging.log")
|
|
106 with self.assertRaises(IOError):
|
|
107 m = lc.read_linearcode("", "logging.log")
|
|
108 with self.assertRaises(IOError):
|
|
109 m = lc.read_linearcode([], "logging.log")
|
|
110
|
|
111 def test_empty_logger(self):
|
|
112 """
|
|
113 should work as usual as logger is defined by default
|
|
114 """
|
|
115 import StringIO
|
|
116
|
|
117 lcinput = ["(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)"]
|
|
118 lchandle = StringIO.StringIO('\n'.join(lcinput))
|
|
119 m = lc.read_linearcode(lchandle)
|
|
120 self.assertIsNotNone(m)
|
|
121
|
|
122 def test_many_lc_extend(self):
|
|
123 import StringIO
|
|
124
|
|
125 lchandle = StringIO.StringIO(''.join(self.examplelc))
|
|
126 m = lc.read_linearcode(lchandle, extend=True)
|
|
127 self.assertIsNotNone(m)
|
|
128 self.assertEqual(150, len(m))
|
|
129
|
|
130 def test_many_lc_append(self):
|
|
131 import StringIO
|
|
132
|
|
133 lchandle = StringIO.StringIO(''.join(self.examplelc))
|
|
134 m = lc.read_linearcode(lchandle)
|
|
135 self.assertIsNotNone(m)
|
|
136 self.assertEqual(52, len(m)) # that is equal to number of examples
|
|
137
|
|
138
|
|
139 def run_tests():
|
|
140 unittest.main()
|
|
141
|
|
142
|
|
143 if __name__ == '__main__':
|
|
144 run_tests()
|
|
145
|
|
146
|