annotate manipulate/extend_linearcode/test_linearcode_extend.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 lc_extend as lc
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 self.examplelc = """(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
13 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
14 (GN??Ma3(GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
15 (GN??(GN??)Ma3(GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
16 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
17 (A??GN??Ma3(GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
18 (GNb4(GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
19 (GNb4(A??GN??Ma3)(GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
20 (NN??A??GN??Ma3(Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
21 (Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M,M)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
22 (A??GN??Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
23 (GNb4(A??GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
24 (GNb4(A??GN??Ma3)(A??GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
25 (Ma2Ma2Ma3(Ma2Ma3(Ma2Ma6)Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
26 (NN??A??GN??Ma3(A??GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
27 (GNb4(A??(Fa3)GN??Ma3)(GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
28 (GNb4(A??GN??Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
29 (A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
30 (NN??A??GN??Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
31 (GNb4(A??(Fa3)GN??Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
32 (A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
33 (NN??A??GN??Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
34 (NN??A??GN??Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
35 (NN??A??GN??Ma3(NN??A??GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
36 (GNb4(NN??A??GN??Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
37 (NN??A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
38 (NN??A??GN??Ma3(NN??A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
39 (NN??A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
40 (GNb4(A??(Fa3)GN??(A??GN??)Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
41 (NN??A??(Fa3)GN??Ma3(NN??A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
42 (NN??A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
43 (GNb4(A??(Fa3)GN??(A??(Fa3)GN??)Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
44 (NN??A??GN??(A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN,F,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
45 (NN??A??GN??(NN??A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
46 (GNb4(NN??A??GN??(A??GN??)Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
47 (NN??A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
48 (NN??A??GN??(NN??A??GN??)Ma3(A??GN??Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
49 (GNb4(NN??A??GN??(A??GN??)Ma3)(A??GN??Ma6)Mb4GNb4(Fa6)GN,F,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
50 (NN??A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
51 (NN??A??GN??(NN??A??GN??)Ma3(NN??A??GN??Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
52 (NN??A??GN??(NN??A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
53 (NN??A??GN??Ma3(NN??A??GN??(NN??A??(Fa3)GN??)Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
54 (GNb4(NN??A??GN??Ma3)(NN??A??GN??(NN??A??GN??)Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
55 (NN??A??GN??(NN??A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
56 (NN??A??GN??(NN??A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,F,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
57 (A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,NN,NN,A??GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
58 (NN??A??GN??(NN??A??GN??)Ma3(NN??A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
59 (A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,F,NN,NN,A??GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
60 (NN??A??(Fa3)GN??(NN??A??GN??)Ma3(NN??A??GN??(NN??A??GN??)Ma6)Mb4GNb4(Fa6)GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
61 (A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,NN,NN,NN,F,A??GN)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
62 (A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,NN,NN,NN,NN,A??GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
63 (A??GN??(A??GN??)Ma3(A??GN??(A??GN??)Ma6)Mb4GNb4(Fa6)GN,NN,NN,NN,NN,A??GN,A??GN,F)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
64 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
65 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
66
89592faa2875 Uploaded
chrisb
parents:
diff changeset
67 def tearDown(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
68 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
69
89592faa2875 Uploaded
chrisb
parents:
diff changeset
70
89592faa2875 Uploaded
chrisb
parents:
diff changeset
71 def test_simple_lc(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
72 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
73
89592faa2875 Uploaded
chrisb
parents:
diff changeset
74 lcinput = ["(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)"]
89592faa2875 Uploaded
chrisb
parents:
diff changeset
75 lchandle = StringIO.StringIO('\n'.join(lcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
76 m = lc.read_linearcode(lchandle, "logging.log")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
77 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
78 self.assertEqual(1, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
79
89592faa2875 Uploaded
chrisb
parents:
diff changeset
80 def test_commad_lc_extend(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
81 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
82
89592faa2875 Uploaded
chrisb
parents:
diff changeset
83 lcinput = ["(Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)"]
89592faa2875 Uploaded
chrisb
parents:
diff changeset
84 lchandle = StringIO.StringIO('\n'.join(lcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
85 m = lc.read_linearcode(lchandle, "logging.log", True)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
86 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
87 self.assertEqual(3, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
88 self.assertEqual(['M??Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN', 'Ma2Ma3(M??Ma3(Ma6)Ma6)Mb4GNb4GN', 'Ma2Ma3(Ma3(M??Ma6)Ma6)Mb4GNb4GN'],m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
89
89592faa2875 Uploaded
chrisb
parents:
diff changeset
90 def test_commad_lc_append(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
91 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
92
89592faa2875 Uploaded
chrisb
parents:
diff changeset
93 lcinput = ["(Ma2Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN,M)"]
89592faa2875 Uploaded
chrisb
parents:
diff changeset
94 lchandle = StringIO.StringIO('\n'.join(lcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
95 m = lc.read_linearcode(lchandle, "logging.log")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
96 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
97 self.assertEqual(1, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
98 self.assertEqual("((M??)X??)(Ma2Ma3(Ma3)(Ma6)Ma6)Mb4GNb4GN", m[0])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
99
89592faa2875 Uploaded
chrisb
parents:
diff changeset
100 def test_empty_stream(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
101 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
102 should raise IOError
89592faa2875 Uploaded
chrisb
parents:
diff changeset
103 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
104 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
105 m = lc.read_linearcode([], "logging.log")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
106 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
107 m = lc.read_linearcode("", "logging.log")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
108 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
109 m = lc.read_linearcode([], "logging.log")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
110
89592faa2875 Uploaded
chrisb
parents:
diff changeset
111 def test_empty_logger(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
112 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
113 should work as usual as logger is defined by default
89592faa2875 Uploaded
chrisb
parents:
diff changeset
114 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
115 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
116
89592faa2875 Uploaded
chrisb
parents:
diff changeset
117 lcinput = ["(Ma3(Ma3(Ma6)Ma6)Mb4GNb4GN)"]
89592faa2875 Uploaded
chrisb
parents:
diff changeset
118 lchandle = StringIO.StringIO('\n'.join(lcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
119 m = lc.read_linearcode(lchandle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
120 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
121
89592faa2875 Uploaded
chrisb
parents:
diff changeset
122 def test_many_lc_extend(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
123 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
124
89592faa2875 Uploaded
chrisb
parents:
diff changeset
125 lchandle = StringIO.StringIO(''.join(self.examplelc))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
126 m = lc.read_linearcode(lchandle, extend=True)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
127 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
128 self.assertEqual(150, len(m))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
129
89592faa2875 Uploaded
chrisb
parents:
diff changeset
130 def test_many_lc_append(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
131 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
132
89592faa2875 Uploaded
chrisb
parents:
diff changeset
133 lchandle = StringIO.StringIO(''.join(self.examplelc))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
134 m = lc.read_linearcode(lchandle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
135 self.assertIsNotNone(m)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
136 self.assertEqual(52, len(m)) # that is equal to number of examples
89592faa2875 Uploaded
chrisb
parents:
diff changeset
137
89592faa2875 Uploaded
chrisb
parents:
diff changeset
138
89592faa2875 Uploaded
chrisb
parents:
diff changeset
139 def run_tests():
89592faa2875 Uploaded
chrisb
parents:
diff changeset
140 unittest.main()
89592faa2875 Uploaded
chrisb
parents:
diff changeset
141
89592faa2875 Uploaded
chrisb
parents:
diff changeset
142
89592faa2875 Uploaded
chrisb
parents:
diff changeset
143 if __name__ == '__main__':
89592faa2875 Uploaded
chrisb
parents:
diff changeset
144 run_tests()
89592faa2875 Uploaded
chrisb
parents:
diff changeset
145
89592faa2875 Uploaded
chrisb
parents:
diff changeset
146