/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-08-21 09:32:52 UTC
  • mfrom: (7065.3.15 python-bundle)
  • Revision ID: breezy.the.bot@gmail.com-20180821093252-dhir83sygqwzbv77
Fix some bundle-related tests on Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/python-bundle/+merge/353123

Show diffs side-by-side

added added

removed removed

Lines of Context:
1202
1202
        self.build_tree(tree)
1203
1203
 
1204
1204
        # rename the 1file to a latin-1 filename
1205
 
        os.rename("./1file", "\xe8file")
1206
 
        if "\xe8file" not in os.listdir("."):
 
1205
        os.rename(b"./1file", b"\xe8file")
 
1206
        if b"\xe8file" not in os.listdir("."):
1207
1207
            self.skipTest("Lack filesystem that preserves arbitrary bytes")
1208
1208
 
1209
1209
        self._save_platform_info()
1211
1211
 
1212
1212
        # this should raise on error
1213
1213
        def attempt():
1214
 
            for dirdetail, dirblock in osutils.walkdirs('.'):
 
1214
            for dirdetail, dirblock in osutils.walkdirs(b'.'):
1215
1215
                pass
1216
1216
 
1217
1217
        self.assertRaises(errors.BadFilenameEncoding, attempt)
1245
1245
            ]
1246
1246
        result = []
1247
1247
        found_bzrdir = False
1248
 
        for dirdetail, dirblock in osutils._walkdirs_utf8('.'):
1249
 
            if len(dirblock) and dirblock[0][1] == '.bzr':
 
1248
        for dirdetail, dirblock in osutils._walkdirs_utf8(b'.'):
 
1249
            if len(dirblock) and dirblock[0][1] == b'.bzr':
1250
1250
                # this tests the filtering of selected paths
1251
1251
                found_bzrdir = True
1252
1252
                del dirblock[0]
 
1253
            dirdetail = (dirdetail[0].decode('utf-8'), dirdetail[1])
 
1254
            dirblock = [
 
1255
                    (entry[0].decode('utf-8'), entry[1].decode('utf-8'), entry[2])
 
1256
                    for entry in dirblock]
1253
1257
            result.append((dirdetail, dirblock))
1254
1258
 
1255
1259
        self.assertTrue(found_bzrdir)
1720
1724
                % (osutils.get_user_encoding(),))
1721
1725
 
1722
1726
        old = osutils.set_or_unset_env('BRZ_TEST_ENV_VAR', uni_val)
1723
 
        self.assertEqual(env_val, os.environ.get('BRZ_TEST_ENV_VAR'))
 
1727
        if PY3:
 
1728
            self.assertEqual(uni_val, os.environ.get('BRZ_TEST_ENV_VAR'))
 
1729
        else:
 
1730
            self.assertEqual(env_val, os.environ.get('BRZ_TEST_ENV_VAR'))
1724
1731
 
1725
1732
    def test_unset(self):
1726
1733
        """Test that passing None will remove the env var"""
2150
2157
        self.assertEqual(u'/home/\xa7test',
2151
2158
            osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2152
2159
        osutils._fs_enc = "iso8859-5"
2153
 
        self.assertEqual(u'/home/\u0407test',
2154
 
            osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2155
 
        osutils._fs_enc = "utf-8"
2156
 
        self.assertRaises(errors.BadFilenameEncoding,
2157
 
            osutils._posix_path_from_environ, 'BRZ_TEST_PATH')
 
2160
        if PY3:
 
2161
            # In Python 3, os.environ returns unicode.
 
2162
            self.assertEqual(u'/home/\xa7test',
 
2163
                osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2164
        else:
 
2165
            self.assertEqual(u'/home/\u0407test',
 
2166
                osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2167
            osutils._fs_enc = "utf-8"
 
2168
            self.assertRaises(errors.BadFilenameEncoding,
 
2169
                osutils._posix_path_from_environ, 'BRZ_TEST_PATH')
2158
2170
 
2159
2171
 
2160
2172
class TestGetHomeDir(tests.TestCase):
2180
2192
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2181
2193
        self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2182
2194
        osutils._fs_enc = "iso8859-5"
2183
 
        self.assertEqual(u'/home/\u0407test', osutils._posix_get_home_dir())
2184
 
        osutils._fs_enc = "utf-8"
2185
 
        self.assertRaises(errors.BadFilenameEncoding,
2186
 
            osutils._posix_get_home_dir)
 
2195
        if PY3:
 
2196
            # In python 3, os.environ returns unicode
 
2197
            self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
 
2198
        else:
 
2199
            self.assertEqual(u'/home/\u0407test', osutils._posix_get_home_dir())
 
2200
            osutils._fs_enc = "utf-8"
 
2201
            self.assertRaises(errors.BadFilenameEncoding,
 
2202
                osutils._posix_get_home_dir)
2187
2203
 
2188
2204
 
2189
2205
class TestGetuserUnicode(tests.TestCase):
2212
2228
                % (osutils.get_user_encoding(),))
2213
2229
        uni_username = u'jrandom' + uni_val
2214
2230
        encoded_username = uni_username.encode(ue)
2215
 
        self.overrideEnv(self.envvar_to_override(), encoded_username)
 
2231
        if PY3:
 
2232
            self.overrideEnv(self.envvar_to_override(), uni_username)
 
2233
        else:
 
2234
            self.overrideEnv(self.envvar_to_override(), encoded_username)
2216
2235
        self.assertEqual(uni_username, osutils.getuser_unicode())
2217
2236
 
2218
2237