~ed.so/duplicity/reuse-passphrase-for-signing-fix

« back to all changes in this revision

Viewing changes to testing/misctest.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import generators
 
2
import sys
 
3
sys.path.insert(0, "../src")
 
4
import unittest, cStringIO
 
5
import misc, log, os
 
6
 
 
7
log.setverbosity(3)
 
8
 
 
9
class MiscTest(unittest.TestCase):
 
10
        """Test functions/classes in misc.py"""
 
11
        def deltmp(self):
 
12
                assert not os.system("rm -rf testfiles/output")
 
13
                os.mkdir("testfiles/output")
 
14
 
 
15
        def test_file_volume_writer(self):
 
16
                """Test FileVolumeWriter class"""
 
17
                self.deltmp()
 
18
                s = "hello" * 10000
 
19
                assert len(s) == 50000
 
20
                infp = cStringIO.StringIO(s)
 
21
                fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
 
22
                fvw.volume_size = 20000
 
23
                fvw.blocksize = 5000
 
24
 
 
25
                l = []
 
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
 
30
 
 
31
                s2 = ""
 
32
                for filename in l:
 
33
                        infp2 = open(filename, "rb")
 
34
                        s2 += infp2.read()
 
35
                        assert not infp2.close()
 
36
 
 
37
                assert s2 == s
 
38
 
 
39
        def test_file_volume_writer2(self):
 
40
                """Test again but one volume this time"""
 
41
                self.deltmp()
 
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)
 
46
 
 
47
        def test_file_volume_writer3(self):
 
48
                """Test case when end of file falls exactly on volume boundary"""
 
49
                self.deltmp()
 
50
                s = "hello" * 10000
 
51
                assert len(s) == 50000
 
52
                infp = cStringIO.StringIO(s)
 
53
                fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
 
54
                fvw.volume_size = 25000
 
55
                fvw.blocksize = 5000
 
56
 
 
57
                l = []
 
58
                for filename in fvw: l.append(filename)
 
59
                assert l == ['testfiles/output/volume.1',
 
60
                                         'testfiles/output/volume.2']
 
61
 
 
62
 
 
63
 
 
64
if __name__ == "__main__": unittest.main()