53 |
self.assertRaises(StopIteration, new_iter.next) |
self.assertRaises(StopIteration, new_iter.next) |
54 |
|
|
55 |
|
|
56 |
class testRORPIters(unittest.TestCase): |
class testMiscIters(unittest.TestCase): |
57 |
"""Test sending rorpiter back and forth""" |
"""Test sending rorpiter back and forth""" |
58 |
def setUp(self): |
def setUp(self): |
59 |
"""Make testfiles/output directory and a few files""" |
"""Make testfiles/output directory and a few files""" |
83 |
self.regfile2.setdata() |
self.regfile2.setdata() |
84 |
self.regfile3.setdata() |
self.regfile3.setdata() |
85 |
|
|
86 |
def print_RORPIterFile(self, rpiter_file): |
def print_MiscIterFile(self, rpiter_file): |
87 |
"""Print the given rorpiter file""" |
"""Print the given rorpiter file""" |
88 |
while 1: |
while 1: |
89 |
buf = rpiter_file.read() |
buf = rpiter_file.read() |
93 |
def testBasic(self): |
def testBasic(self): |
94 |
"""Test basic conversion""" |
"""Test basic conversion""" |
95 |
l = [self.outputrp, self.regfile1, self.regfile2, self.regfile3] |
l = [self.outputrp, self.regfile1, self.regfile2, self.regfile3] |
96 |
i_out = FileToRORPIter(RORPIterToFile(iter(l))) |
i_out = FileToMiscIter(MiscIterToFile(iter(l))) |
97 |
|
|
98 |
out1 = i_out.next() |
out1 = i_out.next() |
99 |
assert out1 == self.outputrp |
assert out1 == self.outputrp |
113 |
i_out.next() |
i_out.next() |
114 |
self.assertRaises(StopIteration, i_out.next) |
self.assertRaises(StopIteration, i_out.next) |
115 |
|
|
116 |
|
def testMix(self): |
117 |
|
"""Test a mix of RPs and ordinary objects""" |
118 |
|
l = [5, self.regfile3, "hello"] |
119 |
|
s = MiscIterToFile(iter(l)).read() |
120 |
|
i_out = FileToMiscIter(StringIO.StringIO(s)) |
121 |
|
|
122 |
|
out1 = i_out.next() |
123 |
|
assert out1 == 5, out1 |
124 |
|
|
125 |
|
out2 = i_out.next() |
126 |
|
assert out2 == self.regfile3 |
127 |
|
fp = out2.open("rb") |
128 |
|
assert fp.read() == "goodbye" |
129 |
|
assert not fp.close() |
130 |
|
|
131 |
|
out3 = i_out.next() |
132 |
|
assert out3 == "hello", out3 |
133 |
|
|
134 |
|
self.assertRaises(StopIteration, i_out.next) |
135 |
|
|
136 |
def testFlush(self): |
def testFlush(self): |
137 |
"""Test flushing property of RORPIterToFile""" |
"""Test flushing property of MiscIterToFile""" |
138 |
l = [self.outputrp, RORPIterFlush, self.outputrp] |
l = [self.outputrp, MiscIterFlush, self.outputrp] |
139 |
filelike = RORPIterToFile(iter(l)) |
filelike = MiscIterToFile(iter(l)) |
140 |
new_filelike = StringIO.StringIO((filelike.read() + "z" + |
new_filelike = StringIO.StringIO((filelike.read() + "z" + |
141 |
C.long2str(0L))) |
C.long2str(0L))) |
142 |
|
|
143 |
i_out = FileToRORPIter(new_filelike) |
i_out = FileToMiscIter(new_filelike) |
144 |
assert i_out.next() == self.outputrp |
assert i_out.next() == self.outputrp |
145 |
self.assertRaises(StopIteration, i_out.next) |
self.assertRaises(StopIteration, i_out.next) |
146 |
|
|
147 |
i_out2 = FileToRORPIter(filelike) |
i_out2 = FileToMiscIter(filelike) |
148 |
assert i_out2.next() == self.outputrp |
assert i_out2.next() == self.outputrp |
149 |
self.assertRaises(StopIteration, i_out2.next) |
self.assertRaises(StopIteration, i_out2.next) |
150 |
|
|
151 |
def testFlushRepeat(self): |
def testFlushRepeat(self): |
152 |
"""Test flushing like above, but have Flush obj emerge from iter""" |
"""Test flushing like above, but have Flush obj emerge from iter""" |
153 |
l = [self.outputrp, RORPIterFlushRepeat, self.outputrp] |
l = [self.outputrp, MiscIterFlushRepeat, self.outputrp] |
154 |
filelike = RORPIterToFile(iter(l)) |
filelike = MiscIterToFile(iter(l)) |
155 |
new_filelike = StringIO.StringIO((filelike.read() + "z" + |
new_filelike = StringIO.StringIO((filelike.read() + "z" + |
156 |
C.long2str(0L))) |
C.long2str(0L))) |
157 |
|
|
158 |
i_out = FileToRORPIter(new_filelike) |
i_out = FileToMiscIter(new_filelike) |
159 |
assert i_out.next() == self.outputrp |
assert i_out.next() == self.outputrp |
160 |
assert i_out.next() is RORPIterFlushRepeat |
assert i_out.next() is MiscIterFlushRepeat |
161 |
self.assertRaises(StopIteration, i_out.next) |
self.assertRaises(StopIteration, i_out.next) |
162 |
|
|
163 |
i_out2 = FileToRORPIter(filelike) |
i_out2 = FileToMiscIter(filelike) |
164 |
assert i_out2.next() == self.outputrp |
assert i_out2.next() == self.outputrp |
165 |
self.assertRaises(StopIteration, i_out2.next) |
self.assertRaises(StopIteration, i_out2.next) |
166 |
|
|