~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Martin Packman
  • Date: 2012-01-04 11:33:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6422.
  • Revision ID: martin.packman@canonical.com-20120104113349-qbgh4edp244gq8i2
Factor out to test helper details on platform username retrieval

Show diffs side-by-side

added added

removed removed

Lines of Context:
2102
2102
        user = osutils.getuser_unicode()
2103
2103
        self.assertIsInstance(user, unicode)
2104
2104
 
 
2105
    def envvar_to_override(self):
 
2106
        if sys.platform == "win32":
 
2107
            # Disable use of platform calls on windows so envvar is used
 
2108
            self.overrideAttr(win32utils, 'has_ctypes', False)
 
2109
            return 'USERNAME' # only variable used on windows
 
2110
        return 'LOGNAME' # first variable checked by getpass.getuser()
 
2111
 
2105
2112
    def test_ascii_user(self):
2106
 
        # Disable use of platform calls on windows so envvar is used
2107
 
        self.overrideAttr(win32utils, 'has_ctypes', False)
2108
 
        self.overrideEnv('USERNAME', 'jrandom')
 
2113
        self.overrideEnv(self.envvar_to_override(), 'jrandom')
2109
2114
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
2110
2115
 
2111
2116
    def test_unicode_user(self):
2117
2122
                % (osutils.get_user_encoding(),))
2118
2123
        uni_username = u'jrandom' + uni_val
2119
2124
        encoded_username = uni_username.encode(ue)
2120
 
        # Disable use of platform calls on windows so envvar is used
2121
 
        self.overrideAttr(win32utils, 'has_ctypes', False)
2122
 
        self.overrideEnv('USERNAME', encoded_username)
 
2125
        var = self.envvar_to_override()
 
2126
        self.overrideEnv(var, encoded_username)
2123
2127
        self.assertEqual(uni_username, osutils.getuser_unicode())
2124
 
        self.overrideEnv('USERNAME', u'jrandom\xb6'.encode(ue))
 
2128
        self.overrideEnv(var, u'jrandom\xb6'.encode(ue))
2125
2129
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2126
2130
 
2127
2131