/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: 2010-01-12 22:51:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4955.
  • Revision ID: john@arbash-meinel.com-20100112225131-he8h411p6aeeb947
Delay grabbing an output stream until we actually go to show a diff.

This makes the test suite happy, but it also seems to be reasonable.
If we aren't going to write anything, we don't need to hold an
output stream open.

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
33
33
    win32utils,
34
34
    )
35
35
from bzrlib.tests import (
36
 
    features,
37
36
    file_utils,
38
37
    test__walkdirs_win32,
39
38
    )
184
183
        shape = sorted(os.listdir('.'))
185
184
        self.assertEquals(['A', 'B'], shape)
186
185
 
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
186
 
195
187
class TestRandChars(tests.TestCase):
196
188
 
317
309
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
318
310
        self.assertEqual("@", osutils.kind_marker("symlink"))
319
311
        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"))
 
312
        self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
323
313
 
324
314
 
325
315
class TestUmask(tests.TestCaseInTempDir):
1145
1135
            dirblock[:] = new_dirblock
1146
1136
 
1147
1137
    def _save_platform_info(self):
1148
 
        self.overrideAttr(win32utils, 'winver')
1149
 
        self.overrideAttr(osutils, '_fs_enc')
1150
 
        self.overrideAttr(osutils, '_selected_dir_reader')
 
1138
        cur_winver = win32utils.winver
 
1139
        cur_fs_enc = osutils._fs_enc
 
1140
        cur_dir_reader = osutils._selected_dir_reader
 
1141
        def restore():
 
1142
            win32utils.winver = cur_winver
 
1143
            osutils._fs_enc = cur_fs_enc
 
1144
            osutils._selected_dir_reader = cur_dir_reader
 
1145
        self.addCleanup(restore)
1151
1146
 
1152
1147
    def assertDirReaderIs(self, expected):
1153
1148
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1586
1581
        def cleanup():
1587
1582
            if 'BZR_TEST_ENV_VAR' in os.environ:
1588
1583
                del os.environ['BZR_TEST_ENV_VAR']
 
1584
 
1589
1585
        self.addCleanup(cleanup)
1590
1586
 
1591
1587
    def test_set(self):
1702
1698
 
1703
1699
    def setUp(self):
1704
1700
        tests.TestCaseInTempDir.setUp(self)
1705
 
        self.overrideAttr(osutils,
1706
 
                          '_selected_dir_reader', self._dir_reader_class())
 
1701
 
 
1702
        # Save platform specific info and reset it
 
1703
        cur_dir_reader = osutils._selected_dir_reader
 
1704
 
 
1705
        def restore():
 
1706
            osutils._selected_dir_reader = cur_dir_reader
 
1707
        self.addCleanup(restore)
 
1708
 
 
1709
        osutils._selected_dir_reader = self._dir_reader_class()
1707
1710
 
1708
1711
    def _get_ascii_tree(self):
1709
1712
        tree = [
1856
1859
 
1857
1860
    def setUp(self):
1858
1861
        super(TestConcurrency, self).setUp()
1859
 
        self.overrideAttr(osutils, '_cached_local_concurrency')
 
1862
        orig = osutils._cached_local_concurrency
 
1863
        def restore():
 
1864
            osutils._cached_local_concurrency = orig
 
1865
        self.addCleanup(restore)
1860
1866
 
1861
1867
    def test_local_concurrency(self):
1862
1868
        concurrency = osutils.local_concurrency()
1889
1895
 
1890
1896
    def setUp(self):
1891
1897
        super(TestFailedToLoadExtension, self).setUp()
1892
 
        self.overrideAttr(osutils, '_extension_load_failures', [])
 
1898
        self.saved_failures = osutils._extension_load_failures[:]
 
1899
        del osutils._extension_load_failures[:]
 
1900
        self.addCleanup(self.restore_failures)
 
1901
 
 
1902
    def restore_failures(self):
 
1903
        osutils._extension_load_failures = self.saved_failures
1893
1904
 
1894
1905
    def test_failure_to_load(self):
1895
1906
        self._try_loading()
1918
1929
class TestTerminalWidth(tests.TestCase):
1919
1930
 
1920
1931
    def replace_stdout(self, new):
1921
 
        self.overrideAttr(sys, 'stdout', new)
 
1932
        orig_stdout = sys.stdout
 
1933
        def restore():
 
1934
            sys.stdout = orig_stdout
 
1935
        self.addCleanup(restore)
 
1936
        sys.stdout = new
1922
1937
 
1923
1938
    def replace__terminal_size(self, new):
1924
 
        self.overrideAttr(osutils, '_terminal_size', new)
 
1939
        orig__terminal_size = osutils._terminal_size
 
1940
        def restore():
 
1941
            osutils._terminal_size = orig__terminal_size
 
1942
        self.addCleanup(restore)
 
1943
        osutils._terminal_size = new
1925
1944
 
1926
1945
    def set_fake_tty(self):
1927
1946
 
1977
1996
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1978
1997
            pass
1979
1998
        else:
1980
 
            self.overrideAttr(termios, 'TIOCGWINSZ')
 
1999
            def restore():
 
2000
                termios.TIOCGWINSZ = orig
 
2001
            self.addCleanup(restore)
1981
2002
            del termios.TIOCGWINSZ
1982
2003
        del os.environ['BZR_COLUMNS']
1983
2004
        del os.environ['COLUMNS']
1984
2005
        # Whatever the result is, if we don't raise an exception, it's ok.
1985
2006
        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)