~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Martin
  • Date: 2010-07-04 07:09:09 UTC
  • mto: This revision was merged to the branch mainline in revision 5333.
  • Revision ID: gzlist@googlemail.com-20100704070909-r51s2leny0wjcqtn
Use same timestamp rounding logic as Inno, just in case

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
24
25
import sys
25
26
import time
26
27
 
27
28
from bzrlib import (
28
29
    errors,
29
 
    lazy_regex,
30
30
    osutils,
31
 
    symbol_versioning,
32
31
    tests,
33
32
    trace,
34
33
    win32utils,
1071
1070
        if sys.platform == 'win32':
1072
1071
            raise tests.TestNotApplicable(
1073
1072
                "readdir IOError not tested on win32")
1074
 
        self.requireFeature(features.not_running_as_root)
1075
1073
        os.mkdir("test-unreadable")
1076
1074
        os.chmod("test-unreadable", 0000)
1077
1075
        # must chmod it back so that it can be removed
1707
1705
 
1708
1706
class TestReCompile(tests.TestCase):
1709
1707
 
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
 
 
1714
1708
    def test_re_compile_checked(self):
1715
 
        r = self._deprecated_re_compile_checked(r'A*', re.IGNORECASE)
 
1709
        r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
1716
1710
        self.assertTrue(r.match('aaaa'))
1717
1711
        self.assertTrue(r.match('aAaA'))
1718
1712
 
1719
1713
    def test_re_compile_checked_error(self):
1720
1714
        # 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()
1725
1715
        err = self.assertRaises(
1726
1716
            errors.BzrCommandError,
1727
 
            self._deprecated_re_compile_checked, '*', re.IGNORECASE, 'test case')
 
1717
            osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
1728
1718
        self.assertEqual(
1729
 
            'Invalid regular expression in test case: '
1730
 
            '"*" nothing to repeat',
 
1719
            "Invalid regular expression in test case: '*': "
 
1720
            "nothing to repeat",
1731
1721
            str(err))
1732
1722
 
1733
1723
 
2076
2066
 
2077
2067
    def test_unicode_user(self):
2078
2068
        ue = osutils.get_user_encoding()
2079
 
        uni_val, env_val = tests.probe_unicode_in_user_encoding()
2080
 
        if uni_val is None:
2081
 
            raise tests.TestSkipped(
2082
 
                'Cannot find a unicode character that works in encoding %s'
2083
 
                % (osutils.get_user_encoding(),))
2084
 
        uni_username = u'jrandom' + uni_val
2085
 
        encoded_username = uni_username.encode(ue)
2086
 
        osutils.set_or_unset_env('LOGNAME', encoded_username)
2087
 
        self.assertEqual(uni_username, osutils.getuser_unicode())
 
2069
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2070
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())