~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Merge cleanup into texinfo

Show diffs side-by-side

added added

removed removed

Lines of Context:
184
184
        shape = sorted(os.listdir('.'))
185
185
        self.assertEquals(['A', 'B'], shape)
186
186
 
187
 
    def test_rename_error(self):
188
 
        # We wrap os.rename to make it give an error including the filenames
189
 
        # https://bugs.launchpad.net/bzr/+bug/491763
190
 
        err = self.assertRaises(OSError, osutils.rename,
191
 
            'nonexistent', 'target')
192
 
        self.assertContainsString(str(err), 'nonexistent')
193
 
 
194
187
 
195
188
class TestRandChars(tests.TestCase):
196
189
 
868
861
        self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
869
862
        # relative path
870
863
        cwd = osutils.getcwd().rstrip('/')
871
 
        drive = osutils._nt_splitdrive(cwd)[0]
 
864
        drive = osutils.ntpath.splitdrive(cwd)[0]
872
865
        self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
873
866
        self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
874
867
        # unicode path
1071
1064
        self.assertExpectedBlocks(expected_dirblocks[1:], result)
1072
1065
 
1073
1066
    def test_walkdirs_os_error(self):
1074
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
 
1067
        # <https://bugs.launchpad.net/bzr/+bug/338653>
1075
1068
        # Pyrex readdir didn't raise useful messages if it had an error
1076
1069
        # reading the directory
1077
1070
        if sys.platform == 'win32':
1090
1083
        # Ensure the message contains the file name
1091
1084
        self.assertContainsRe(str(e), "\./test-unreadable")
1092
1085
 
 
1086
 
 
1087
    def test_walkdirs_encoding_error(self):
 
1088
        # <https://bugs.launchpad.net/bzr/+bug/488519>
 
1089
        # walkdirs didn't raise a useful message when the filenames
 
1090
        # are not using the filesystem's encoding
 
1091
 
 
1092
        # require a bytestring based filesystem
 
1093
        self.requireFeature(tests.ByteStringNamedFilesystem)
 
1094
 
 
1095
        tree = [
 
1096
            '.bzr',
 
1097
            '0file',
 
1098
            '1dir/',
 
1099
            '1dir/0file',
 
1100
            '1dir/1dir/',
 
1101
            '1file'
 
1102
            ]
 
1103
 
 
1104
        self.build_tree(tree)
 
1105
 
 
1106
        # rename the 1file to a latin-1 filename
 
1107
        os.rename("./1file", "\xe8file")
 
1108
 
 
1109
        self._save_platform_info()
 
1110
        win32utils.winver = None # Avoid the win32 detection code
 
1111
        osutils._fs_enc = 'UTF-8'
 
1112
 
 
1113
        # this should raise on error
 
1114
        def attempt():
 
1115
            for dirdetail, dirblock in osutils.walkdirs('.'):
 
1116
                pass
 
1117
 
 
1118
        self.assertRaises(errors.BadFilenameEncoding, attempt)
 
1119
 
1093
1120
    def test__walkdirs_utf8(self):
1094
1121
        tree = [
1095
1122
            '.bzr',
1917
1944
 
1918
1945
class TestTerminalWidth(tests.TestCase):
1919
1946
 
 
1947
    def setUp(self):
 
1948
        tests.TestCase.setUp(self)
 
1949
        self._orig_terminal_size_state = osutils._terminal_size_state
 
1950
        self._orig_first_terminal_size = osutils._first_terminal_size
 
1951
        self.addCleanup(self.restore_osutils_globals)
 
1952
        osutils._terminal_size_state = 'no_data'
 
1953
        osutils._first_terminal_size = None
 
1954
 
 
1955
    def restore_osutils_globals(self):
 
1956
        osutils._terminal_size_state = self._orig_terminal_size_state
 
1957
        osutils._first_terminal_size = self._orig_first_terminal_size
 
1958
 
1920
1959
    def replace_stdout(self, new):
1921
1960
        self.overrideAttr(sys, 'stdout', new)
1922
1961
 
2018
2057
        self.assertEquals(self.path, 'test_file')
2019
2058
        self.assertEquals(self.uid, s.st_uid)
2020
2059
        self.assertEquals(self.gid, s.st_gid)
 
2060
 
 
2061
class TestGetuserUnicode(tests.TestCase):
 
2062
 
 
2063
    def test_ascii_user(self):
 
2064
        osutils.set_or_unset_env('LOGNAME', 'jrandom')
 
2065
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
 
2066
 
 
2067
    def test_unicode_user(self):
 
2068
        ue = osutils.get_user_encoding()
 
2069
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2070
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())