/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

  • Committer: Jelmer Vernooij
  • Date: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

Show diffs side-by-side

added added

removed removed

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