~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Patch Queue Manager
  • Date: 2013-06-24 13:05:33 UTC
  • mfrom: (6578.1.1 2.6-merges-2.5)
  • Revision ID: pqm@pqm.ubuntu.com-20130624130533-51c8htekjd8mix3u
(jameinel) Merge bzr/2.5 into trunk,
 including the fix for bug #855155 (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
180
180
        # we can't use failUnlessExists on case-insensitive filesystem
181
181
        # so try to check shape of the tree
182
182
        shape = sorted(os.listdir('.'))
183
 
        self.assertEqual(['A', 'B'], shape)
 
183
        self.assertEquals(['A', 'B'], shape)
184
184
 
185
185
    def test_rename_exception(self):
186
186
        try:
222
222
                         (['src'], SRC_FOO_C),
223
223
                         (['src'], 'src'),
224
224
                         ]:
225
 
            self.assertTrue(osutils.is_inside_any(dirs, fn))
 
225
            self.assert_(osutils.is_inside_any(dirs, fn))
226
226
        for dirs, fn in [(['src'], 'srccontrol'),
227
227
                         (['src'], 'srccontrol/foo')]:
228
228
            self.assertFalse(osutils.is_inside_any(dirs, fn))
234
234
                         (['src/bar.c', 'bla/foo.c'], 'src'),
235
235
                         (['src'], 'src'),
236
236
                         ]:
237
 
            self.assertTrue(osutils.is_inside_or_parent_of_any(dirs, fn))
 
237
            self.assert_(osutils.is_inside_or_parent_of_any(dirs, fn))
238
238
 
239
239
        for dirs, fn in [(['src'], 'srccontrol'),
240
240
                         (['srccontrol/foo.c'], 'src'),
298
298
 
299
299
    def test_file_kind(self):
300
300
        self.build_tree(['file', 'dir/'])
301
 
        self.assertEqual('file', osutils.file_kind('file'))
302
 
        self.assertEqual('directory', osutils.file_kind('dir/'))
 
301
        self.assertEquals('file', osutils.file_kind('file'))
 
302
        self.assertEquals('directory', osutils.file_kind('dir/'))
303
303
        if osutils.has_symlinks():
304
304
            os.symlink('symlink', 'symlink')
305
 
            self.assertEqual('symlink', osutils.file_kind('symlink'))
 
305
            self.assertEquals('symlink', osutils.file_kind('symlink'))
306
306
 
307
307
        # TODO: jam 20060529 Test a block device
308
308
        try:
311
311
            if e.errno not in (errno.ENOENT,):
312
312
                raise
313
313
        else:
314
 
            self.assertEqual('chardev', osutils.file_kind('/dev/null'))
 
314
            self.assertEquals('chardev', osutils.file_kind('/dev/null'))
315
315
 
316
316
        mkfifo = getattr(os, 'mkfifo', None)
317
317
        if mkfifo:
318
318
            mkfifo('fifo')
319
319
            try:
320
 
                self.assertEqual('fifo', osutils.file_kind('fifo'))
 
320
                self.assertEquals('fifo', osutils.file_kind('fifo'))
321
321
            finally:
322
322
                os.remove('fifo')
323
323
 
326
326
            s = socket.socket(AF_UNIX)
327
327
            s.bind('socket')
328
328
            try:
329
 
                self.assertEqual('socket', osutils.file_kind('socket'))
 
329
                self.assertEquals('socket', osutils.file_kind('socket'))
330
330
            finally:
331
331
                os.remove('socket')
332
332
 
925
925
    """Test that _win32 versions of os utilities return appropriate paths."""
926
926
 
927
927
    def test_abspath(self):
928
 
        self.requireFeature(features.win32_feature)
929
928
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
930
929
        self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
931
930
        self.assertEqual('//HOST/path', osutils._win32_abspath(r'\\HOST\path'))
944
943
                         osutils._win32_pathjoin('path/to', 'C:/foo'))
945
944
        self.assertEqual('path/to/foo',
946
945
                         osutils._win32_pathjoin('path/to/', 'foo'))
947
 
 
948
 
    def test_pathjoin_late_bugfix(self):
949
 
        if sys.version_info < (2, 7, 6):
950
 
            expected = '/foo'
951
 
        else:
952
 
            expected = 'C:/foo'
953
 
        self.assertEqual(expected,
 
946
        self.assertEqual('/foo',
954
947
                         osutils._win32_pathjoin('C:/path/to/', '/foo'))
955
 
        self.assertEqual(expected,
 
948
        self.assertEqual('/foo',
956
949
                         osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
957
950
 
958
951
    def test_normpath(self):
978
971
        self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
979
972
 
980
973
    def test_win98_abspath(self):
981
 
        self.requireFeature(features.win32_feature)
982
974
        # absolute path
983
975
        self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
984
976
        self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
1205
1197
        # (It would be ok if it happened earlier but at the moment it
1206
1198
        # doesn't.)
1207
1199
        e = self.assertRaises(OSError, list, osutils._walkdirs_utf8("."))
1208
 
        self.assertEqual('./test-unreadable', e.filename)
1209
 
        self.assertEqual(errno.EACCES, e.errno)
 
1200
        self.assertEquals('./test-unreadable', e.filename)
 
1201
        self.assertEquals(errno.EACCES, e.errno)
1210
1202
        # Ensure the message contains the file name
1211
1203
        self.assertContainsRe(str(e), "\./test-unreadable")
1212
1204
 
2003
1995
        os.symlink(self.target, self.link)
2004
1996
 
2005
1997
    def test_os_readlink_link_encoding(self):
2006
 
        self.assertEqual(self.target,  os.readlink(self.link))
 
1998
        self.assertEquals(self.target,  os.readlink(self.link))
2007
1999
 
2008
2000
    def test_os_readlink_link_decoding(self):
2009
 
        self.assertEqual(self.target.encode(osutils._fs_enc),
 
2001
        self.assertEquals(self.target.encode(osutils._fs_enc),
2010
2002
                          os.readlink(self.link.encode(osutils._fs_enc)))
2011
2003
 
2012
2004
 
2032
2024
        self.overrideEnv('BZR_CONCURRENCY', '1')
2033
2025
        self.run_bzr('rocks --concurrency 42')
2034
2026
        # Command line overrides environment variable
2035
 
        self.assertEqual('42', os.environ['BZR_CONCURRENCY'])
2036
 
        self.assertEqual(42, osutils.local_concurrency(use_cache=False))
 
2027
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
 
2028
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
2037
2029
 
2038
2030
 
2039
2031
class TestFailedToLoadExtension(tests.TestCase):
2052
2044
    def test_failure_to_load(self):
2053
2045
        self._try_loading()
2054
2046
        self.assertLength(1, osutils._extension_load_failures)
2055
 
        self.assertEqual(osutils._extension_load_failures[0],
 
2047
        self.assertEquals(osutils._extension_load_failures[0],
2056
2048
            "No module named _fictional_extension_py")
2057
2049
 
2058
2050
    def test_report_extension_load_failures_no_warning(self):
2179
2171
        osutils.copy_ownership_from_path('test_file', ownsrc)
2180
2172
 
2181
2173
        s = os.stat(ownsrc)
2182
 
        self.assertEqual(self.path, 'test_file')
2183
 
        self.assertEqual(self.uid, s.st_uid)
2184
 
        self.assertEqual(self.gid, s.st_gid)
 
2174
        self.assertEquals(self.path, 'test_file')
 
2175
        self.assertEquals(self.uid, s.st_uid)
 
2176
        self.assertEquals(self.gid, s.st_gid)
2185
2177
 
2186
2178
    def test_copy_ownership_nonesrc(self):
2187
2179
        """copy_ownership_from_path test with src=None."""
2190
2182
        osutils.copy_ownership_from_path('test_file')
2191
2183
 
2192
2184
        s = os.stat('..')
2193
 
        self.assertEqual(self.path, 'test_file')
2194
 
        self.assertEqual(self.uid, s.st_uid)
2195
 
        self.assertEqual(self.gid, s.st_gid)
 
2185
        self.assertEquals(self.path, 'test_file')
 
2186
        self.assertEquals(self.uid, s.st_uid)
 
2187
        self.assertEquals(self.gid, s.st_gid)
2196
2188
 
2197
2189
 
2198
2190
class TestPathFromEnviron(tests.TestCase):