1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
3
# Copyright 2002 Ben Escoto <ben@emerose.org>
4
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
6
# This file is part of duplicity.
8
# Duplicity is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by the
10
# Free Software Foundation; either version 2 of the License, or (at your
11
# option) any later version.
13
# Duplicity is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with duplicity; if not, write to the Free Software Foundation,
20
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
import sys, os, unittest, cStringIO
25
from duplicity import misc
29
class MiscTest(unittest.TestCase):
30
"""Test functions/classes in misc.py"""
32
assert not os.system("tar xzf testfiles.tar.gz > /dev/null 2>&1")
35
assert not os.system("rm -rf testfiles tempdir temp2.tar")
38
assert not os.system("rm -rf testfiles/output")
39
os.mkdir("testfiles/output")
41
def test_file_volume_writer(self):
42
"""Test FileVolumeWriter class"""
45
assert len(s) == 50000
46
infp = cStringIO.StringIO(s)
47
fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
48
fvw.volume_size = 20000
52
for filename in fvw: l.append(filename)
53
assert l == ['testfiles/output/volume.1',
54
'testfiles/output/volume.2',
55
'testfiles/output/volume.3'], l
59
infp2 = open(filename, "rb")
61
assert not infp2.close()
65
def test_file_volume_writer2(self):
66
"""Test again but one volume this time"""
68
fvw = misc.FileVolumeWriter(cStringIO.StringIO("hello, world!"),
69
"testfiles/output/one_vol")
70
assert fvw.next() == "testfiles/output/one_vol"
71
self.assertRaises(StopIteration, fvw.next)
73
def test_file_volume_writer3(self):
74
"""Test case when end of file falls exactly on volume boundary"""
77
assert len(s) == 50000
78
infp = cStringIO.StringIO(s)
79
fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
80
fvw.volume_size = 25000
84
for filename in fvw: l.append(filename)
85
assert l == ['testfiles/output/volume.1',
86
'testfiles/output/volume.2']
90
if __name__ == "__main__":