~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    win32utils,
34
34
    )
35
35
from bzrlib.tests import (
 
36
    features,
36
37
    file_utils,
37
38
    test__walkdirs_win32,
38
39
    )
309
310
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
310
311
        self.assertEqual("@", osutils.kind_marker("symlink"))
311
312
        self.assertEqual("+", osutils.kind_marker("tree-reference"))
312
 
        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"))
313
316
 
314
317
 
315
318
class TestUmask(tests.TestCaseInTempDir):
1135
1138
            dirblock[:] = new_dirblock
1136
1139
 
1137
1140
    def _save_platform_info(self):
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)
 
1141
        self.overrideAttr(win32utils, 'winver')
 
1142
        self.overrideAttr(osutils, '_fs_enc')
 
1143
        self.overrideAttr(osutils, '_selected_dir_reader')
1146
1144
 
1147
1145
    def assertDirReaderIs(self, expected):
1148
1146
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1581
1579
        def cleanup():
1582
1580
            if 'BZR_TEST_ENV_VAR' in os.environ:
1583
1581
                del os.environ['BZR_TEST_ENV_VAR']
1584
 
 
1585
1582
        self.addCleanup(cleanup)
1586
1583
 
1587
1584
    def test_set(self):
1698
1695
 
1699
1696
    def setUp(self):
1700
1697
        tests.TestCaseInTempDir.setUp(self)
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()
 
1698
        self.overrideAttr(osutils,
 
1699
                          '_selected_dir_reader', self._dir_reader_class())
1710
1700
 
1711
1701
    def _get_ascii_tree(self):
1712
1702
        tree = [
1859
1849
 
1860
1850
    def setUp(self):
1861
1851
        super(TestConcurrency, self).setUp()
1862
 
        orig = osutils._cached_local_concurrency
1863
 
        def restore():
1864
 
            osutils._cached_local_concurrency = orig
1865
 
        self.addCleanup(restore)
 
1852
        self.overrideAttr(osutils, '_cached_local_concurrency')
1866
1853
 
1867
1854
    def test_local_concurrency(self):
1868
1855
        concurrency = osutils.local_concurrency()
1895
1882
 
1896
1883
    def setUp(self):
1897
1884
        super(TestFailedToLoadExtension, self).setUp()
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
 
1885
        self.overrideAttr(osutils, '_extension_load_failures', [])
1904
1886
 
1905
1887
    def test_failure_to_load(self):
1906
1888
        self._try_loading()
1929
1911
class TestTerminalWidth(tests.TestCase):
1930
1912
 
1931
1913
    def replace_stdout(self, new):
1932
 
        orig_stdout = sys.stdout
1933
 
        def restore():
1934
 
            sys.stdout = orig_stdout
1935
 
        self.addCleanup(restore)
1936
 
        sys.stdout = new
 
1914
        self.overrideAttr(sys, 'stdout', new)
1937
1915
 
1938
1916
    def replace__terminal_size(self, 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
 
1917
        self.overrideAttr(osutils, '_terminal_size', new)
1944
1918
 
1945
1919
    def set_fake_tty(self):
1946
1920
 
1996
1970
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1997
1971
            pass
1998
1972
        else:
1999
 
            def restore():
2000
 
                termios.TIOCGWINSZ = orig
2001
 
            self.addCleanup(restore)
 
1973
            self.overrideAttr(termios, 'TIOCGWINSZ')
2002
1974
            del termios.TIOCGWINSZ
2003
1975
        del os.environ['BZR_COLUMNS']
2004
1976
        del os.environ['COLUMNS']
2005
1977
        # Whatever the result is, if we don't raise an exception, it's ok.
2006
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_mkdir_with_ownership_chown(self):
 
1994
        """Ensure that osutils.mkdir_with_ownership chowns correctly with ownership_src.
 
1995
        """
 
1996
        ownsrc = '/'
 
1997
        osutils.mkdir_with_ownership('foo', ownsrc)
 
1998
 
 
1999
        s = os.stat(ownsrc)
 
2000
        self.assertEquals(self.path, 'foo')
 
2001
        self.assertEquals(self.uid, s.st_uid)
 
2002
        self.assertEquals(self.gid, s.st_gid)
 
2003
 
 
2004
    def test_open_with_ownership_chown(self):
 
2005
        """Ensure that osutils.open_with_ownership chowns correctly with ownership_src.
 
2006
        """
 
2007
        ownsrc = '/'
 
2008
        f = osutils.open_with_ownership('foo', 'w', ownership_src=ownsrc)
 
2009
 
 
2010
        # do a test write and close
 
2011
        f.write('hello')
 
2012
        f.close()
 
2013
 
 
2014
        s = os.stat(ownsrc)
 
2015
        self.assertEquals(self.path, 'foo')
 
2016
        self.assertEquals(self.uid, s.st_uid)
 
2017
        self.assertEquals(self.gid, s.st_gid)
 
2018