~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-04 10:59:49 UTC
  • mfrom: (4862.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091204105949-cp822ctg4bp7vgd4
(vila) BZR_COLUMNS can override terminal_width()

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import socket
24
24
import stat
25
25
import sys
 
26
import termios
26
27
import time
27
28
 
28
29
from bzrlib import (
1922
1923
            r"bzr: warning: some compiled extensions could not be loaded; "
1923
1924
            "see <https://answers\.launchpad\.net/bzr/\+faq/703>\n"
1924
1925
            )
 
1926
 
 
1927
 
 
1928
class TestTerminalWidth(tests.TestCase):
 
1929
 
 
1930
    def test_default_values(self):
 
1931
        self.assertEquals(80, osutils.default_terminal_width)
 
1932
 
 
1933
    def test_defaults_to_BZR_COLUMNS(self):
 
1934
        # BZR_COLUMNS is set by the test framework
 
1935
        self.assertEquals('80', os.environ['BZR_COLUMNS'])
 
1936
        os.environ['BZR_COLUMNS'] = '12'
 
1937
        self.assertEquals(12, osutils.terminal_width())
 
1938
 
 
1939
    def test_tty_default_without_columns(self):
 
1940
        del os.environ['BZR_COLUMNS']
 
1941
        del os.environ['COLUMNS']
 
1942
        orig_stdout = sys.stdout
 
1943
        def restore():
 
1944
            sys.stdout = orig_stdout
 
1945
        self.addCleanup(restore)
 
1946
 
 
1947
        class I_am_a_tty(object):
 
1948
            def isatty(self):
 
1949
                return True
 
1950
 
 
1951
        sys.stdout = I_am_a_tty()
 
1952
        self.assertEquals(None, osutils.terminal_width())
 
1953
 
 
1954
    def test_non_tty_default_without_columns(self):
 
1955
        del os.environ['BZR_COLUMNS']
 
1956
        del os.environ['COLUMNS']
 
1957
        orig_stdout = sys.stdout
 
1958
        def restore():
 
1959
            sys.stdout = orig_stdout
 
1960
        self.addCleanup(restore)
 
1961
        sys.stdout = None
 
1962
        self.assertEquals(None, osutils.terminal_width())
 
1963
 
 
1964
    def test_TIOCGWINSZ(self):
 
1965
        # bug 63539 is about a termios without TIOCGWINSZ attribute
 
1966
        exist = True
 
1967
        try:
 
1968
            orig = termios.TIOCGWINSZ
 
1969
        except AttributeError:
 
1970
            exist = False
 
1971
 
 
1972
        def restore():
 
1973
            if exist:
 
1974
                termios.TIOCGWINSZ = orig
 
1975
        self.addCleanup(restore)
 
1976
 
 
1977
        del termios.TIOCGWINSZ
 
1978
        del os.environ['BZR_COLUMNS']
 
1979
        del os.environ['COLUMNS']
 
1980
        self.assertEquals(None, osutils.terminal_width())