~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-06 11:36:02 UTC
  • mfrom: (6462 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6463.
  • Revision ID: jelmer@samba.org-20120206113602-yu3j0xe7qbk1szw9
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2095
2095
        self.assertEquals(self.gid, s.st_gid)
2096
2096
 
2097
2097
 
 
2098
class TestPathFromEnviron(tests.TestCase):
 
2099
 
 
2100
    def test_is_unicode(self):
 
2101
        self.overrideEnv('BZR_TEST_PATH', './anywhere at all/')
 
2102
        path = osutils.path_from_environ('BZR_TEST_PATH')
 
2103
        self.assertIsInstance(path, unicode)
 
2104
        self.assertEqual(u'./anywhere at all/', path)
 
2105
 
 
2106
    def test_posix_path_env_ascii(self):
 
2107
        self.overrideEnv('BZR_TEST_PATH', '/tmp')
 
2108
        home = osutils._posix_path_from_environ('BZR_TEST_PATH')
 
2109
        self.assertIsInstance(home, unicode)
 
2110
        self.assertEqual(u'/tmp', home)
 
2111
 
 
2112
    def test_posix_path_env_unicode(self):
 
2113
        self.requireFeature(features.ByteStringNamedFilesystem)
 
2114
        self.overrideEnv('BZR_TEST_PATH', '/home/\xa7test')
 
2115
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
 
2116
        self.assertEqual(u'/home/\xa7test',
 
2117
            osutils._posix_path_from_environ('BZR_TEST_PATH'))
 
2118
        osutils._fs_enc = "iso8859-5"
 
2119
        self.assertEqual(u'/home/\u0407test',
 
2120
            osutils._posix_path_from_environ('BZR_TEST_PATH'))
 
2121
        osutils._fs_enc = "utf-8"
 
2122
        self.assertRaises(errors.BadFilenameEncoding,
 
2123
            osutils._posix_path_from_environ, 'BZR_TEST_PATH')
 
2124
 
 
2125
 
 
2126
class TestGetHomeDir(tests.TestCase):
 
2127
 
 
2128
    def test_is_unicode(self):
 
2129
        home = osutils._get_home_dir()
 
2130
        self.assertIsInstance(home, unicode)
 
2131
 
 
2132
    def test_posix_homeless(self):
 
2133
        self.overrideEnv('HOME', None)
 
2134
        home = osutils._get_home_dir()
 
2135
        self.assertIsInstance(home, unicode)
 
2136
 
 
2137
    def test_posix_home_ascii(self):
 
2138
        self.overrideEnv('HOME', '/home/test')
 
2139
        home = osutils._posix_get_home_dir()
 
2140
        self.assertIsInstance(home, unicode)
 
2141
        self.assertEqual(u'/home/test', home)
 
2142
 
 
2143
    def test_posix_home_unicode(self):
 
2144
        self.requireFeature(features.ByteStringNamedFilesystem)
 
2145
        self.overrideEnv('HOME', '/home/\xa7test')
 
2146
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
 
2147
        self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
 
2148
        osutils._fs_enc = "iso8859-5"
 
2149
        self.assertEqual(u'/home/\u0407test', osutils._posix_get_home_dir())
 
2150
        osutils._fs_enc = "utf-8"
 
2151
        self.assertRaises(errors.BadFilenameEncoding,
 
2152
            osutils._posix_get_home_dir)
 
2153
 
 
2154
 
2098
2155
class TestGetuserUnicode(tests.TestCase):
2099
2156
 
2100
2157
    def test_is_unicode(self):