1
from __future__ import generators
3
sys.path.insert(0, "../src")
4
import unittest, cStringIO
9
class MiscTest(unittest.TestCase):
10
"""Test functions/classes in misc.py"""
12
assert not os.system("rm -rf testfiles/output")
13
os.mkdir("testfiles/output")
15
def test_file_volume_writer(self):
16
"""Test FileVolumeWriter class"""
19
assert len(s) == 50000
20
infp = cStringIO.StringIO(s)
21
fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
22
fvw.volume_size = 20000
26
for filename in fvw: l.append(filename)
27
assert l == ['testfiles/output/volume.1',
28
'testfiles/output/volume.2',
29
'testfiles/output/volume.3'], l
33
infp2 = open(filename, "rb")
35
assert not infp2.close()
39
def test_file_volume_writer2(self):
40
"""Test again but one volume this time"""
42
fvw = misc.FileVolumeWriter(cStringIO.StringIO("hello, world!"),
43
"testfiles/output/one_vol")
44
assert fvw.next() == "testfiles/output/one_vol"
45
self.assertRaises(StopIteration, fvw.next)
47
def test_file_volume_writer3(self):
48
"""Test case when end of file falls exactly on volume boundary"""
51
assert len(s) == 50000
52
infp = cStringIO.StringIO(s)
53
fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
54
fvw.volume_size = 25000
58
for filename in fvw: l.append(filename)
59
assert l == ['testfiles/output/volume.1',
60
'testfiles/output/volume.2']
64
if __name__ == "__main__": unittest.main()