~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-15 22:00:36 UTC
  • mto: (1185.50.20 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1532.
  • Revision ID: john@arbash-meinel.com-20051215220036-e1f4de8dff952819
Added the ability to disable setting permissions

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
            os.chmod(p, file_mode)
54
54
 
55
55
 
56
 
def check_mode_r(test, base, file_mode, dir_mode):
57
 
    """Check that all permissions match"""
 
56
def check_mode_r(test, base, file_mode, dir_mode, include_base=True):
 
57
    """Check that all permissions match
 
58
 
 
59
    :param test: The TestCase being run
 
60
    :param base: The path to the root directory to check
 
61
    :param file_mode: The mode for all files
 
62
    :param dir_mode: The mode for all directories
 
63
    :param include_base: If false, only check the subdirectories
 
64
    """
 
65
    assert os.path.isdir(base)
 
66
    if include_base:
 
67
        check_mode(test, base, dir_mode)
58
68
    for root, dirs, files in os.walk(base):
59
69
        for d in dirs:
60
70
            p = os.path.join(root, d)
138
148
        t.commit('new d')
139
149
        check_mode_r(self, '.bzr', 0664, 02775)
140
150
 
 
151
    def test_disable_set_mode(self):
 
152
        # TODO: jam 20051215 Ultimately, this test should probably test that
 
153
        #                    extra chmod calls aren't being made
 
154
        import bzrlib.branch
 
155
        try:
 
156
            b = Branch.initialize(u'.')
 
157
            self.assertNotEqual(None, b._dir_mode)
 
158
            self.assertNotEqual(None, b._file_mode)
 
159
 
 
160
            bzrlib.branch.BzrBranch._set_dir_mode = False
 
161
            b = Branch.open(u'.')
 
162
            self.assertEqual(None, b._dir_mode)
 
163
            self.assertNotEqual(None, b._file_mode)
 
164
 
 
165
            bzrlib.branch.BzrBranch._set_file_mode = False
 
166
            b = Branch.open(u'.')
 
167
            self.assertEqual(None, b._dir_mode)
 
168
            self.assertEqual(None, b._file_mode)
 
169
 
 
170
            bzrlib.branch.BzrBranch._set_dir_mode = True
 
171
            b = Branch.open(u'.')
 
172
            self.assertNotEqual(None, b._dir_mode)
 
173
            self.assertEqual(None, b._file_mode)
 
174
 
 
175
            bzrlib.branch.BzrBranch._set_file_mode = True
 
176
            b = Branch.open(u'.')
 
177
            self.assertNotEqual(None, b._dir_mode)
 
178
            self.assertNotEqual(None, b._file_mode)
 
179
        finally:
 
180
            bzrlib.branch.BzrBranch._set_dir_mode = True
 
181
            bzrlib.branch.BzrBranch._set_file_mode = True
 
182
 
 
183
    def test_new_branch(self):
 
184
        if sys.platform == 'win32':
 
185
            raise TestSkipped('chmod has no effect on win32')
 
186
 
 
187
        os.mkdir('a')
 
188
        mode = stat.S_IMODE(os.stat('a').st_mode)
 
189
        b = Branch.initialize('a')
 
190
        assertEqualMode(self, mode, b._dir_mode)
 
191
        assertEqualMode(self, mode & ~07111, b._file_mode)
 
192
 
 
193
        os.mkdir('b')
 
194
        os.chmod('b', 02777)
 
195
        b = Branch.initialize('b')
 
196
        assertEqualMode(self, 02777, b._dir_mode)
 
197
        assertEqualMode(self, 00666, b._file_mode)
 
198
        check_mode_r(self, 'b/.bzr', 00666, 02777)
 
199
 
 
200
        os.mkdir('c')
 
201
        os.chmod('c', 02750)
 
202
        b = Branch.initialize('c')
 
203
        assertEqualMode(self, 02750, b._dir_mode)
 
204
        assertEqualMode(self, 00640, b._file_mode)
 
205
        check_mode_r(self, 'c/.bzr', 00640, 02750)
 
206
 
 
207
        os.mkdir('d')
 
208
        os.chmod('d', 0700)
 
209
        b = Branch.initialize('d')
 
210
        assertEqualMode(self, 0700, b._dir_mode)
 
211
        assertEqualMode(self, 0600, b._file_mode)
 
212
        check_mode_r(self, 'd/.bzr', 00600, 0700)
 
213
 
141
214
try:
142
215
    import paramiko
143
216
except ImportError: