~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

Added unit tests for find_unmerged

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
import os
19
 
import sys
20
 
import stat
21
19
from cStringIO import StringIO
22
20
 
23
21
from bzrlib.errors import (NoSuchFile, FileExists,
25
23
from bzrlib.tests import TestCase, TestCaseInTempDir
26
24
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
27
25
from bzrlib.transport import memory, urlescape
28
 
from bzrlib.osutils import pathjoin
29
26
 
30
27
 
31
28
def _append(fn, txt):
36
33
    f.close()
37
34
    del f
38
35
 
39
 
 
40
 
if sys.platform != 'win32':
41
 
    def check_mode(test, path, mode):
42
 
        """Check that a particular path has the correct mode."""
43
 
        actual_mode = stat.S_IMODE(os.stat(path).st_mode)
44
 
        test.assertEqual(mode, actual_mode,
45
 
            'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
46
 
else:
47
 
    def check_mode(test, path, mode):
48
 
        """On win32 chmod doesn't have any effect, 
49
 
        so don't actually check anything
50
 
        """
51
 
        return
52
 
 
53
 
 
54
36
class TestTransport(TestCase):
55
37
    """Test the non transport-concrete class functionality."""
56
38
 
113
95
        self.assertEqual(open('a', 'rb').read(), t.get('a').read())
114
96
        content_f = t.get_multi(files)
115
97
        for path,f in zip(files, content_f):
116
 
            self.assertEqual(f.read(), open(path, 'rb').read())
 
98
            self.assertEqual(open(path).read(), f.read())
117
99
 
118
100
        content_f = t.get_multi(iter(files))
119
101
        for path,f in zip(files, content_f):
120
 
            self.assertEqual(f.read(), open(path, 'rb').read())
 
102
            self.assertEqual(f.read(), open(path).read())
121
103
 
122
104
        self.assertRaises(NoSuchFile, t.get, 'c')
123
105
        self.assertListRaises(NoSuchFile, t.get_multi, ['a', 'b', 'c'])
126
108
    def test_put(self):
127
109
        t = self.get_transport()
128
110
 
129
 
        # TODO: jam 20051215 No need to do anything if the test is readonly
130
 
        #                    origininally it was thought that it would give
131
 
        #                    more of a workout to readonly tests. By now the
132
 
        #                    suite is probably thorough enough without testing
133
 
        #                    readonly protocols in write sections
134
 
        #                    The only thing that needs to be tested is that the
135
 
        #                    right error is raised
136
 
 
137
111
        if self.readonly:
138
112
            self.assertRaises(TransportNotPossible,
139
113
                    t.put, 'a', 'some text for a\n')
184
158
            self.assertRaises(NoSuchFile,
185
159
                    t.put, 'path/doesnt/exist/c', 'contents')
186
160
 
187
 
        if not self.readonly:
188
 
            t.put('mode644', 'test text\n', mode=0644)
189
 
            check_mode(self, 'mode644', 0644)
190
 
 
191
 
            t.put('mode666', 'test text\n', mode=0666)
192
 
            check_mode(self, 'mode666', 0666)
193
 
 
194
 
            t.put('mode600', 'test text\n', mode=0600)
195
 
            check_mode(self, 'mode600', 0600)
196
 
 
197
 
            # Yes, you can put a file such that it becomes readonly
198
 
            t.put('mode400', 'test text\n', mode=0400)
199
 
            check_mode(self, 'mode400', 0400)
200
 
 
201
 
            t.put_multi([('mmode644', 'text\n')], mode=0644)
202
 
            check_mode(self, 'mmode644', 0644)
203
 
 
204
 
        # TODO: jam 20051215 test put_multi with a mode. I didn't bother because
205
 
        #                    it seems most people don't like the _multi functions
206
 
 
207
161
    def test_put_file(self):
208
162
        t = self.get_transport()
209
163
 
258
212
        self.check_file_contents('f5', 'here is some text\nand a bit more\n')
259
213
        self.check_file_contents('f6', 'some text for the\nthird file created\n')
260
214
 
261
 
        if not self.readonly:
262
 
            sio = StringIO('test text\n')
263
 
            t.put('mode644', sio, mode=0644)
264
 
            check_mode(self, 'mode644', 0644)
265
 
 
266
 
            a = open('mode644', 'rb')
267
 
            t.put('mode666', a, mode=0666)
268
 
            check_mode(self, 'mode666', 0666)
269
 
 
270
 
            a = open('mode644', 'rb')
271
 
            t.put('mode600', a, mode=0600)
272
 
            check_mode(self, 'mode600', 0600)
273
 
 
274
 
            # Yes, you can put a file such that it becomes readonly
275
 
            a = open('mode644', 'rb')
276
 
            t.put('mode400', a, mode=0400)
277
 
            check_mode(self, 'mode400', 0400)
278
 
 
279
215
    def test_mkdir(self):
280
216
        t = self.get_transport()
281
217
 
342
278
                             ('dir_b/b', 'contents of dir_b/b')])
343
279
                          , 2)
344
280
        for f in ('dir_a/a', 'dir_b/b'):
345
 
            self.assertEqual(t.get(f).read(), open(f, 'rb').read())
346
 
 
347
 
        if not self.readonly:
348
 
            # Test mkdir with a mode
349
 
            t.mkdir('dmode755', mode=0755)
350
 
            check_mode(self, 'dmode755', 0755)
351
 
 
352
 
            t.mkdir('dmode555', mode=0555)
353
 
            check_mode(self, 'dmode555', 0555)
354
 
 
355
 
            t.mkdir('dmode777', mode=0777)
356
 
            check_mode(self, 'dmode777', 0777)
357
 
 
358
 
            t.mkdir('dmode700', mode=0700)
359
 
            check_mode(self, 'dmode700', 0700)
360
 
 
361
 
            # TODO: jam 20051215 test mkdir_multi with a mode
362
 
            t.mkdir_multi(['mdmode755'], mode=0755)
363
 
            check_mode(self, 'mdmode755', 0755)
364
 
 
 
281
            self.assertEqual(t.get(f).read(), open(f).read())
365
282
 
366
283
    def test_copy_to(self):
367
284
        import tempfile
372
289
        files = ['a', 'b', 'c', 'd']
373
290
        self.build_tree(files)
374
291
 
375
 
        def get_temp_local():
376
 
            dtmp = tempfile.mkdtemp(dir=u'.', prefix='test-transport-')
377
 
            dtmp_base = os.path.basename(dtmp)
378
 
            return dtmp_base, LocalTransport(dtmp)
379
 
        dtmp_base, local_t = get_temp_local()
 
292
        dtmp = tempfile.mkdtemp(dir=u'.', prefix='test-transport-')
 
293
        dtmp_base = os.path.basename(dtmp)
 
294
        local_t = LocalTransport(dtmp)
380
295
 
381
296
        t.copy_to(files, local_t)
382
297
        for f in files:
383
 
            self.assertEquals(open(f, 'rb').read(),
384
 
                    open(pathjoin(dtmp_base, f), 'rb').read())
 
298
            self.assertEquals(open(f).read(),
 
299
                    open(os.path.join(dtmp_base, f)).read())
385
300
 
386
301
        # Test that copying into a missing directory raises
387
302
        # NoSuchFile
389
304
        open('e/f', 'wb').write('contents of e')
390
305
        self.assertRaises(NoSuchFile, t.copy_to, ['e/f'], local_t)
391
306
 
392
 
        os.mkdir(pathjoin(dtmp_base, 'e'))
 
307
        os.mkdir(os.path.join(dtmp_base, 'e'))
393
308
        t.copy_to(['e/f'], local_t)
394
309
 
395
 
        del dtmp_base, local_t
 
310
        del dtmp, dtmp_base, local_t
396
311
 
397
 
        dtmp_base, local_t = get_temp_local()
 
312
        dtmp = tempfile.mkdtemp(dir=u'.', prefix='test-transport-')
 
313
        dtmp_base = os.path.basename(dtmp)
 
314
        local_t = LocalTransport(dtmp)
398
315
 
399
316
        files = ['a', 'b', 'c', 'd']
400
317
        t.copy_to(iter(files), local_t)
401
318
        for f in files:
402
 
            self.assertEquals(open(f, 'rb').read(),
403
 
                    open(pathjoin(dtmp_base, f), 'rb').read())
404
 
 
405
 
        del dtmp_base, local_t
406
 
 
407
 
        for mode in (0666, 0644, 0600, 0400):
408
 
            dtmp_base, local_t = get_temp_local()
409
 
            t.copy_to(files, local_t, mode=mode)
410
 
            for f in files:
411
 
                check_mode(self, os.path.join(dtmp_base, f), mode)
 
319
            self.assertEquals(open(f).read(),
 
320
                    open(os.path.join(dtmp_base, f)).read())
 
321
 
 
322
        del dtmp, dtmp_base, local_t
412
323
 
413
324
    def test_append(self):
414
325
        t = self.get_transport()