~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Merge previous attempt into current trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    errors,
30
30
    osutils,
31
31
    tests,
 
32
    trace,
32
33
    win32utils,
33
34
    )
34
35
from bzrlib.tests import (
 
36
    features,
35
37
    file_utils,
36
38
    test__walkdirs_win32,
37
39
    )
52
54
 
53
55
UTF8DirReaderFeature = _UTF8DirReaderFeature()
54
56
 
 
57
term_ios_feature = tests.ModuleAvailableFeature('termios')
 
58
 
55
59
 
56
60
def _already_unicode(s):
57
61
    return s
58
62
 
59
63
 
60
 
def _fs_enc_to_unicode(s):
61
 
    return s.decode(osutils._fs_enc)
62
 
 
63
 
 
64
64
def _utf8_to_unicode(s):
65
65
    return s.decode('UTF-8')
66
66
 
83
83
                          dict(_dir_reader_class=_readdir_pyx.UTF8DirReader,
84
84
                               _native_to_unicode=_utf8_to_unicode)))
85
85
 
86
 
    if test__walkdirs_win32.Win32ReadDirFeature.available():
 
86
    if test__walkdirs_win32.win32_readdir_feature.available():
87
87
        try:
88
88
            from bzrlib import _walkdirs_win32
89
 
            # TODO: check on windows, it may be that we need to use/add
90
 
            # safe_unicode instead of _fs_enc_to_unicode
91
89
            scenarios.append(
92
90
                ('win32',
93
91
                 dict(_dir_reader_class=_walkdirs_win32.Win32ReadDir,
94
 
                      _native_to_unicode=_fs_enc_to_unicode)))
 
92
                      _native_to_unicode=_already_unicode)))
95
93
        except ImportError:
96
94
            pass
97
95
    return scenarios
125
123
 
126
124
class TestRename(tests.TestCaseInTempDir):
127
125
 
 
126
    def create_file(self, filename, content):
 
127
        f = open(filename, 'wb')
 
128
        try:
 
129
            f.write(content)
 
130
        finally:
 
131
            f.close()
 
132
 
 
133
    def _fancy_rename(self, a, b):
 
134
        osutils.fancy_rename(a, b, rename_func=os.rename,
 
135
                             unlink_func=os.unlink)
 
136
 
128
137
    def test_fancy_rename(self):
129
138
        # This should work everywhere
130
 
        def rename(a, b):
131
 
            osutils.fancy_rename(a, b,
132
 
                    rename_func=os.rename,
133
 
                    unlink_func=os.unlink)
134
 
 
135
 
        open('a', 'wb').write('something in a\n')
136
 
        rename('a', 'b')
 
139
        self.create_file('a', 'something in a\n')
 
140
        self._fancy_rename('a', 'b')
137
141
        self.failIfExists('a')
138
142
        self.failUnlessExists('b')
139
143
        self.check_file_contents('b', 'something in a\n')
140
144
 
141
 
        open('a', 'wb').write('new something in a\n')
142
 
        rename('b', 'a')
 
145
        self.create_file('a', 'new something in a\n')
 
146
        self._fancy_rename('b', 'a')
143
147
 
144
148
        self.check_file_contents('a', 'something in a\n')
145
149
 
 
150
    def test_fancy_rename_fails_source_missing(self):
 
151
        # An exception should be raised, and the target should be left in place
 
152
        self.create_file('target', 'data in target\n')
 
153
        self.assertRaises((IOError, OSError), self._fancy_rename,
 
154
                          'missingsource', 'target')
 
155
        self.failUnlessExists('target')
 
156
        self.check_file_contents('target', 'data in target\n')
 
157
 
 
158
    def test_fancy_rename_fails_if_source_and_target_missing(self):
 
159
        self.assertRaises((IOError, OSError), self._fancy_rename,
 
160
                          'missingsource', 'missingtarget')
 
161
 
146
162
    def test_rename(self):
147
163
        # Rename should be semi-atomic on all platforms
148
 
        open('a', 'wb').write('something in a\n')
 
164
        self.create_file('a', 'something in a\n')
149
165
        osutils.rename('a', 'b')
150
166
        self.failIfExists('a')
151
167
        self.failUnlessExists('b')
152
168
        self.check_file_contents('b', 'something in a\n')
153
169
 
154
 
        open('a', 'wb').write('new something in a\n')
 
170
        self.create_file('a', 'new something in a\n')
155
171
        osutils.rename('b', 'a')
156
172
 
157
173
        self.check_file_contents('a', 'something in a\n')
294
310
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
295
311
        self.assertEqual("@", osutils.kind_marker("symlink"))
296
312
        self.assertEqual("+", osutils.kind_marker("tree-reference"))
297
 
        self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
 
313
        self.assertEqual("", osutils.kind_marker("fifo"))
 
314
        self.assertEqual("", osutils.kind_marker("socket"))
 
315
        self.assertEqual("", osutils.kind_marker("unknown"))
298
316
 
299
317
 
300
318
class TestUmask(tests.TestCaseInTempDir):
365
383
        # Instead blackbox.test_locale should check for localized
366
384
        # dates once they do occur in output strings.
367
385
 
 
386
    def test_format_date_with_offset_in_original_timezone(self):
 
387
        self.assertEqual("Thu 1970-01-01 00:00:00 +0000",
 
388
            osutils.format_date_with_offset_in_original_timezone(0))
 
389
        self.assertEqual("Fri 1970-01-02 03:46:40 +0000",
 
390
            osutils.format_date_with_offset_in_original_timezone(100000))
 
391
        self.assertEqual("Fri 1970-01-02 05:46:40 +0200",
 
392
            osutils.format_date_with_offset_in_original_timezone(100000, 7200))
 
393
 
368
394
    def test_local_time_offset(self):
369
395
        """Test that local_time_offset() returns a sane value."""
370
396
        offset = osutils.local_time_offset()
446
472
    def test_canonical_relpath_simple(self):
447
473
        f = file('MixedCaseName', 'w')
448
474
        f.close()
449
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
450
 
        real_base_dir = osutils.realpath(self.test_base_dir)
451
 
        actual = osutils.canonical_relpath(real_base_dir, 'mixedcasename')
 
475
        actual = osutils.canonical_relpath(self.test_base_dir, 'mixedcasename')
452
476
        self.failUnlessEqual('work/MixedCaseName', actual)
453
477
 
454
478
    def test_canonical_relpath_missing_tail(self):
455
479
        os.mkdir('MixedCaseParent')
456
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
457
 
        real_base_dir = osutils.realpath(self.test_base_dir)
458
 
        actual = osutils.canonical_relpath(real_base_dir,
 
480
        actual = osutils.canonical_relpath(self.test_base_dir,
459
481
                                           'mixedcaseparent/nochild')
460
482
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
461
483
 
462
484
 
 
485
class Test_CICPCanonicalRelpath(tests.TestCaseWithTransport):
 
486
 
 
487
    def assertRelpath(self, expected, base, path):
 
488
        actual = osutils._cicp_canonical_relpath(base, path)
 
489
        self.assertEqual(expected, actual)
 
490
 
 
491
    def test_simple(self):
 
492
        self.build_tree(['MixedCaseName'])
 
493
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
 
494
        self.assertRelpath('MixedCaseName', base, 'mixedcAsename')
 
495
 
 
496
    def test_subdir_missing_tail(self):
 
497
        self.build_tree(['MixedCaseParent/', 'MixedCaseParent/a_child'])
 
498
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
 
499
        self.assertRelpath('MixedCaseParent/a_child', base,
 
500
                           'MixedCaseParent/a_child')
 
501
        self.assertRelpath('MixedCaseParent/a_child', base,
 
502
                           'MixedCaseParent/A_Child')
 
503
        self.assertRelpath('MixedCaseParent/not_child', base,
 
504
                           'MixedCaseParent/not_child')
 
505
 
 
506
    def test_at_root_slash(self):
 
507
        # We can't test this on Windows, because it has a 'MIN_ABS_PATHLENGTH'
 
508
        # check...
 
509
        if osutils.MIN_ABS_PATHLENGTH > 1:
 
510
            raise tests.TestSkipped('relpath requires %d chars'
 
511
                                    % osutils.MIN_ABS_PATHLENGTH)
 
512
        self.assertRelpath('foo', '/', '/foo')
 
513
 
 
514
    def test_at_root_drive(self):
 
515
        if sys.platform != 'win32':
 
516
            raise tests.TestNotApplicable('we can only test drive-letter relative'
 
517
                                          ' paths on Windows where we have drive'
 
518
                                          ' letters.')
 
519
        # see bug #322807
 
520
        # The specific issue is that when at the root of a drive, 'abspath'
 
521
        # returns "C:/" or just "/". However, the code assumes that abspath
 
522
        # always returns something like "C:/foo" or "/foo" (no trailing slash).
 
523
        self.assertRelpath('foo', 'C:/', 'C:/foo')
 
524
        self.assertRelpath('foo', 'X:/', 'X:/foo')
 
525
        self.assertRelpath('foo', 'X:/', 'X://foo')
 
526
 
 
527
 
463
528
class TestPumpFile(tests.TestCase):
464
529
    """Test pumpfile method."""
465
530
 
625
690
        self.assertEqual("1234", output.getvalue())
626
691
 
627
692
 
 
693
class TestRelpath(tests.TestCase):
 
694
 
 
695
    def test_simple_relpath(self):
 
696
        cwd = osutils.getcwd()
 
697
        subdir = cwd + '/subdir'
 
698
        self.assertEqual('subdir', osutils.relpath(cwd, subdir))
 
699
 
 
700
    def test_deep_relpath(self):
 
701
        cwd = osutils.getcwd()
 
702
        subdir = cwd + '/sub/subsubdir'
 
703
        self.assertEqual('sub/subsubdir', osutils.relpath(cwd, subdir))
 
704
 
 
705
    def test_not_relative(self):
 
706
        self.assertRaises(errors.PathNotChild,
 
707
                          osutils.relpath, 'C:/path', 'H:/path')
 
708
        self.assertRaises(errors.PathNotChild,
 
709
                          osutils.relpath, 'C:/', 'H:/path')
 
710
 
 
711
 
628
712
class TestSafeUnicode(tests.TestCase):
629
713
 
630
714
    def test_from_ascii_string(self):
908
992
 
909
993
    def test_osutils_binding(self):
910
994
        from bzrlib.tests import test__chunks_to_lines
911
 
        if test__chunks_to_lines.CompiledChunksToLinesFeature.available():
 
995
        if test__chunks_to_lines.compiled_chunkstolines_feature.available():
912
996
            from bzrlib._chunks_to_lines_pyx import chunks_to_lines
913
997
        else:
914
998
            from bzrlib._chunks_to_lines_py import chunks_to_lines
980
1064
        self.assertExpectedBlocks(expected_dirblocks[1:], result)
981
1065
 
982
1066
    def test_walkdirs_os_error(self):
983
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
 
1067
        # <https://bugs.launchpad.net/bzr/+bug/338653>
984
1068
        # Pyrex readdir didn't raise useful messages if it had an error
985
1069
        # reading the directory
986
1070
        if sys.platform == 'win32':
1054
1138
            dirblock[:] = new_dirblock
1055
1139
 
1056
1140
    def _save_platform_info(self):
1057
 
        cur_winver = win32utils.winver
1058
 
        cur_fs_enc = osutils._fs_enc
1059
 
        cur_dir_reader = osutils._selected_dir_reader
1060
 
        def restore():
1061
 
            win32utils.winver = cur_winver
1062
 
            osutils._fs_enc = cur_fs_enc
1063
 
            osutils._selected_dir_reader = cur_dir_reader
1064
 
        self.addCleanup(restore)
 
1141
        self.overrideAttr(win32utils, 'winver')
 
1142
        self.overrideAttr(osutils, '_fs_enc')
 
1143
        self.overrideAttr(osutils, '_selected_dir_reader')
1065
1144
 
1066
1145
    def assertDirReaderIs(self, expected):
1067
1146
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1100
1179
 
1101
1180
    def test_force_walkdirs_utf8_nt(self):
1102
1181
        # Disabled because the thunk of the whole walkdirs api is disabled.
1103
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1182
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1104
1183
        self._save_platform_info()
1105
1184
        win32utils.winver = 'Windows NT'
1106
1185
        from bzrlib._walkdirs_win32 import Win32ReadDir
1107
1186
        self.assertDirReaderIs(Win32ReadDir)
1108
1187
 
1109
1188
    def test_force_walkdirs_utf8_98(self):
1110
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1189
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1111
1190
        self._save_platform_info()
1112
1191
        win32utils.winver = 'Windows 98'
1113
1192
        self.assertDirReaderIs(osutils.UnicodeDirReader)
1264
1343
        self.assertEqual(expected_dirblocks, result)
1265
1344
 
1266
1345
    def test__walkdirs_utf8_win32readdir(self):
1267
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1346
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1268
1347
        self.requireFeature(tests.UnicodeFilenameFeature)
1269
1348
        from bzrlib._walkdirs_win32 import Win32ReadDir
1270
1349
        self._save_platform_info()
1321
1400
 
1322
1401
    def test__walkdirs_utf_win32_find_file_stat_file(self):
1323
1402
        """make sure our Stat values are valid"""
1324
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1403
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1325
1404
        self.requireFeature(tests.UnicodeFilenameFeature)
1326
1405
        from bzrlib._walkdirs_win32 import Win32ReadDir
1327
1406
        name0u = u'0file-\xb6'
1345
1424
 
1346
1425
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
1347
1426
        """make sure our Stat values are valid"""
1348
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1427
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1349
1428
        self.requireFeature(tests.UnicodeFilenameFeature)
1350
1429
        from bzrlib._walkdirs_win32 import Win32ReadDir
1351
1430
        name0u = u'0dir-\u062c\u0648'
1500
1579
        def cleanup():
1501
1580
            if 'BZR_TEST_ENV_VAR' in os.environ:
1502
1581
                del os.environ['BZR_TEST_ENV_VAR']
1503
 
 
1504
1582
        self.addCleanup(cleanup)
1505
1583
 
1506
1584
    def test_set(self):
1554
1632
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
1555
1633
        self.build_tree_contents([('foo', text)])
1556
1634
        expected_sha = osutils.sha_string(text)
1557
 
        f = open('foo')
 
1635
        f = open('foo', 'rb')
1558
1636
        self.addCleanup(f.close)
1559
1637
        size, sha = osutils.size_sha_file(f)
1560
1638
        self.assertEqual(38, size)
1617
1695
 
1618
1696
    def setUp(self):
1619
1697
        tests.TestCaseInTempDir.setUp(self)
1620
 
 
1621
 
        # Save platform specific info and reset it
1622
 
        cur_dir_reader = osutils._selected_dir_reader
1623
 
 
1624
 
        def restore():
1625
 
            osutils._selected_dir_reader = cur_dir_reader
1626
 
        self.addCleanup(restore)
1627
 
 
1628
 
        osutils._selected_dir_reader = self._dir_reader_class()
 
1698
        self.overrideAttr(osutils,
 
1699
                          '_selected_dir_reader', self._dir_reader_class())
1629
1700
 
1630
1701
    def _get_ascii_tree(self):
1631
1702
        tree = [
1776
1847
 
1777
1848
class TestConcurrency(tests.TestCase):
1778
1849
 
 
1850
    def setUp(self):
 
1851
        super(TestConcurrency, self).setUp()
 
1852
        self.overrideAttr(osutils, '_cached_local_concurrency')
 
1853
 
1779
1854
    def test_local_concurrency(self):
1780
1855
        concurrency = osutils.local_concurrency()
1781
1856
        self.assertIsInstance(concurrency, int)
 
1857
 
 
1858
    def test_local_concurrency_environment_variable(self):
 
1859
        os.environ['BZR_CONCURRENCY'] = '2'
 
1860
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
 
1861
        os.environ['BZR_CONCURRENCY'] = '3'
 
1862
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
 
1863
        os.environ['BZR_CONCURRENCY'] = 'foo'
 
1864
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
 
1865
 
 
1866
    def test_option_concurrency(self):
 
1867
        os.environ['BZR_CONCURRENCY'] = '1'
 
1868
        self.run_bzr('rocks --concurrency 42')
 
1869
        # Command line overrides envrionment variable
 
1870
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
 
1871
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
 
1872
 
 
1873
 
 
1874
class TestFailedToLoadExtension(tests.TestCase):
 
1875
 
 
1876
    def _try_loading(self):
 
1877
        try:
 
1878
            import bzrlib._fictional_extension_py
 
1879
        except ImportError, e:
 
1880
            osutils.failed_to_load_extension(e)
 
1881
            return True
 
1882
 
 
1883
    def setUp(self):
 
1884
        super(TestFailedToLoadExtension, self).setUp()
 
1885
        self.overrideAttr(osutils, '_extension_load_failures', [])
 
1886
 
 
1887
    def test_failure_to_load(self):
 
1888
        self._try_loading()
 
1889
        self.assertLength(1, osutils._extension_load_failures)
 
1890
        self.assertEquals(osutils._extension_load_failures[0],
 
1891
            "No module named _fictional_extension_py")
 
1892
 
 
1893
    def test_report_extension_load_failures_no_warning(self):
 
1894
        self.assertTrue(self._try_loading())
 
1895
        warnings, result = self.callCatchWarnings(osutils.report_extension_load_failures)
 
1896
        # it used to give a Python warning; it no longer does
 
1897
        self.assertLength(0, warnings)
 
1898
 
 
1899
    def test_report_extension_load_failures_message(self):
 
1900
        log = StringIO()
 
1901
        trace.push_log_file(log)
 
1902
        self.assertTrue(self._try_loading())
 
1903
        osutils.report_extension_load_failures()
 
1904
        self.assertContainsRe(
 
1905
            log.getvalue(),
 
1906
            r"bzr: warning: some compiled extensions could not be loaded; "
 
1907
            "see <https://answers\.launchpad\.net/bzr/\+faq/703>\n"
 
1908
            )
 
1909
 
 
1910
 
 
1911
class TestTerminalWidth(tests.TestCase):
 
1912
 
 
1913
    def replace_stdout(self, new):
 
1914
        self.overrideAttr(sys, 'stdout', new)
 
1915
 
 
1916
    def replace__terminal_size(self, new):
 
1917
        self.overrideAttr(osutils, '_terminal_size', new)
 
1918
 
 
1919
    def set_fake_tty(self):
 
1920
 
 
1921
        class I_am_a_tty(object):
 
1922
            def isatty(self):
 
1923
                return True
 
1924
 
 
1925
        self.replace_stdout(I_am_a_tty())
 
1926
 
 
1927
    def test_default_values(self):
 
1928
        self.assertEqual(80, osutils.default_terminal_width)
 
1929
 
 
1930
    def test_defaults_to_BZR_COLUMNS(self):
 
1931
        # BZR_COLUMNS is set by the test framework
 
1932
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
 
1933
        os.environ['BZR_COLUMNS'] = '12'
 
1934
        self.assertEqual(12, osutils.terminal_width())
 
1935
 
 
1936
    def test_falls_back_to_COLUMNS(self):
 
1937
        del os.environ['BZR_COLUMNS']
 
1938
        self.assertNotEqual('42', os.environ['COLUMNS'])
 
1939
        self.set_fake_tty()
 
1940
        os.environ['COLUMNS'] = '42'
 
1941
        self.assertEqual(42, osutils.terminal_width())
 
1942
 
 
1943
    def test_tty_default_without_columns(self):
 
1944
        del os.environ['BZR_COLUMNS']
 
1945
        del os.environ['COLUMNS']
 
1946
 
 
1947
        def terminal_size(w, h):
 
1948
            return 42, 42
 
1949
 
 
1950
        self.set_fake_tty()
 
1951
        # We need to override the osutils definition as it depends on the
 
1952
        # running environment that we can't control (PQM running without a
 
1953
        # controlling terminal is one example).
 
1954
        self.replace__terminal_size(terminal_size)
 
1955
        self.assertEqual(42, osutils.terminal_width())
 
1956
 
 
1957
    def test_non_tty_default_without_columns(self):
 
1958
        del os.environ['BZR_COLUMNS']
 
1959
        del os.environ['COLUMNS']
 
1960
        self.replace_stdout(None)
 
1961
        self.assertEqual(None, osutils.terminal_width())
 
1962
 
 
1963
    def test_no_TIOCGWINSZ(self):
 
1964
        self.requireFeature(term_ios_feature)
 
1965
        termios = term_ios_feature.module
 
1966
        # bug 63539 is about a termios without TIOCGWINSZ attribute
 
1967
        try:
 
1968
            orig = termios.TIOCGWINSZ
 
1969
        except AttributeError:
 
1970
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
 
1971
            pass
 
1972
        else:
 
1973
            self.overrideAttr(termios, 'TIOCGWINSZ')
 
1974
            del termios.TIOCGWINSZ
 
1975
        del os.environ['BZR_COLUMNS']
 
1976
        del os.environ['COLUMNS']
 
1977
        # Whatever the result is, if we don't raise an exception, it's ok.
 
1978
        osutils.terminal_width()
 
1979
 
 
1980
class TestCreationOps(tests.TestCaseInTempDir):
 
1981
    _test_needs_features = [features.chown_feature]
 
1982
 
 
1983
    def setUp(self):
 
1984
        tests.TestCaseInTempDir.setUp(self)
 
1985
        self.overrideAttr(os, 'chown', self._dummy_chown)
 
1986
 
 
1987
        # params set by call to _dummy_chown
 
1988
        self.path = self.uid = self.gid = None
 
1989
 
 
1990
    def _dummy_chown(self, path, uid, gid):
 
1991
        self.path, self.uid, self.gid = path, uid, gid
 
1992
 
 
1993
    def test_copy_ownership_from_path(self):
 
1994
        """copy_ownership_from_path test with specified src."""
 
1995
        ownsrc = '/'
 
1996
        f = open('test_file', 'wt')
 
1997
        osutils.copy_ownership_from_path('test_file', ownsrc)
 
1998
 
 
1999
        s = os.stat(ownsrc)
 
2000
        self.assertEquals(self.path, 'test_file')
 
2001
        self.assertEquals(self.uid, s.st_uid)
 
2002
        self.assertEquals(self.gid, s.st_gid)
 
2003
 
 
2004
    def test_copy_ownership_nonesrc(self):
 
2005
        """copy_ownership_from_path test with src=None."""
 
2006
        f = open('test_file', 'wt')
 
2007
        # should use parent dir for permissions
 
2008
        osutils.copy_ownership_from_path('test_file')
 
2009
 
 
2010
        s = os.stat('..')
 
2011
        self.assertEquals(self.path, 'test_file')
 
2012
        self.assertEquals(self.uid, s.st_uid)
 
2013
        self.assertEquals(self.gid, s.st_gid)
 
2014
 
 
2015
class TestGetuserUnicode(tests.TestCase):
 
2016
 
 
2017
    def test_ascii_user(self):
 
2018
        osutils.set_or_unset_env('LOGNAME', 'jrandom')
 
2019
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
 
2020
 
 
2021
    def test_unicode_user(self):
 
2022
        ue = osutils.get_user_encoding()
 
2023
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2024
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())