/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: Canonical.com Patch Queue Manager
  • Date: 2009-12-09 18:07:09 UTC
  • mfrom: (4881.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091209180709-vahds276v0vklwad
Fix minor issues and make test passing on windows for terminal_width()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1928
1928
 
1929
1929
class TestTerminalWidth(tests.TestCase):
1930
1930
 
 
1931
    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
 
1937
 
 
1938
    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
 
1944
 
 
1945
    def set_fake_tty(self):
 
1946
 
 
1947
        class I_am_a_tty(object):
 
1948
            def isatty(self):
 
1949
                return True
 
1950
 
 
1951
        self.replace_stdout(I_am_a_tty())
 
1952
 
1931
1953
    def test_default_values(self):
1932
 
        self.assertEquals(80, osutils.default_terminal_width)
 
1954
        self.assertEqual(80, osutils.default_terminal_width)
1933
1955
 
1934
1956
    def test_defaults_to_BZR_COLUMNS(self):
1935
1957
        # BZR_COLUMNS is set by the test framework
1936
 
        self.assertEquals('80', os.environ['BZR_COLUMNS'])
 
1958
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1937
1959
        os.environ['BZR_COLUMNS'] = '12'
1938
 
        self.assertEquals(12, osutils.terminal_width())
 
1960
        self.assertEqual(12, osutils.terminal_width())
 
1961
 
 
1962
    def test_falls_back_to_COLUMNS(self):
 
1963
        del os.environ['BZR_COLUMNS']
 
1964
        self.assertNotEqual('42', os.environ['COLUMNS'])
 
1965
        self.set_fake_tty()
 
1966
        os.environ['COLUMNS'] = '42'
 
1967
        self.assertEqual(42, osutils.terminal_width())
1939
1968
 
1940
1969
    def test_tty_default_without_columns(self):
1941
1970
        del os.environ['BZR_COLUMNS']
1942
1971
        del os.environ['COLUMNS']
1943
 
        orig_stdout = sys.stdout
1944
 
        def restore():
1945
 
            sys.stdout = orig_stdout
1946
 
        self.addCleanup(restore)
1947
 
 
1948
 
        class I_am_a_tty(object):
1949
 
            def isatty(self):
1950
 
                return True
1951
 
 
1952
 
        sys.stdout = I_am_a_tty()
1953
 
        self.assertEquals(None, osutils.terminal_width())
 
1972
 
 
1973
        def terminal_size(w, h):
 
1974
            return 42, 42
 
1975
 
 
1976
        self.set_fake_tty()
 
1977
        # We need to override the osutils definition as it depends on the
 
1978
        # running environment that we can't control (PQM running without a
 
1979
        # controlling terminal is one example).
 
1980
        self.replace__terminal_size(terminal_size)
 
1981
        self.assertEqual(42, osutils.terminal_width())
1954
1982
 
1955
1983
    def test_non_tty_default_without_columns(self):
1956
1984
        del os.environ['BZR_COLUMNS']
1957
1985
        del os.environ['COLUMNS']
1958
 
        orig_stdout = sys.stdout
1959
 
        def restore():
1960
 
            sys.stdout = orig_stdout
1961
 
        self.addCleanup(restore)
1962
 
        sys.stdout = None
1963
 
        self.assertEquals(None, osutils.terminal_width())
 
1986
        self.replace_stdout(None)
 
1987
        self.assertEqual(None, osutils.terminal_width())
1964
1988
 
1965
1989
    def test_no_TIOCGWINSZ(self):
1966
1990
        self.requireFeature(TermIOSFeature)
1978
2002
            del termios.TIOCGWINSZ
1979
2003
        del os.environ['BZR_COLUMNS']
1980
2004
        del os.environ['COLUMNS']
1981
 
        self.assertIs(None, osutils.terminal_width())
 
2005
        # Whatever the result is, if we don't raise an exception, it's ok.
 
2006
        osutils.terminal_width()