~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Get first deployment

Show diffs side-by-side

added added

removed removed

Lines of Context:
320
320
            self.assertEqual(0, osutils.get_umask())
321
321
            return
322
322
 
323
 
        orig_umask = osutils.get_umask()
324
 
        self.addCleanup(os.umask, orig_umask)
 
323
        self.addAttrCleanup(os, 'umask')
325
324
        os.umask(0222)
326
325
        self.assertEqual(0222, osutils.get_umask())
327
326
        os.umask(0022)
1135
1134
            dirblock[:] = new_dirblock
1136
1135
 
1137
1136
    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)
 
1137
        self.addAttrCleanup(win32utils, 'winver')
 
1138
        self.addAttrCleanup(osutils, '_fs_enc')
 
1139
        self.addAttrCleanup(osutils, '_selected_dir_reader')
1146
1140
 
1147
1141
    def assertDirReaderIs(self, expected):
1148
1142
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1581
1575
        def cleanup():
1582
1576
            if 'BZR_TEST_ENV_VAR' in os.environ:
1583
1577
                del os.environ['BZR_TEST_ENV_VAR']
1584
 
 
1585
1578
        self.addCleanup(cleanup)
1586
1579
 
1587
1580
    def test_set(self):
1698
1691
 
1699
1692
    def setUp(self):
1700
1693
        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
 
 
 
1694
        self.addAttrCleanup(osutils, '_selected_dir_reader')
1709
1695
        osutils._selected_dir_reader = self._dir_reader_class()
1710
1696
 
1711
1697
    def _get_ascii_tree(self):
1859
1845
 
1860
1846
    def setUp(self):
1861
1847
        super(TestConcurrency, self).setUp()
1862
 
        orig = osutils._cached_local_concurrency
1863
 
        def restore():
1864
 
            osutils._cached_local_concurrency = orig
1865
 
        self.addCleanup(restore)
 
1848
        self.addAttrCleanup(osutils, '_cached_local_concurrency')
1866
1849
 
1867
1850
    def test_local_concurrency(self):
1868
1851
        concurrency = osutils.local_concurrency()
1895
1878
 
1896
1879
    def setUp(self):
1897
1880
        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
 
1881
        self.addAttrCleanup(osutils, '_extension_load_failures')
 
1882
        osutils._extension_load_failures = []
1904
1883
 
1905
1884
    def test_failure_to_load(self):
1906
1885
        self._try_loading()
1929
1908
class TestTerminalWidth(tests.TestCase):
1930
1909
 
1931
1910
    def replace_stdout(self, new):
1932
 
        orig_stdout = sys.stdout
1933
 
        def restore():
1934
 
            sys.stdout = orig_stdout
1935
 
        self.addCleanup(restore)
 
1911
        self.addAttrCleanup(sys, 'stdout')
1936
1912
        sys.stdout = new
1937
1913
 
1938
1914
    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)
 
1915
        self.addAttrCleanup(osutils, '_terminal_size')
1943
1916
        osutils._terminal_size = new
1944
1917
 
1945
1918
    def set_fake_tty(self):
1996
1969
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1997
1970
            pass
1998
1971
        else:
1999
 
            def restore():
2000
 
                termios.TIOCGWINSZ = orig
2001
 
            self.addCleanup(restore)
 
1972
            self.addAttrCleanup(termios, 'TIOCGWINSZ')
2002
1973
            del termios.TIOCGWINSZ
2003
1974
        del os.environ['BZR_COLUMNS']
2004
1975
        del os.environ['COLUMNS']