~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os
22
22
import re
23
23
import socket
24
 
import stat
25
24
import sys
26
25
import time
27
26
 
39
38
    file_utils,
40
39
    test__walkdirs_win32,
41
40
    )
 
41
from bzrlib.tests.scenarios import load_tests_apply_scenarios
42
42
 
43
43
 
44
44
class _UTF8DirReaderFeature(tests.Feature):
97
97
    return scenarios
98
98
 
99
99
 
100
 
def load_tests(basic_tests, module, loader):
101
 
    suite = loader.suiteClass()
102
 
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
103
 
        basic_tests, tests.condition_isinstance(TestDirReader))
104
 
    tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
105
 
    suite.addTest(remaining_tests)
106
 
    return suite
 
100
load_tests = load_tests_apply_scenarios
107
101
 
108
102
 
109
103
class TestContainsWhitespace(tests.TestCase):
1072
1066
        if sys.platform == 'win32':
1073
1067
            raise tests.TestNotApplicable(
1074
1068
                "readdir IOError not tested on win32")
 
1069
        self.requireFeature(features.not_running_as_root)
1075
1070
        os.mkdir("test-unreadable")
1076
1071
        os.chmod("test-unreadable", 0000)
1077
1072
        # must chmod it back so that it can be removed
1107
1102
 
1108
1103
        # rename the 1file to a latin-1 filename
1109
1104
        os.rename("./1file", "\xe8file")
 
1105
        if "\xe8file" not in os.listdir("."):
 
1106
            self.skip("Lack filesystem that preserves arbitrary bytes")
1110
1107
 
1111
1108
        self._save_platform_info()
1112
1109
        win32utils.winver = None # Avoid the win32 detection code
1733
1730
 
1734
1731
class TestDirReader(tests.TestCaseInTempDir):
1735
1732
 
 
1733
    scenarios = dir_reader_scenarios()
 
1734
 
1736
1735
    # Set by load_tests
1737
1736
    _dir_reader_class = None
1738
1737
    _native_to_unicode = None
2076
2075
 
2077
2076
    def test_unicode_user(self):
2078
2077
        ue = osutils.get_user_encoding()
 
2078
        uni_val, env_val = tests.probe_unicode_in_user_encoding()
 
2079
        if uni_val is None:
 
2080
            raise tests.TestSkipped(
 
2081
                'Cannot find a unicode character that works in encoding %s'
 
2082
                % (osutils.get_user_encoding(),))
 
2083
        uni_username = u'jrandom' + uni_val
 
2084
        encoded_username = uni_username.encode(ue)
 
2085
        osutils.set_or_unset_env('LOGNAME', encoded_username)
 
2086
        self.assertEqual(uni_username, osutils.getuser_unicode())
2079
2087
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
2080
2088
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
 
2089
 
 
2090
class TestBackupNames(tests.TestCase):
 
2091
 
 
2092
    def setUp(self):
 
2093
        super(TestBackupNames, self).setUp()
 
2094
        self.backups = []
 
2095
 
 
2096
    def backup_exists(self, name):
 
2097
        return name in self.backups
 
2098
 
 
2099
    def available_backup_name(self, name):
 
2100
        backup_name = osutils.available_backup_name(name, self.backup_exists)
 
2101
        self.backups.append(backup_name)
 
2102
        return backup_name
 
2103
 
 
2104
    def assertBackupName(self, expected, name):
 
2105
        self.assertEqual(expected, self.available_backup_name(name))
 
2106
 
 
2107
    def test_empty(self):
 
2108
        self.assertBackupName('file.~1~', 'file')
 
2109
 
 
2110
    def test_existing(self):
 
2111
        self.available_backup_name('file')
 
2112
        self.available_backup_name('file')
 
2113
        self.assertBackupName('file.~3~', 'file')
 
2114
        # Empty slots are found, this is not a strict requirement and may be
 
2115
        # revisited if we test against all implementations.
 
2116
        self.backups.remove('file.~2~')
 
2117
        self.assertBackupName('file.~2~', 'file')