~duplicity-team/duplicity/0.8-series

« back to all changes in this revision

Viewing changes to testing/manual/roottest.py

* Merged in lp:~kenneth-loafman/duplicity/duplicity-pylint
  - Enable additional pylint warnings. Make 1st pass at correction.
      unused-argument,
      unused-wildcard-import,
      redefined-builtin,
      bad-indentation,
      mixed-indentation,
     unreachable
  - Renamed globals to config to fix conflict with __builtin__.glogals()
  - Resolved conflict between duplicity.config and testing.manual.config
  - Normalized emacs mode line to have encoding:utf8 on all *.py files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
 
1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf8 -*-
2
2
#
3
3
# Copyright 2002 Ben Escoto <ben@emerose.org>
4
4
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
21
21
 
22
22
import config
23
23
import sys, unittest
24
 
sys.path.insert(0, "../")
 
24
sys.path.insert(0, u"../")
25
25
 
26
26
from duplicity import diffdir
27
27
from duplicity import patchdir
28
28
from duplicity import selection
29
 
from duplicity.path import * #@UnusedWildImport
 
29
from duplicity.path import *  # pylint: disable=unused-wildcard-import,redefined-builtin
30
30
 
31
31
config.setup()
32
32
 
33
33
class RootTest(unittest.TestCase):
34
 
    """Test doing operations that only root can"""
 
34
    u"""Test doing operations that only root can"""
35
35
 
36
36
    def setUp(self):
37
37
        # must run with euid/egid of root
39
39
        # make sure uid/gid match euid/egid
40
40
        os.setuid(os.geteuid())
41
41
        os.setgid(os.getegid())
42
 
        assert not os.system("tar xzf manual/rootfiles.tar.gz > /dev/null 2>&1")
 
42
        assert not os.system(u"tar xzf manual/rootfiles.tar.gz > /dev/null 2>&1")
43
43
 
44
44
    def tearDown(self):
45
 
        assert not os.system("rm -rf testfiles tempdir temp2.tar")
 
45
        assert not os.system(u"rm -rf testfiles tempdir temp2.tar")
46
46
 
47
47
    def copyfileobj(self, infp, outfp):
48
 
        """Copy in fileobj to out, closing afterwards"""
 
48
        u"""Copy in fileobj to out, closing afterwards"""
49
49
        blocksize = 32 * 1024
50
50
        while 1:
51
51
            buf = infp.read(blocksize)
55
55
        assert not outfp.close()
56
56
 
57
57
    def deltmp(self):
58
 
        """Delete temporary directories"""
59
 
        assert not os.system("rm -rf testfiles/output")
60
 
        os.mkdir("testfiles/output")
 
58
        u"""Delete temporary directories"""
 
59
        assert not os.system(u"rm -rf testfiles/output")
 
60
        os.mkdir(u"testfiles/output")
61
61
 
62
62
    def get_sel(self, path):
63
 
        """Get selection iter over the given directory"""
 
63
        u"""Get selection iter over the given directory"""
64
64
        return selection.Select(path).set_iter()
65
65
 
66
66
    def total_sequence(self, filelist):
67
 
        """Test signatures, diffing, and patching on directory list"""
 
67
        u"""Test signatures, diffing, and patching on directory list"""
68
68
        assert len(filelist) >= 2
69
69
        self.deltmp()
70
 
        assert not os.system("cp -pR %s testfiles/output/sequence" %
 
70
        assert not os.system(u"cp -pR %s testfiles/output/sequence" %
71
71
                             (filelist[0],))
72
 
        seq_path = Path("testfiles/output/sequence")
73
 
        sig = Path("testfiles/output/sig.tar")
74
 
        diff = Path("testfiles/output/diff.tar")
 
72
        seq_path = Path(u"testfiles/output/sequence")
 
73
        sig = Path(u"testfiles/output/sig.tar")
 
74
        diff = Path(u"testfiles/output/diff.tar")
75
75
        for dirname in filelist[1:]:
76
76
            new_path = Path(dirname)
77
77
            diffdir.write_block_iter(
79
79
 
80
80
            diffdir.write_block_iter(
81
81
                diffdir.DirDelta(selection.Select(new_path).set_iter(),
82
 
                                 sig.open("rb")),
 
82
                                 sig.open(u"rb")),
83
83
                diff)
84
84
 
85
 
            patchdir.Patch(seq_path, diff.open("rb"))
 
85
            patchdir.Patch(seq_path, diff.open(u"rb"))
86
86
 
87
87
            assert seq_path.compare_recursive(new_path, 1)
88
88
 
89
89
    def test_basic_cycle(self):
90
 
        """Test cycle on dir with devices, changing uid/gid, etc."""
91
 
        self.total_sequence(['testfiles/root1', 'testfiles/root2'])
 
90
        u"""Test cycle on dir with devices, changing uid/gid, etc."""
 
91
        self.total_sequence([u'testfiles/root1', u'testfiles/root2'])
92
92
 
93
93
    def test_patchdir(self):
94
 
        """Test changing uid/gid, devices"""
 
94
        u"""Test changing uid/gid, devices"""
95
95
        self.deltmp()
96
 
        os.system("cp -pR testfiles/root1 testfiles/output/sequence")
97
 
        seq_path = Path("testfiles/output/sequence")
98
 
        new_path = Path("testfiles/root2")
99
 
        sig = Path("testfiles/output/sig.tar")
100
 
        diff = Path("testfiles/output/diff.tar")
 
96
        os.system(u"cp -pR testfiles/root1 testfiles/output/sequence")
 
97
        seq_path = Path(u"testfiles/output/sequence")
 
98
        new_path = Path(u"testfiles/root2")
 
99
        sig = Path(u"testfiles/output/sig.tar")
 
100
        diff = Path(u"testfiles/output/diff.tar")
101
101
 
102
102
        diffdir.write_block_iter(diffdir.DirSig(self.get_sel(seq_path)), sig)
103
 
        deltablock = diffdir.DirDelta(self.get_sel(new_path), sig.open("rb"))
 
103
        deltablock = diffdir.DirDelta(self.get_sel(new_path), sig.open(u"rb"))
104
104
        diffdir.write_block_iter(deltablock, diff)
105
105
 
106
 
        patchdir.Patch(seq_path, diff.open("rb"))
 
106
        patchdir.Patch(seq_path, diff.open(u"rb"))
107
107
 
108
108
        # since we are not running as root, don't even both comparing,
109
109
        # just make sure file5 exists and file4 doesn't.
110
 
        file5 = seq_path.append("file5")
 
110
        file5 = seq_path.append(u"file5")
111
111
        assert file5.isreg()
112
 
        file4 = seq_path.append("file4")
 
112
        file4 = seq_path.append(u"file4")
113
113
        assert file4.type is None
114
114
 
115
115
    def test_patchdir2(self):
116
 
        """Again test files we don't have access to, this time Tar_WriteSig"""
 
116
        u"""Again test files we don't have access to, this time Tar_WriteSig"""
117
117
        self.deltmp()
118
 
        sig_path = Path("testfiles/output/sig.sigtar")
119
 
        tar_path = Path("testfiles/output/tar.tar")
120
 
        basis_path = Path("testfiles/root1")
 
118
        sig_path = Path(u"testfiles/output/sig.sigtar")
 
119
        tar_path = Path(u"testfiles/output/tar.tar")
 
120
        basis_path = Path(u"testfiles/root1")
121
121
 
122
122
        deltablock = diffdir.DirFull_WriteSig(self.get_sel(basis_path),
123
 
                                              sig_path.open("wb"))
 
123
                                              sig_path.open(u"wb"))
124
124
        diffdir.write_block_iter(deltablock, tar_path)
125
125
 
126
126
def runtests(): unittest.main()
127
127
 
128
 
if __name__ == "__main__":
 
128
if __name__ == u"__main__":
129
129
    unittest.main()