1
2
3 import os
4 from testformats import swissprot38
5 import Martel
6 from Martel import RecordReader, Parser
7 from xml.sax import handler
8
9 import test_swissprot38
10
11 text = test_swissprot38.record1 + test_swissprot38.record2
12
13
28
44
56
58
59 exp = Martel.Re("(?P<term>(?P<a>a+)(?P<b>b+))+")
60 x = exp.make_iterator("term").iterateString("aabbabaaaabb")
61 term = x.next()
62 assert len(term["a"]) == 1 and term["a"][0] == "aa", term["a"]
63 assert len(term["b"]) == 1 and term["b"][0] == "bb", term["b"]
64 term = x.next()
65 assert len(term["a"]) == 1 and term["a"][0] == "a", term["a"]
66 assert len(term["b"]) == 1 and term["b"][0] == "b", term["b"]
67 term = x.next()
68 assert len(term["a"]) == 1 and term["a"][0] == "aaaa", term["a"]
69 assert len(term["b"]) == 1 and term["b"][0] == "bb", term["b"]
70 term = x.next()
71 assert term is None, "Did not stop correctly"
72
74
75 try:
76 iter
77 except NameError:
78 print "Test skipped - missing 'iter' builtin from Python 2.2."
79 return
80 exp = Martel.Re("(?P<term>(?P<a>a+)(?P<b>b+))+")
81 x = exp.make_iterator("term")
82 it = iter(x.iterateString("aabbabaaaabb"))
83 term = it.next()
84 assert len(term["a"]) == 1 and term["a"][0] == "aa", term["a"]
85 assert len(term["b"]) == 1 and term["b"][0] == "bb", term["b"]
86 term = it.next()
87 assert len(term["a"]) == 1 and term["a"][0] == "a", term["a"]
88 assert len(term["b"]) == 1 and term["b"][0] == "b", term["b"]
89 term = it.next()
90 assert len(term["a"]) == 1 and term["a"][0] == "aaaa", term["a"]
91 assert len(term["b"]) == 1 and term["b"][0] == "bb", term["b"]
92 try:
93 it.next()
94 raise AssertionError("Did not stop correctly")
95 except StopIteration:
96 pass
97
123
124
149
150
174
175
201
202
226
227
250
273
274
275
295
296 if __name__ == "__main__":
297 test()
298