~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: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2016 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.assertEquals(['A', 'B'], shape)
 
183
        self.assertEqual(['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.assert_(osutils.is_inside_any(dirs, fn))
 
225
            self.assertTrue(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.assert_(osutils.is_inside_or_parent_of_any(dirs, fn))
 
237
            self.assertTrue(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.assertEquals('file', osutils.file_kind('file'))
302
 
        self.assertEquals('directory', osutils.file_kind('dir/'))
 
301
        self.assertEqual('file', osutils.file_kind('file'))
 
302
        self.assertEqual('directory', osutils.file_kind('dir/'))
303
303
        if osutils.has_symlinks():
304
304
            os.symlink('symlink', 'symlink')
305
 
            self.assertEquals('symlink', osutils.file_kind('symlink'))
 
305
            self.assertEqual('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.assertEquals('chardev', osutils.file_kind('/dev/null'))
 
314
            self.assertEqual('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.assertEquals('fifo', osutils.file_kind('fifo'))
 
320
                self.assertEqual('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.assertEquals('socket', osutils.file_kind('socket'))
 
329
                self.assertEqual('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)
928
929
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
929
930
        self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
930
931
        self.assertEqual('//HOST/path', osutils._win32_abspath(r'\\HOST\path'))
943
944
                         osutils._win32_pathjoin('path/to', 'C:/foo'))
944
945
        self.assertEqual('path/to/foo',
945
946
                         osutils._win32_pathjoin('path/to/', 'foo'))
946
 
        self.assertEqual('/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,
947
954
                         osutils._win32_pathjoin('C:/path/to/', '/foo'))
948
 
        self.assertEqual('/foo',
 
955
        self.assertEqual(expected,
949
956
                         osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
950
957
 
951
958
    def test_normpath(self):
971
978
        self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
972
979
 
973
980
    def test_win98_abspath(self):
 
981
        self.requireFeature(features.win32_feature)
974
982
        # absolute path
975
983
        self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
976
984
        self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
1197
1205
        # (It would be ok if it happened earlier but at the moment it
1198
1206
        # doesn't.)
1199
1207
        e = self.assertRaises(OSError, list, osutils._walkdirs_utf8("."))
1200
 
        self.assertEquals('./test-unreadable', e.filename)
1201
 
        self.assertEquals(errno.EACCES, e.errno)
 
1208
        self.assertEqual('./test-unreadable', e.filename)
 
1209
        self.assertEqual(errno.EACCES, e.errno)
1202
1210
        # Ensure the message contains the file name
1203
1211
        self.assertContainsRe(str(e), "\./test-unreadable")
1204
1212
 
1995
2003
        os.symlink(self.target, self.link)
1996
2004
 
1997
2005
    def test_os_readlink_link_encoding(self):
1998
 
        self.assertEquals(self.target,  os.readlink(self.link))
 
2006
        self.assertEqual(self.target,  os.readlink(self.link))
1999
2007
 
2000
2008
    def test_os_readlink_link_decoding(self):
2001
 
        self.assertEquals(self.target.encode(osutils._fs_enc),
 
2009
        self.assertEqual(self.target.encode(osutils._fs_enc),
2002
2010
                          os.readlink(self.link.encode(osutils._fs_enc)))
2003
2011
 
2004
2012
 
2024
2032
        self.overrideEnv('BZR_CONCURRENCY', '1')
2025
2033
        self.run_bzr('rocks --concurrency 42')
2026
2034
        # Command line overrides environment variable
2027
 
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
2028
 
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
 
2035
        self.assertEqual('42', os.environ['BZR_CONCURRENCY'])
 
2036
        self.assertEqual(42, osutils.local_concurrency(use_cache=False))
2029
2037
 
2030
2038
 
2031
2039
class TestFailedToLoadExtension(tests.TestCase):
2044
2052
    def test_failure_to_load(self):
2045
2053
        self._try_loading()
2046
2054
        self.assertLength(1, osutils._extension_load_failures)
2047
 
        self.assertEquals(osutils._extension_load_failures[0],
 
2055
        self.assertEqual(osutils._extension_load_failures[0],
2048
2056
            "No module named _fictional_extension_py")
2049
2057
 
2050
2058
    def test_report_extension_load_failures_no_warning(self):
2171
2179
        osutils.copy_ownership_from_path('test_file', ownsrc)
2172
2180
 
2173
2181
        s = os.stat(ownsrc)
2174
 
        self.assertEquals(self.path, 'test_file')
2175
 
        self.assertEquals(self.uid, s.st_uid)
2176
 
        self.assertEquals(self.gid, s.st_gid)
 
2182
        self.assertEqual(self.path, 'test_file')
 
2183
        self.assertEqual(self.uid, s.st_uid)
 
2184
        self.assertEqual(self.gid, s.st_gid)
2177
2185
 
2178
2186
    def test_copy_ownership_nonesrc(self):
2179
2187
        """copy_ownership_from_path test with src=None."""
2182
2190
        osutils.copy_ownership_from_path('test_file')
2183
2191
 
2184
2192
        s = os.stat('..')
2185
 
        self.assertEquals(self.path, 'test_file')
2186
 
        self.assertEquals(self.uid, s.st_uid)
2187
 
        self.assertEquals(self.gid, s.st_gid)
 
2193
        self.assertEqual(self.path, 'test_file')
 
2194
        self.assertEqual(self.uid, s.st_uid)
 
2195
        self.assertEqual(self.gid, s.st_gid)
2188
2196
 
2189
2197
 
2190
2198
class TestPathFromEnviron(tests.TestCase):