~duplicity-team/duplicity/trunk

« back to all changes in this revision

Viewing changes to testing/roottest.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
import sys
 
2
sys.path.insert(0, "../src")
 
3
import os, unittest
 
4
import diffdir, patchdir
 
5
from path import *
 
6
 
 
7
log.setverbosity(7)
 
8
 
 
9
class RootTest(unittest.TestCase):
 
10
        """Test doing operations that only root can"""
 
11
        def copyfileobj(self, infp, outfp):
 
12
                """Copy in fileobj to out, closing afterwards"""
 
13
                blocksize = 32 * 1024
 
14
                while 1:
 
15
                        buf = infp.read(blocksize)
 
16
                        if not buf: break
 
17
                        outfp.write(buf)
 
18
                assert not infp.close()
 
19
                assert not outfp.close()
 
20
 
 
21
        def deltmp(self):
 
22
                """Delete temporary directories"""
 
23
                assert not os.system("rm -rf testfiles/output")
 
24
                os.mkdir("testfiles/output")
 
25
 
 
26
        def total_sequence(self, filelist):
 
27
                """Test signatures, diffing, and patching on directory list"""
 
28
                assert len(filelist) >= 2
 
29
                self.deltmp()
 
30
                assert not os.system("cp -a %s testfiles/output/sequence" %
 
31
                                                         (filelist[0],))
 
32
                seq_path = Path("testfiles/output/sequence")
 
33
                sig = Path("testfiles/output/sig.tar")
 
34
                diff = Path("testfiles/output/diff.tar")
 
35
                for dirname in filelist[1:]:
 
36
                        new_path = Path(dirname)
 
37
                        diffdir.write_block_iter(
 
38
                                diffdir.DirSig(selection.Select(seq_path).set_iter()), sig)
 
39
 
 
40
                        diffdir.write_block_iter(
 
41
                                diffdir.DirDelta(selection.Select(new_path).set_iter(),
 
42
                                                                 sig.open("rb")),
 
43
                                diff)
 
44
 
 
45
                        patchdir.Patch(seq_path, diff.open("rb"))
 
46
 
 
47
                        assert seq_path.compare_recursive(new_path, 1)
 
48
 
 
49
        def test_basic_cycle(self):
 
50
                """Test cycle on dir with devices, changing uid/gid, etc."""
 
51
                self.total_sequence(['testfiles/root1', 'testfiles/root2'])
 
52
 
 
53
def runtests(): unittest.main()
 
54
 
 
55
if __name__ == "__main__": unittest.main()