/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Daniel Watkins
  • Date: 2007-11-06 09:33:05 UTC
  • mfrom: (2967 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2993.
  • Revision ID: d.m.watkins@warwick.ac.uk-20071106093305-zfef3c0jbcvunnuz
Merged bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib.tests import (
38
38
        probe_unicode_in_user_encoding,
39
39
        StringIOWrapper,
 
40
        SymlinkFeature,
40
41
        TestCase,
41
42
        TestCaseInTempDir,
42
43
        TestSkipped,
250
251
        self.assertFormatedDelta('2 seconds in the future', -2)
251
252
 
252
253
    def test_dereference_path(self):
253
 
        if not osutils.has_symlinks():
254
 
            raise TestSkipped('Symlinks are not supported on this platform')
 
254
        self.requireFeature(SymlinkFeature)
255
255
        cwd = osutils.realpath('.')
256
256
        os.mkdir('bar')
257
257
        bar_path = osutils.pathjoin(cwd, 'bar')
277
277
        foo_baz_path = osutils.pathjoin(foo_path, 'baz')
278
278
        self.assertEqual(baz_path, osutils.dereference_path(foo_baz_path))
279
279
 
280
 
 
281
280
    def test_changing_access(self):
282
281
        f = file('file', 'w')
283
282
        f.write('monkey')
285
284
 
286
285
        # Make a file readonly
287
286
        osutils.make_readonly('file')
288
 
        mode = osutils.lstat('file').st_mode
 
287
        mode = os.lstat('file').st_mode
289
288
        self.assertEqual(mode, mode & 0777555)
290
289
 
291
290
        # Make a file writable
292
291
        osutils.make_writable('file')
293
 
        mode = osutils.lstat('file').st_mode
 
292
        mode = os.lstat('file').st_mode
294
293
        self.assertEqual(mode, mode | 0200)
295
294
 
296
295
        if osutils.has_symlinks():
299
298
            osutils.make_readonly('dangling')
300
299
            osutils.make_writable('dangling')
301
300
 
302
 
 
303
301
    def test_kind_marker(self):
304
302
        self.assertEqual("", osutils.kind_marker("file"))
305
303
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
350
348
class TestSafeRevisionId(TestCase):
351
349
 
352
350
    def test_from_ascii_string(self):
 
351
        # this shouldn't give a warning because it's getting an ascii string
353
352
        self.assertEqual('foobar', osutils.safe_revision_id('foobar'))
354
353
 
355
354
    def test_from_unicode_string_ascii_contents(self):
477
476
        #       osutils.getcwd() renormalize the path.
478
477
        self.assertEndsWith(osutils._win32_getcwd(), u'mu-\xb5')
479
478
 
 
479
    def test_minimum_path_selection(self):
 
480
        self.assertEqual(set(),
 
481
            osutils.minimum_path_selection([]))
 
482
        self.assertEqual(set(['a', 'b']),
 
483
            osutils.minimum_path_selection(['a', 'b']))
 
484
        self.assertEqual(set(['a/', 'b']),
 
485
            osutils.minimum_path_selection(['a/', 'b']))
 
486
        self.assertEqual(set(['a/', 'b']),
 
487
            osutils.minimum_path_selection(['a/c', 'a/', 'b']))
 
488
 
480
489
    def test_mkdtemp(self):
481
490
        tmpdir = osutils._win32_mkdtemp(dir='.')
482
491
        self.assertFalse('\\' in tmpdir)
928
937
        self.assertEqual(['c'], os.listdir('target/b'))
929
938
 
930
939
    def test_copy_tree_symlinks(self):
931
 
        if not osutils.has_symlinks():
932
 
            return
 
940
        self.requireFeature(SymlinkFeature)
933
941
        self.build_tree(['source/'])
934
942
        os.symlink('a/generic/path', 'source/lnk')
935
943
        osutils.copy_tree('source', 'target')
1039
1047
        self.assertTrue(isinstance(offset, int))
1040
1048
        eighteen_hours = 18 * 3600
1041
1049
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
 
1050
 
 
1051
 
 
1052
class TestShaFileByName(TestCaseInTempDir):
 
1053
 
 
1054
    def test_sha_empty(self):
 
1055
        self.build_tree_contents([('foo', '')])
 
1056
        expected_sha = osutils.sha_string('')
 
1057
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
 
1058
 
 
1059
    def test_sha_mixed_endings(self):
 
1060
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
 
1061
        self.build_tree_contents([('foo', text)])
 
1062
        expected_sha = osutils.sha_string(text)
 
1063
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))