~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

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
309
309
        self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
310
310
        self.assertEqual("@", osutils.kind_marker("symlink"))
311
311
        self.assertEqual("+", osutils.kind_marker("tree-reference"))
312
 
        self.assertEqual("", osutils.kind_marker("fifo"))
313
 
        self.assertEqual("", osutils.kind_marker("socket"))
314
 
        self.assertEqual("", osutils.kind_marker("unknown"))
 
312
        self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
315
313
 
316
314
 
317
315
class TestUmask(tests.TestCaseInTempDir):
1137
1135
            dirblock[:] = new_dirblock
1138
1136
 
1139
1137
    def _save_platform_info(self):
1140
 
        self.overrideAttr(win32utils, 'winver')
1141
 
        self.overrideAttr(osutils, '_fs_enc')
1142
 
        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)
1143
1146
 
1144
1147
    def assertDirReaderIs(self, expected):
1145
1148
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1578
1581
        def cleanup():
1579
1582
            if 'BZR_TEST_ENV_VAR' in os.environ:
1580
1583
                del os.environ['BZR_TEST_ENV_VAR']
 
1584
 
1581
1585
        self.addCleanup(cleanup)
1582
1586
 
1583
1587
    def test_set(self):
1694
1698
 
1695
1699
    def setUp(self):
1696
1700
        tests.TestCaseInTempDir.setUp(self)
1697
 
        self.overrideAttr(osutils,
1698
 
                          '_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()
1699
1710
 
1700
1711
    def _get_ascii_tree(self):
1701
1712
        tree = [
1848
1859
 
1849
1860
    def setUp(self):
1850
1861
        super(TestConcurrency, self).setUp()
1851
 
        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)
1852
1866
 
1853
1867
    def test_local_concurrency(self):
1854
1868
        concurrency = osutils.local_concurrency()
1881
1895
 
1882
1896
    def setUp(self):
1883
1897
        super(TestFailedToLoadExtension, self).setUp()
1884
 
        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
1885
1904
 
1886
1905
    def test_failure_to_load(self):
1887
1906
        self._try_loading()
1910
1929
class TestTerminalWidth(tests.TestCase):
1911
1930
 
1912
1931
    def replace_stdout(self, new):
1913
 
        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
1914
1937
 
1915
1938
    def replace__terminal_size(self, new):
1916
 
        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
1917
1944
 
1918
1945
    def set_fake_tty(self):
1919
1946
 
1969
1996
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1970
1997
            pass
1971
1998
        else:
1972
 
            self.overrideAttr(termios, 'TIOCGWINSZ')
 
1999
            def restore():
 
2000
                termios.TIOCGWINSZ = orig
 
2001
            self.addCleanup(restore)
1973
2002
            del termios.TIOCGWINSZ
1974
2003
        del os.environ['BZR_COLUMNS']
1975
2004
        del os.environ['COLUMNS']