~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Andrew Bennetts
  • Date: 2010-07-28 07:05:19 UTC
  • mfrom: (5050.3.15 2.2)
  • mto: (5050.3.16 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100728070519-kkflohg6djas3ui4
Merge lp:bzr/2.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from bzrlib import (
29
29
    errors,
 
30
    lazy_regex,
30
31
    osutils,
 
32
    symbol_versioning,
31
33
    tests,
32
34
    trace,
33
35
    win32utils,
861
863
        self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
862
864
        # relative path
863
865
        cwd = osutils.getcwd().rstrip('/')
864
 
        drive = osutils._nt_splitdrive(cwd)[0]
 
866
        drive = osutils.ntpath.splitdrive(cwd)[0]
865
867
        self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
866
868
        self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
867
869
        # unicode path
1083
1085
        # Ensure the message contains the file name
1084
1086
        self.assertContainsRe(str(e), "\./test-unreadable")
1085
1087
 
 
1088
 
 
1089
    def test_walkdirs_encoding_error(self):
 
1090
        # <https://bugs.launchpad.net/bzr/+bug/488519>
 
1091
        # walkdirs didn't raise a useful message when the filenames
 
1092
        # are not using the filesystem's encoding
 
1093
 
 
1094
        # require a bytestring based filesystem
 
1095
        self.requireFeature(tests.ByteStringNamedFilesystem)
 
1096
 
 
1097
        tree = [
 
1098
            '.bzr',
 
1099
            '0file',
 
1100
            '1dir/',
 
1101
            '1dir/0file',
 
1102
            '1dir/1dir/',
 
1103
            '1file'
 
1104
            ]
 
1105
 
 
1106
        self.build_tree(tree)
 
1107
 
 
1108
        # rename the 1file to a latin-1 filename
 
1109
        os.rename("./1file", "\xe8file")
 
1110
 
 
1111
        self._save_platform_info()
 
1112
        win32utils.winver = None # Avoid the win32 detection code
 
1113
        osutils._fs_enc = 'UTF-8'
 
1114
 
 
1115
        # this should raise on error
 
1116
        def attempt():
 
1117
            for dirdetail, dirblock in osutils.walkdirs('.'):
 
1118
                pass
 
1119
 
 
1120
        self.assertRaises(errors.BadFilenameEncoding, attempt)
 
1121
 
1086
1122
    def test__walkdirs_utf8(self):
1087
1123
        tree = [
1088
1124
            '.bzr',
1671
1707
 
1672
1708
class TestReCompile(tests.TestCase):
1673
1709
 
 
1710
    def _deprecated_re_compile_checked(self, *args, **kwargs):
 
1711
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
1712
            osutils.re_compile_checked, *args, **kwargs)
 
1713
 
1674
1714
    def test_re_compile_checked(self):
1675
 
        r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
 
1715
        r = self._deprecated_re_compile_checked(r'A*', re.IGNORECASE)
1676
1716
        self.assertTrue(r.match('aaaa'))
1677
1717
        self.assertTrue(r.match('aAaA'))
1678
1718
 
1679
1719
    def test_re_compile_checked_error(self):
1680
1720
        # like https://bugs.launchpad.net/bzr/+bug/251352
 
1721
 
 
1722
        # Due to possible test isolation error, re.compile is not lazy at
 
1723
        # this point. We re-install lazy compile.
 
1724
        lazy_regex.install_lazy_compile()
1681
1725
        err = self.assertRaises(
1682
1726
            errors.BzrCommandError,
1683
 
            osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
 
1727
            self._deprecated_re_compile_checked, '*', re.IGNORECASE, 'test case')
1684
1728
        self.assertEqual(
1685
 
            "Invalid regular expression in test case: '*': "
1686
 
            "nothing to repeat",
 
1729
            'Invalid regular expression in test case: '
 
1730
            '"*" nothing to repeat',
1687
1731
            str(err))
1688
1732
 
1689
1733
 
1921
1965
    def restore_osutils_globals(self):
1922
1966
        osutils._terminal_size_state = self._orig_terminal_size_state
1923
1967
        osutils._first_terminal_size = self._orig_first_terminal_size
1924
 
        
 
1968
 
1925
1969
    def replace_stdout(self, new):
1926
1970
        self.overrideAttr(sys, 'stdout', new)
1927
1971