~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 17:48:22 UTC
  • mto: (4987.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125174822-nce4l19sbwx83jvq
Deploying the new overrideAttr facility further reduces the complexity
and make the code clearer.

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
 
        self.addAttrCleanup(os, 'umask')
 
323
        orig_umask = osutils.get_umask()
 
324
        self.addCleanup(os.umask, orig_umask)
324
325
        os.umask(0222)
325
326
        self.assertEqual(0222, osutils.get_umask())
326
327
        os.umask(0022)
1134
1135
            dirblock[:] = new_dirblock
1135
1136
 
1136
1137
    def _save_platform_info(self):
1137
 
        self.addAttrCleanup(win32utils, 'winver')
1138
 
        self.addAttrCleanup(osutils, '_fs_enc')
1139
 
        self.addAttrCleanup(osutils, '_selected_dir_reader')
 
1138
        self.overrideAttr(win32utils, 'winver')
 
1139
        self.overrideAttr(osutils, '_fs_enc')
 
1140
        self.overrideAttr(osutils, '_selected_dir_reader')
1140
1141
 
1141
1142
    def assertDirReaderIs(self, expected):
1142
1143
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
1691
1692
 
1692
1693
    def setUp(self):
1693
1694
        tests.TestCaseInTempDir.setUp(self)
1694
 
        self.addAttrCleanup(osutils, '_selected_dir_reader')
1695
 
        osutils._selected_dir_reader = self._dir_reader_class()
 
1695
        self.overrideAttr(osutils,
 
1696
                          '_selected_dir_reader', self._dir_reader_class())
1696
1697
 
1697
1698
    def _get_ascii_tree(self):
1698
1699
        tree = [
1845
1846
 
1846
1847
    def setUp(self):
1847
1848
        super(TestConcurrency, self).setUp()
1848
 
        self.addAttrCleanup(osutils, '_cached_local_concurrency')
 
1849
        self.overrideAttr(osutils, '_cached_local_concurrency')
1849
1850
 
1850
1851
    def test_local_concurrency(self):
1851
1852
        concurrency = osutils.local_concurrency()
1878
1879
 
1879
1880
    def setUp(self):
1880
1881
        super(TestFailedToLoadExtension, self).setUp()
1881
 
        self.addAttrCleanup(osutils, '_extension_load_failures')
1882
 
        osutils._extension_load_failures = []
 
1882
        self.overrideAttr(osutils, '_extension_load_failures', [])
1883
1883
 
1884
1884
    def test_failure_to_load(self):
1885
1885
        self._try_loading()
1908
1908
class TestTerminalWidth(tests.TestCase):
1909
1909
 
1910
1910
    def replace_stdout(self, new):
1911
 
        self.addAttrCleanup(sys, 'stdout')
1912
 
        sys.stdout = new
 
1911
        self.overrideAttr(sys, 'stdout', new)
1913
1912
 
1914
1913
    def replace__terminal_size(self, new):
1915
 
        self.addAttrCleanup(osutils, '_terminal_size')
1916
 
        osutils._terminal_size = new
 
1914
        self.overrideAttr(osutils, '_terminal_size', new)
1917
1915
 
1918
1916
    def set_fake_tty(self):
1919
1917
 
1969
1967
            # We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1970
1968
            pass
1971
1969
        else:
1972
 
            self.addAttrCleanup(termios, 'TIOCGWINSZ')
 
1970
            self.overrideAttr(termios, 'TIOCGWINSZ')
1973
1971
            del termios.TIOCGWINSZ
1974
1972
        del os.environ['BZR_COLUMNS']
1975
1973
        del os.environ['COLUMNS']