/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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,
33
32
    win32utils,
34
33
    )
35
34
from bzrlib.tests import (
36
 
    features,
37
35
    file_utils,
38
36
    test__walkdirs_win32,
39
37
    )
54
52
 
55
53
UTF8DirReaderFeature = _UTF8DirReaderFeature()
56
54
 
57
 
term_ios_feature = tests.ModuleAvailableFeature('termios')
58
 
 
59
55
 
60
56
def _already_unicode(s):
61
57
    return s
62
58
 
63
59
 
 
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.win32_readdir_feature.available():
 
86
    if test__walkdirs_win32.Win32ReadDirFeature.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
89
91
            scenarios.append(
90
92
                ('win32',
91
93
                 dict(_dir_reader_class=_walkdirs_win32.Win32ReadDir,
92
 
                      _native_to_unicode=_already_unicode)))
 
94
                      _native_to_unicode=_fs_enc_to_unicode)))
93
95
        except ImportError:
94
96
            pass
95
97
    return scenarios
123
125
 
124
126
class TestRename(tests.TestCaseInTempDir):
125
127
 
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
 
 
137
128
    def test_fancy_rename(self):
138
129
        # This should work everywhere
139
 
        self.create_file('a', 'something in a\n')
140
 
        self._fancy_rename('a', 'b')
 
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')
141
137
        self.failIfExists('a')
142
138
        self.failUnlessExists('b')
143
139
        self.check_file_contents('b', 'something in a\n')
144
140
 
145
 
        self.create_file('a', 'new something in a\n')
146
 
        self._fancy_rename('b', 'a')
 
141
        open('a', 'wb').write('new something in a\n')
 
142
        rename('b', 'a')
147
143
 
148
144
        self.check_file_contents('a', 'something in a\n')
149
145
 
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
 
 
162
146
    def test_rename(self):
163
147
        # Rename should be semi-atomic on all platforms
164
 
        self.create_file('a', 'something in a\n')
 
148
        open('a', 'wb').write('something in a\n')
165
149
        osutils.rename('a', 'b')
166
150
        self.failIfExists('a')
167
151
        self.failUnlessExists('b')
168
152
        self.check_file_contents('b', 'something in a\n')
169
153
 
170
 
        self.create_file('a', 'new something in a\n')
 
154
        open('a', 'wb').write('new something in a\n')
171
155
        osutils.rename('b', 'a')
172
156
 
173
157
        self.check_file_contents('a', 'something in a\n')
184
168
        shape = sorted(os.listdir('.'))
185
169
        self.assertEquals(['A', 'B'], shape)
186
170
 
187
 
    def test_rename_error(self):
188
 
        # We wrap os.rename to make it give an error including the filenames
189
 
        # https://bugs.launchpad.net/bzr/+bug/491763
190
 
        err = self.assertRaises(OSError, osutils.rename,
191
 
            'nonexistent', 'target')
192
 
        self.assertContainsString(str(err), 'nonexistent')
193
 
 
194
171
 
195
172
class TestRandChars(tests.TestCase):
196
173
 
263
240
        self.failIfExists('dir')
264
241
 
265
242
 
266
 
class TestDeleteAny(tests.TestCaseInTempDir):
267
 
 
268
 
    def test_delete_any_readonly(self):
269
 
        # from <https://bugs.launchpad.net/bzr/+bug/218206>
270
 
        self.build_tree(['d/', 'f'])
271
 
        osutils.make_readonly('d')
272
 
        osutils.make_readonly('f')
273
 
 
274
 
        osutils.delete_any('f')
275
 
        osutils.delete_any('d')
276
 
 
277
 
 
278
243
class TestKind(tests.TestCaseInTempDir):
279
244
 
280
245
    def test_file_kind(self):
317
282
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
318
283
        self.assertEqual("@", osutils.kind_marker("symlink"))
319
284
        self.assertEqual("+", osutils.kind_marker("tree-reference"))
320
 
        self.assertEqual("", osutils.kind_marker("fifo"))
321
 
        self.assertEqual("", osutils.kind_marker("socket"))
322
 
        self.assertEqual("", osutils.kind_marker("unknown"))
 
285
        self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
323
286
 
324
287
 
325
288
class TestUmask(tests.TestCaseInTempDir):
390
353
        # Instead blackbox.test_locale should check for localized
391
354
        # dates once they do occur in output strings.
392
355
 
393
 
    def test_format_date_with_offset_in_original_timezone(self):
394
 
        self.assertEqual("Thu 1970-01-01 00:00:00 +0000",
395
 
            osutils.format_date_with_offset_in_original_timezone(0))
396
 
        self.assertEqual("Fri 1970-01-02 03:46:40 +0000",
397
 
            osutils.format_date_with_offset_in_original_timezone(100000))
398
 
        self.assertEqual("Fri 1970-01-02 05:46:40 +0200",
399
 
            osutils.format_date_with_offset_in_original_timezone(100000, 7200))
400
 
 
401
356
    def test_local_time_offset(self):
402
357
        """Test that local_time_offset() returns a sane value."""
403
358
        offset = osutils.local_time_offset()
479
434
    def test_canonical_relpath_simple(self):
480
435
        f = file('MixedCaseName', 'w')
481
436
        f.close()
482
 
        actual = osutils.canonical_relpath(self.test_base_dir, 'mixedcasename')
 
437
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
 
438
        real_base_dir = osutils.realpath(self.test_base_dir)
 
439
        actual = osutils.canonical_relpath(real_base_dir, 'mixedcasename')
483
440
        self.failUnlessEqual('work/MixedCaseName', actual)
484
441
 
485
442
    def test_canonical_relpath_missing_tail(self):
486
443
        os.mkdir('MixedCaseParent')
487
 
        actual = osutils.canonical_relpath(self.test_base_dir,
 
444
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
 
445
        real_base_dir = osutils.realpath(self.test_base_dir)
 
446
        actual = osutils.canonical_relpath(real_base_dir,
488
447
                                           'mixedcaseparent/nochild')
489
448
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
490
449
 
491
450
 
492
 
class Test_CICPCanonicalRelpath(tests.TestCaseWithTransport):
493
 
 
494
 
    def assertRelpath(self, expected, base, path):
495
 
        actual = osutils._cicp_canonical_relpath(base, path)
496
 
        self.assertEqual(expected, actual)
497
 
 
498
 
    def test_simple(self):
499
 
        self.build_tree(['MixedCaseName'])
500
 
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
501
 
        self.assertRelpath('MixedCaseName', base, 'mixedcAsename')
502
 
 
503
 
    def test_subdir_missing_tail(self):
504
 
        self.build_tree(['MixedCaseParent/', 'MixedCaseParent/a_child'])
505
 
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
506
 
        self.assertRelpath('MixedCaseParent/a_child', base,
507
 
                           'MixedCaseParent/a_child')
508
 
        self.assertRelpath('MixedCaseParent/a_child', base,
509
 
                           'MixedCaseParent/A_Child')
510
 
        self.assertRelpath('MixedCaseParent/not_child', base,
511
 
                           'MixedCaseParent/not_child')
512
 
 
513
 
    def test_at_root_slash(self):
514
 
        # We can't test this on Windows, because it has a 'MIN_ABS_PATHLENGTH'
515
 
        # check...
516
 
        if osutils.MIN_ABS_PATHLENGTH > 1:
517
 
            raise tests.TestSkipped('relpath requires %d chars'
518
 
                                    % osutils.MIN_ABS_PATHLENGTH)
519
 
        self.assertRelpath('foo', '/', '/foo')
520
 
 
521
 
    def test_at_root_drive(self):
522
 
        if sys.platform != 'win32':
523
 
            raise tests.TestNotApplicable('we can only test drive-letter relative'
524
 
                                          ' paths on Windows where we have drive'
525
 
                                          ' letters.')
526
 
        # see bug #322807
527
 
        # The specific issue is that when at the root of a drive, 'abspath'
528
 
        # returns "C:/" or just "/". However, the code assumes that abspath
529
 
        # always returns something like "C:/foo" or "/foo" (no trailing slash).
530
 
        self.assertRelpath('foo', 'C:/', 'C:/foo')
531
 
        self.assertRelpath('foo', 'X:/', 'X:/foo')
532
 
        self.assertRelpath('foo', 'X:/', 'X://foo')
533
 
 
534
 
 
535
451
class TestPumpFile(tests.TestCase):
536
452
    """Test pumpfile method."""
537
453
 
697
613
        self.assertEqual("1234", output.getvalue())
698
614
 
699
615
 
700
 
class TestRelpath(tests.TestCase):
701
 
 
702
 
    def test_simple_relpath(self):
703
 
        cwd = osutils.getcwd()
704
 
        subdir = cwd + '/subdir'
705
 
        self.assertEqual('subdir', osutils.relpath(cwd, subdir))
706
 
 
707
 
    def test_deep_relpath(self):
708
 
        cwd = osutils.getcwd()
709
 
        subdir = cwd + '/sub/subsubdir'
710
 
        self.assertEqual('sub/subsubdir', osutils.relpath(cwd, subdir))
711
 
 
712
 
    def test_not_relative(self):
713
 
        self.assertRaises(errors.PathNotChild,
714
 
                          osutils.relpath, 'C:/path', 'H:/path')
715
 
        self.assertRaises(errors.PathNotChild,
716
 
                          osutils.relpath, 'C:/', 'H:/path')
717
 
 
718
 
 
719
616
class TestSafeUnicode(tests.TestCase):
720
617
 
721
618
    def test_from_ascii_string(self):
999
896
 
1000
897
    def test_osutils_binding(self):
1001
898
        from bzrlib.tests import test__chunks_to_lines
1002
 
        if test__chunks_to_lines.compiled_chunkstolines_feature.available():
 
899
        if test__chunks_to_lines.CompiledChunksToLinesFeature.available():
1003
900
            from bzrlib._chunks_to_lines_pyx import chunks_to_lines
1004
901
        else:
1005
902
            from bzrlib._chunks_to_lines_py import chunks_to_lines
1145
1042
            dirblock[:] = new_dirblock
1146
1043
 
1147
1044
    def _save_platform_info(self):
1148
 
        self.overrideAttr(win32utils, 'winver')
1149
 
        self.overrideAttr(osutils, '_fs_enc')
1150
 
        self.overrideAttr(osutils, '_selected_dir_reader')
 
1045
        cur_winver = win32utils.winver
 
1046
        cur_fs_enc = osutils._fs_enc
 
1047
        cur_dir_reader = osutils._selected_dir_reader
 
1048
        def restore():
 
1049
            win32utils.winver = cur_winver
 
1050
            osutils._fs_enc = cur_fs_enc
 
1051
            osutils._selected_dir_reader = cur_dir_reader
 
1052
        self.addCleanup(restore)
1151
1053
 
1152
1054
    def assertDirReaderIs(self, expected):
1153
1055
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1186
1088
 
1187
1089
    def test_force_walkdirs_utf8_nt(self):
1188
1090
        # Disabled because the thunk of the whole walkdirs api is disabled.
1189
 
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
1091
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1190
1092
        self._save_platform_info()
1191
1093
        win32utils.winver = 'Windows NT'
1192
1094
        from bzrlib._walkdirs_win32 import Win32ReadDir
1193
1095
        self.assertDirReaderIs(Win32ReadDir)
1194
1096
 
1195
1097
    def test_force_walkdirs_utf8_98(self):
1196
 
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
1098
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1197
1099
        self._save_platform_info()
1198
1100
        win32utils.winver = 'Windows 98'
1199
1101
        self.assertDirReaderIs(osutils.UnicodeDirReader)
1350
1252
        self.assertEqual(expected_dirblocks, result)
1351
1253
 
1352
1254
    def test__walkdirs_utf8_win32readdir(self):
1353
 
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
1255
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1354
1256
        self.requireFeature(tests.UnicodeFilenameFeature)
1355
1257
        from bzrlib._walkdirs_win32 import Win32ReadDir
1356
1258
        self._save_platform_info()
1407
1309
 
1408
1310
    def test__walkdirs_utf_win32_find_file_stat_file(self):
1409
1311
        """make sure our Stat values are valid"""
1410
 
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
1312
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1411
1313
        self.requireFeature(tests.UnicodeFilenameFeature)
1412
1314
        from bzrlib._walkdirs_win32 import Win32ReadDir
1413
1315
        name0u = u'0file-\xb6'
1431
1333
 
1432
1334
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
1433
1335
        """make sure our Stat values are valid"""
1434
 
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
1336
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1435
1337
        self.requireFeature(tests.UnicodeFilenameFeature)
1436
1338
        from bzrlib._walkdirs_win32 import Win32ReadDir
1437
1339
        name0u = u'0dir-\u062c\u0648'
1586
1488
        def cleanup():
1587
1489
            if 'BZR_TEST_ENV_VAR' in os.environ:
1588
1490
                del os.environ['BZR_TEST_ENV_VAR']
 
1491
 
1589
1492
        self.addCleanup(cleanup)
1590
1493
 
1591
1494
    def test_set(self):
1639
1542
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
1640
1543
        self.build_tree_contents([('foo', text)])
1641
1544
        expected_sha = osutils.sha_string(text)
1642
 
        f = open('foo', 'rb')
 
1545
        f = open('foo')
1643
1546
        self.addCleanup(f.close)
1644
1547
        size, sha = osutils.size_sha_file(f)
1645
1548
        self.assertEqual(38, size)
1702
1605
 
1703
1606
    def setUp(self):
1704
1607
        tests.TestCaseInTempDir.setUp(self)
1705
 
        self.overrideAttr(osutils,
1706
 
                          '_selected_dir_reader', self._dir_reader_class())
 
1608
 
 
1609
        # Save platform specific info and reset it
 
1610
        cur_dir_reader = osutils._selected_dir_reader
 
1611
 
 
1612
        def restore():
 
1613
            osutils._selected_dir_reader = cur_dir_reader
 
1614
        self.addCleanup(restore)
 
1615
 
 
1616
        osutils._selected_dir_reader = self._dir_reader_class()
1707
1617
 
1708
1618
    def _get_ascii_tree(self):
1709
1619
        tree = [
1854
1764
 
1855
1765
class TestConcurrency(tests.TestCase):
1856
1766
 
1857
 
    def setUp(self):
1858
 
        super(TestConcurrency, self).setUp()
1859
 
        self.overrideAttr(osutils, '_cached_local_concurrency')
1860
 
 
1861
1767
    def test_local_concurrency(self):
1862
1768
        concurrency = osutils.local_concurrency()
1863
1769
        self.assertIsInstance(concurrency, int)
1864
 
 
1865
 
    def test_local_concurrency_environment_variable(self):
1866
 
        os.environ['BZR_CONCURRENCY'] = '2'
1867
 
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1868
 
        os.environ['BZR_CONCURRENCY'] = '3'
1869
 
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1870
 
        os.environ['BZR_CONCURRENCY'] = 'foo'
1871
 
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1872
 
 
1873
 
    def test_option_concurrency(self):
1874
 
        os.environ['BZR_CONCURRENCY'] = '1'
1875
 
        self.run_bzr('rocks --concurrency 42')
1876
 
        # Command line overrides envrionment variable
1877
 
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1878
 
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1879
 
 
1880
 
 
1881
 
class TestFailedToLoadExtension(tests.TestCase):
1882
 
 
1883
 
    def _try_loading(self):
1884
 
        try:
1885
 
            import bzrlib._fictional_extension_py
1886
 
        except ImportError, e:
1887
 
            osutils.failed_to_load_extension(e)
1888
 
            return True
1889
 
 
1890
 
    def setUp(self):
1891
 
        super(TestFailedToLoadExtension, self).setUp()
1892
 
        self.overrideAttr(osutils, '_extension_load_failures', [])
1893
 
 
1894
 
    def test_failure_to_load(self):
1895
 
        self._try_loading()
1896
 
        self.assertLength(1, osutils._extension_load_failures)
1897
 
        self.assertEquals(osutils._extension_load_failures[0],
1898
 
            "No module named _fictional_extension_py")
1899
 
 
1900
 
    def test_report_extension_load_failures_no_warning(self):
1901
 
        self.assertTrue(self._try_loading())
1902
 
        warnings, result = self.callCatchWarnings(osutils.report_extension_load_failures)
1903
 
        # it used to give a Python warning; it no longer does
1904
 
        self.assertLength(0, warnings)
1905
 
 
1906
 
    def test_report_extension_load_failures_message(self):
1907
 
        log = StringIO()
1908
 
        trace.push_log_file(log)
1909
 
        self.assertTrue(self._try_loading())
1910
 
        osutils.report_extension_load_failures()
1911
 
        self.assertContainsRe(
1912
 
            log.getvalue(),
1913
 
            r"bzr: warning: some compiled extensions could not be loaded; "
1914
 
            "see <https://answers\.launchpad\.net/bzr/\+faq/703>\n"
1915
 
            )
1916
 
 
1917
 
 
1918
 
class TestTerminalWidth(tests.TestCase):
1919
 
 
1920
 
    def replace_stdout(self, new):
1921
 
        self.overrideAttr(sys, 'stdout', new)
1922
 
 
1923
 
    def replace__terminal_size(self, new):
1924
 
        self.overrideAttr(osutils, '_terminal_size', new)
1925
 
 
1926
 
    def set_fake_tty(self):
1927
 
 
1928
 
        class I_am_a_tty(object):
1929
 
            def isatty(self):
1930
 
                return True
1931
 
 
1932
 
        self.replace_stdout(I_am_a_tty())
1933
 
 
1934
 
    def test_default_values(self):
1935
 
        self.assertEqual(80, osutils.default_terminal_width)
1936
 
 
1937
 
    def test_defaults_to_BZR_COLUMNS(self):
1938
 
        # BZR_COLUMNS is set by the test framework
1939
 
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1940
 
        os.environ['BZR_COLUMNS'] = '12'
1941
 
        self.assertEqual(12, osutils.terminal_width())
1942
 
 
1943
 
    def test_falls_back_to_COLUMNS(self):
1944
 
        del os.environ['BZR_COLUMNS']
1945
 
        self.assertNotEqual('42', os.environ['COLUMNS'])
1946
 
        self.set_fake_tty()
1947
 
        os.environ['COLUMNS'] = '42'
1948
 
        self.assertEqual(42, osutils.terminal_width())
1949
 
 
1950
 
    def test_tty_default_without_columns(self):
1951
 
        del os.environ['BZR_COLUMNS']
1952
 
        del os.environ['COLUMNS']
1953
 
 
1954
 
        def terminal_size(w, h):
1955
 
            return 42, 42
1956
 
 
1957
 
        self.set_fake_tty()
1958
 
        # We need to override the osutils definition as it depends on the
1959
 
        # running environment that we can't control (PQM running without a
1960
 
        # controlling terminal is one example).
1961
 
        self.replace__terminal_size(terminal_size)
1962
 
        self.assertEqual(42, osutils.terminal_width())
1963
 
 
1964
 
    def test_non_tty_default_without_columns(self):
1965
 
        del os.environ['BZR_COLUMNS']
1966
 
        del os.environ['COLUMNS']
1967
 
        self.replace_stdout(None)
1968
 
        self.assertEqual(None, osutils.terminal_width())
1969
 
 
1970
 
    def test_no_TIOCGWINSZ(self):
1971
 
        self.requireFeature(term_ios_feature)
1972
 
        termios = term_ios_feature.module
1973
 
        # bug 63539 is about a termios without TIOCGWINSZ attribute
1974
 
        try:
1975
 
            orig = termios.TIOCGWINSZ
1976
 
        except AttributeError:
1977
 
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1978
 
            pass
1979
 
        else:
1980
 
            self.overrideAttr(termios, 'TIOCGWINSZ')
1981
 
            del termios.TIOCGWINSZ
1982
 
        del os.environ['BZR_COLUMNS']
1983
 
        del os.environ['COLUMNS']
1984
 
        # Whatever the result is, if we don't raise an exception, it's ok.
1985
 
        osutils.terminal_width()
1986
 
 
1987
 
class TestCreationOps(tests.TestCaseInTempDir):
1988
 
    _test_needs_features = [features.chown_feature]
1989
 
 
1990
 
    def setUp(self):
1991
 
        tests.TestCaseInTempDir.setUp(self)
1992
 
        self.overrideAttr(os, 'chown', self._dummy_chown)
1993
 
 
1994
 
        # params set by call to _dummy_chown
1995
 
        self.path = self.uid = self.gid = None
1996
 
 
1997
 
    def _dummy_chown(self, path, uid, gid):
1998
 
        self.path, self.uid, self.gid = path, uid, gid
1999
 
 
2000
 
    def test_copy_ownership_from_path(self):
2001
 
        """copy_ownership_from_path test with specified src."""
2002
 
        ownsrc = '/'
2003
 
        f = open('test_file', 'wt')
2004
 
        osutils.copy_ownership_from_path('test_file', ownsrc)
2005
 
 
2006
 
        s = os.stat(ownsrc)
2007
 
        self.assertEquals(self.path, 'test_file')
2008
 
        self.assertEquals(self.uid, s.st_uid)
2009
 
        self.assertEquals(self.gid, s.st_gid)
2010
 
 
2011
 
    def test_copy_ownership_nonesrc(self):
2012
 
        """copy_ownership_from_path test with src=None."""
2013
 
        f = open('test_file', 'wt')
2014
 
        # should use parent dir for permissions
2015
 
        osutils.copy_ownership_from_path('test_file')
2016
 
 
2017
 
        s = os.stat('..')
2018
 
        self.assertEquals(self.path, 'test_file')
2019
 
        self.assertEquals(self.uid, s.st_uid)
2020
 
        self.assertEquals(self.gid, s.st_gid)