~duplicity-team/duplicity/0.7-series

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import config
import sys, os, unittest, cStringIO
sys.path.insert(0, "../")
from duplicity import misc, log

config.setup()

class MiscTest(unittest.TestCase):
    """Test functions/classes in misc.py"""
    def deltmp(self):
        assert not os.system("rm -rf testfiles/output")
        os.mkdir("testfiles/output")

    def test_file_volume_writer(self):
        """Test FileVolumeWriter class"""
        self.deltmp()
        s = "hello" * 10000
        assert len(s) == 50000
        infp = cStringIO.StringIO(s)
        fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
        fvw.volume_size = 20000
        fvw.blocksize = 5000

        l = []
        for filename in fvw: l.append(filename)
        assert l == ['testfiles/output/volume.1',
                     'testfiles/output/volume.2',
                     'testfiles/output/volume.3'], l

        s2 = ""
        for filename in l:
            infp2 = open(filename, "rb")
            s2 += infp2.read()
            assert not infp2.close()

        assert s2 == s

    def test_file_volume_writer2(self):
        """Test again but one volume this time"""
        self.deltmp()
        fvw = misc.FileVolumeWriter(cStringIO.StringIO("hello, world!"),
                                    "testfiles/output/one_vol")
        assert fvw.next() == "testfiles/output/one_vol"
        self.assertRaises(StopIteration, fvw.next)

    def test_file_volume_writer3(self):
        """Test case when end of file falls exactly on volume boundary"""
        self.deltmp()
        s = "hello" * 10000
        assert len(s) == 50000
        infp = cStringIO.StringIO(s)
        fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
        fvw.volume_size = 25000
        fvw.blocksize = 5000

        l = []
        for filename in fvw: l.append(filename)
        assert l == ['testfiles/output/volume.1',
                     'testfiles/output/volume.2']



if __name__ == "__main__":
    unittest.main()