~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-12 09:49:24 UTC
  • mfrom: (6015.9.10 2.4)
  • mto: This revision was merged to the branch mainline in revision 6066.
  • Revision ID: v.ladeuil+lp@free.fr-20110812094924-knc5s0g7vs31a2f1
Merge 2.4 into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from bzrlib.tests.scenarios import load_tests_apply_scenarios
42
42
 
43
43
 
44
 
class _UTF8DirReaderFeature(tests.Feature):
 
44
class _UTF8DirReaderFeature(features.Feature):
45
45
 
46
46
    def _probe(self):
47
47
        try:
54
54
    def feature_name(self):
55
55
        return 'bzrlib._readdir_pyx'
56
56
 
57
 
UTF8DirReaderFeature = _UTF8DirReaderFeature()
 
57
UTF8DirReaderFeature = features.ModuleAvailableFeature('bzrlib._readdir_pyx')
58
58
 
59
 
term_ios_feature = tests.ModuleAvailableFeature('termios')
 
59
term_ios_feature = features.ModuleAvailableFeature('termios')
60
60
 
61
61
 
62
62
def _already_unicode(s):
429
429
class TestLinks(tests.TestCaseInTempDir):
430
430
 
431
431
    def test_dereference_path(self):
432
 
        self.requireFeature(tests.SymlinkFeature)
 
432
        self.requireFeature(features.SymlinkFeature)
433
433
        cwd = osutils.realpath('.')
434
434
        os.mkdir('bar')
435
435
        bar_path = osutils.pathjoin(cwd, 'bar')
482
482
 
483
483
class TestCanonicalRelPath(tests.TestCaseInTempDir):
484
484
 
485
 
    _test_needs_features = [tests.CaseInsCasePresFilenameFeature]
 
485
    _test_needs_features = [features.CaseInsCasePresFilenameFeature]
486
486
 
487
487
    def test_canonical_relpath_simple(self):
488
488
        f = file('MixedCaseName', 'w')
888
888
    """Test win32 functions that create files."""
889
889
 
890
890
    def test_getcwd(self):
891
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
891
        self.requireFeature(features.UnicodeFilenameFeature)
892
892
        os.mkdir(u'mu-\xb5')
893
893
        os.chdir(u'mu-\xb5')
894
894
        # TODO: jam 20060427 This will probably fail on Mac OSX because
984
984
    """Test mac special functions that require directories."""
985
985
 
986
986
    def test_getcwd(self):
987
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
987
        self.requireFeature(features.UnicodeFilenameFeature)
988
988
        os.mkdir(u'B\xe5gfors')
989
989
        os.chdir(u'B\xe5gfors')
990
990
        self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
991
991
 
992
992
    def test_getcwd_nonnorm(self):
993
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
993
        self.requireFeature(features.UnicodeFilenameFeature)
994
994
        # Test that _mac_getcwd() will normalize this path
995
995
        os.mkdir(u'Ba\u030agfors')
996
996
        os.chdir(u'Ba\u030agfors')
1106
1106
        # are not using the filesystem's encoding
1107
1107
 
1108
1108
        # require a bytestring based filesystem
1109
 
        self.requireFeature(tests.ByteStringNamedFilesystem)
 
1109
        self.requireFeature(features.ByteStringNamedFilesystem)
1110
1110
 
1111
1111
        tree = [
1112
1112
            '.bzr',
1207
1207
        self._save_platform_info()
1208
1208
        win32utils.winver = None # Avoid the win32 detection code
1209
1209
        osutils._fs_enc = 'UTF-8'
1210
 
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
 
1210
        self.assertDirReaderIs(
 
1211
            UTF8DirReaderFeature.module.UTF8DirReader)
1211
1212
 
1212
1213
    def test_force_walkdirs_utf8_fs_ascii(self):
1213
1214
        self.requireFeature(UTF8DirReaderFeature)
1214
1215
        self._save_platform_info()
1215
1216
        win32utils.winver = None # Avoid the win32 detection code
1216
1217
        osutils._fs_enc = 'US-ASCII'
1217
 
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
 
1218
        self.assertDirReaderIs(
 
1219
            UTF8DirReaderFeature.module.UTF8DirReader)
1218
1220
 
1219
1221
    def test_force_walkdirs_utf8_fs_ANSI(self):
1220
1222
        self.requireFeature(UTF8DirReaderFeature)
1221
1223
        self._save_platform_info()
1222
1224
        win32utils.winver = None # Avoid the win32 detection code
1223
1225
        osutils._fs_enc = 'ANSI_X3.4-1968'
1224
 
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
 
1226
        self.assertDirReaderIs(
 
1227
            UTF8DirReaderFeature.module.UTF8DirReader)
1225
1228
 
1226
1229
    def test_force_walkdirs_utf8_fs_latin1(self):
1227
1230
        self._save_platform_info()
1245
1248
 
1246
1249
    def test_unicode_walkdirs(self):
1247
1250
        """Walkdirs should always return unicode paths."""
1248
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1251
        self.requireFeature(features.UnicodeFilenameFeature)
1249
1252
        name0 = u'0file-\xb6'
1250
1253
        name1 = u'1dir-\u062c\u0648'
1251
1254
        name2 = u'2file-\u0633'
1288
1291
 
1289
1292
        The abspath portion might be in unicode or utf-8
1290
1293
        """
1291
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1294
        self.requireFeature(features.UnicodeFilenameFeature)
1292
1295
        name0 = u'0file-\xb6'
1293
1296
        name1 = u'1dir-\u062c\u0648'
1294
1297
        name2 = u'2file-\u0633'
1349
1352
 
1350
1353
        The abspath portion should be in unicode
1351
1354
        """
1352
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1355
        self.requireFeature(features.UnicodeFilenameFeature)
1353
1356
        # Use the unicode reader. TODO: split into driver-and-driven unit
1354
1357
        # tests.
1355
1358
        self._save_platform_info()
1396
1399
 
1397
1400
    def test__walkdirs_utf8_win32readdir(self):
1398
1401
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1399
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1402
        self.requireFeature(features.UnicodeFilenameFeature)
1400
1403
        from bzrlib._walkdirs_win32 import Win32ReadDir
1401
1404
        self._save_platform_info()
1402
1405
        osutils._selected_dir_reader = Win32ReadDir()
1453
1456
    def test__walkdirs_utf_win32_find_file_stat_file(self):
1454
1457
        """make sure our Stat values are valid"""
1455
1458
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1456
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1459
        self.requireFeature(features.UnicodeFilenameFeature)
1457
1460
        from bzrlib._walkdirs_win32 import Win32ReadDir
1458
1461
        name0u = u'0file-\xb6'
1459
1462
        name0 = name0u.encode('utf8')
1477
1480
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
1478
1481
        """make sure our Stat values are valid"""
1479
1482
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1480
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1483
        self.requireFeature(features.UnicodeFilenameFeature)
1481
1484
        from bzrlib._walkdirs_win32 import Win32ReadDir
1482
1485
        name0u = u'0dir-\u062c\u0648'
1483
1486
        name0 = name0u.encode('utf8')
1583
1586
        self.assertEqual(['c'], os.listdir('target/b'))
1584
1587
 
1585
1588
    def test_copy_tree_symlinks(self):
1586
 
        self.requireFeature(tests.SymlinkFeature)
 
1589
        self.requireFeature(features.SymlinkFeature)
1587
1590
        self.build_tree(['source/'])
1588
1591
        os.symlink('a/generic/path', 'source/lnk')
1589
1592
        osutils.copy_tree('source', 'target')
1856
1859
        return filtered_dirblocks
1857
1860
 
1858
1861
    def test_walk_unicode_tree(self):
1859
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1862
        self.requireFeature(features.UnicodeFilenameFeature)
1860
1863
        tree, expected_dirblocks = self._get_unicode_tree()
1861
1864
        self.build_tree(tree)
1862
1865
        result = list(osutils._walkdirs_utf8('.'))
1863
1866
        self.assertEqual(expected_dirblocks, self._filter_out(result))
1864
1867
 
1865
1868
    def test_symlink(self):
1866
 
        self.requireFeature(tests.SymlinkFeature)
1867
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1869
        self.requireFeature(features.SymlinkFeature)
 
1870
        self.requireFeature(features.UnicodeFilenameFeature)
1868
1871
        target = u'target\N{Euro Sign}'
1869
1872
        link_name = u'l\N{Euro Sign}nk'
1870
1873
        os.symlink(target, link_name)
1888
1891
    But prior python versions failed to properly encode the passed unicode
1889
1892
    string.
1890
1893
    """
1891
 
    _test_needs_features = [tests.SymlinkFeature, tests.UnicodeFilenameFeature]
 
1894
    _test_needs_features = [features.SymlinkFeature, features.UnicodeFilenameFeature]
1892
1895
 
1893
1896
    def setUp(self):
1894
1897
        super(tests.TestCaseInTempDir, self).setUp()