/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 breezy/tests/test_osutils.py

Support user.signingkey configuration variable in .git/config.

Merged from https://code.launchpad.net/~jelmer/brz/local-git-key/+merge/381000

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the osutils wrapper."""
18
18
 
 
19
from __future__ import absolute_import, division
 
20
 
19
21
import errno
20
 
from io import BytesIO
21
22
import os
22
23
import select
23
24
import socket
32
33
    trace,
33
34
    win32utils,
34
35
    )
 
36
from ..sixish import (
 
37
    BytesIO,
 
38
    PY3,
 
39
    text_type,
 
40
    )
35
41
from . import (
36
42
    features,
37
43
    file_utils,
399
405
        self.assertRaises(osutils.UnsupportedTimezoneFormat,
400
406
                          osutils.format_date, 0, timezone='foo')
401
407
        self.assertIsInstance(osutils.format_date(0), str)
402
 
        self.assertIsInstance(osutils.format_local_date(0), str)
 
408
        self.assertIsInstance(osutils.format_local_date(0), text_type)
403
409
        # Testing for the actual value of the local weekday without
404
410
        # duplicating the code from format_date is difficult.
405
411
        # Instead blackbox.test_locale should check for localized
941
947
                         osutils._win32_pathjoin('path/to/', 'foo'))
942
948
 
943
949
    def test_pathjoin_late_bugfix(self):
944
 
        expected = 'C:/foo'
 
950
        if sys.version_info < (2, 7, 6):
 
951
            expected = '/foo'
 
952
        else:
 
953
            expected = 'C:/foo'
945
954
        self.assertEqual(expected,
946
955
                         osutils._win32_pathjoin('C:/path/to/', '/foo'))
947
956
        self.assertEqual(expected,
1400
1409
        # all abspaths are Unicode, and encode them back into utf8.
1401
1410
        for dirdetail, dirblock in osutils._walkdirs_utf8('.'):
1402
1411
            self.assertIsInstance(dirdetail[0], bytes)
1403
 
            if isinstance(dirdetail[1], str):
 
1412
            if isinstance(dirdetail[1], text_type):
1404
1413
                dirdetail = (dirdetail[0], dirdetail[1].encode('utf8'))
1405
1414
                dirblock = [list(info) for info in dirblock]
1406
1415
                for info in dirblock:
1407
 
                    self.assertIsInstance(info[4], str)
 
1416
                    self.assertIsInstance(info[4], text_type)
1408
1417
                    info[4] = info[4].encode('utf8')
1409
1418
            new_dirblock = []
1410
1419
            for info in dirblock:
1731
1740
                % (osutils.get_user_encoding(),))
1732
1741
 
1733
1742
        osutils.set_or_unset_env('BRZ_TEST_ENV_VAR', uni_val)
1734
 
        self.assertEqual(uni_val, os.environ.get('BRZ_TEST_ENV_VAR'))
 
1743
        if PY3:
 
1744
            self.assertEqual(uni_val, os.environ.get('BRZ_TEST_ENV_VAR'))
 
1745
        else:
 
1746
            self.assertEqual(env_val, os.environ.get('BRZ_TEST_ENV_VAR'))
1735
1747
 
1736
1748
    def test_unset(self):
1737
1749
        """Test that passing None will remove the env var"""
1992
2004
    def test_failure_to_load(self):
1993
2005
        self._try_loading()
1994
2006
        self.assertLength(1, osutils._extension_load_failures)
1995
 
        self.assertEqual(
1996
 
            osutils._extension_load_failures[0],
1997
 
            "No module named 'breezy._fictional_extension_py'")
 
2007
        if PY3:
 
2008
            self.assertEqual(
 
2009
                osutils._extension_load_failures[0],
 
2010
                "No module named 'breezy._fictional_extension_py'")
 
2011
        else:
 
2012
            self.assertEqual(osutils._extension_load_failures[0],
 
2013
                             "No module named _fictional_extension_py")
1998
2014
 
1999
2015
    def test_report_extension_load_failures_no_warning(self):
2000
2016
        self.assertTrue(self._try_loading())
2142
2158
    def test_is_unicode(self):
2143
2159
        self.overrideEnv('BRZ_TEST_PATH', './anywhere at all/')
2144
2160
        path = osutils.path_from_environ('BRZ_TEST_PATH')
2145
 
        self.assertIsInstance(path, str)
 
2161
        self.assertIsInstance(path, text_type)
2146
2162
        self.assertEqual(u'./anywhere at all/', path)
2147
2163
 
2148
2164
    def test_posix_path_env_ascii(self):
2149
2165
        self.overrideEnv('BRZ_TEST_PATH', '/tmp')
2150
2166
        home = osutils._posix_path_from_environ('BRZ_TEST_PATH')
2151
 
        self.assertIsInstance(home, str)
 
2167
        self.assertIsInstance(home, text_type)
2152
2168
        self.assertEqual(u'/tmp', home)
2153
2169
 
2154
2170
    def test_posix_path_env_unicode(self):
2158
2174
        self.assertEqual(u'/home/\xa7test',
2159
2175
                         osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2160
2176
        osutils._fs_enc = "iso8859-5"
2161
 
        # In Python 3, os.environ returns unicode.
2162
 
        self.assertEqual(u'/home/\xa7test',
2163
 
                         osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2177
        if PY3:
 
2178
            # In Python 3, os.environ returns unicode.
 
2179
            self.assertEqual(u'/home/\xa7test',
 
2180
                             osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2181
        else:
 
2182
            self.assertEqual(u'/home/\u0407test',
 
2183
                             osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2184
            osutils._fs_enc = "utf-8"
 
2185
            self.assertRaises(
 
2186
                errors.BadFilenameEncoding,
 
2187
                osutils._posix_path_from_environ, 'BRZ_TEST_PATH')
2164
2188
 
2165
2189
 
2166
2190
class TestGetHomeDir(tests.TestCase):
2167
2191
 
2168
2192
    def test_is_unicode(self):
2169
2193
        home = osutils._get_home_dir()
2170
 
        self.assertIsInstance(home, str)
 
2194
        self.assertIsInstance(home, text_type)
2171
2195
 
2172
2196
    def test_posix_homeless(self):
2173
2197
        self.overrideEnv('HOME', None)
2174
2198
        home = osutils._get_home_dir()
2175
 
        self.assertIsInstance(home, str)
 
2199
        self.assertIsInstance(home, text_type)
2176
2200
 
2177
2201
    def test_posix_home_ascii(self):
2178
2202
        self.overrideEnv('HOME', '/home/test')
2179
2203
        home = osutils._posix_get_home_dir()
2180
 
        self.assertIsInstance(home, str)
 
2204
        self.assertIsInstance(home, text_type)
2181
2205
        self.assertEqual(u'/home/test', home)
2182
2206
 
2183
2207
    def test_posix_home_unicode(self):
2186
2210
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2187
2211
        self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2188
2212
        osutils._fs_enc = "iso8859-5"
2189
 
        # In python 3, os.environ returns unicode
2190
 
        self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
 
2213
        if PY3:
 
2214
            # In python 3, os.environ returns unicode
 
2215
            self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
 
2216
        else:
 
2217
            self.assertEqual(u'/home/\u0407test',
 
2218
                             osutils._posix_get_home_dir())
 
2219
            osutils._fs_enc = "utf-8"
 
2220
            self.assertRaises(errors.BadFilenameEncoding,
 
2221
                              osutils._posix_get_home_dir)
2191
2222
 
2192
2223
 
2193
2224
class TestGetuserUnicode(tests.TestCase):
2194
2225
 
2195
2226
    def test_is_unicode(self):
2196
2227
        user = osutils.getuser_unicode()
2197
 
        self.assertIsInstance(user, str)
 
2228
        self.assertIsInstance(user, text_type)
2198
2229
 
2199
2230
    def envvar_to_override(self):
2200
2231
        if sys.platform == "win32":
2216
2247
                % (osutils.get_user_encoding(),))
2217
2248
        uni_username = u'jrandom' + uni_val
2218
2249
        encoded_username = uni_username.encode(ue)
2219
 
        self.overrideEnv(self.envvar_to_override(), uni_username)
 
2250
        if PY3:
 
2251
            self.overrideEnv(self.envvar_to_override(), uni_username)
 
2252
        else:
 
2253
            self.overrideEnv(self.envvar_to_override(), encoded_username)
2220
2254
        self.assertEqual(uni_username, osutils.getuser_unicode())
2221
2255
 
2222
2256
 
2340
2374
 
2341
2375
    def test_returns_string_or_none(self):
2342
2376
        ret = osutils.get_fs_type(self.test_dir)
2343
 
        self.assertTrue(isinstance(ret, str) or ret is None)
 
2377
        self.assertTrue(isinstance(ret, text_type) or ret is None)
2344
2378
 
2345
2379
    def test_returns_most_specific(self):
2346
2380
        self.overrideAttr(