1181
1182
def test_force_walkdirs_utf8_nt(self):
1182
1183
# Disabled because the thunk of the whole walkdirs api is disabled.
1183
self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1184
self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1184
1185
self._save_platform_info()
1185
1186
win32utils.winver = 'Windows NT'
1186
1187
from bzrlib._walkdirs_win32 import Win32ReadDir
1187
1188
self.assertDirReaderIs(Win32ReadDir)
1189
1190
def test_force_walkdirs_utf8_98(self):
1190
self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
1191
self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1191
1192
self._save_platform_info()
1192
1193
win32utils.winver = 'Windows 98'
1193
1194
self.assertDirReaderIs(osutils.UnicodeDirReader)
1928
1929
class TestTerminalWidth(tests.TestCase):
1931
def replace_stdout(self, new):
1932
orig_stdout = sys.stdout
1934
sys.stdout = orig_stdout
1935
self.addCleanup(restore)
1938
def replace__terminal_size(self, new):
1939
orig__terminal_size = osutils._terminal_size
1941
osutils._terminal_size = orig__terminal_size
1942
self.addCleanup(restore)
1943
osutils._terminal_size = new
1945
def set_fake_tty(self):
1947
class I_am_a_tty(object):
1951
self.replace_stdout(I_am_a_tty())
1930
1953
def test_default_values(self):
1931
self.assertEquals(80, osutils.default_terminal_width)
1954
self.assertEqual(80, osutils.default_terminal_width)
1933
1956
def test_defaults_to_BZR_COLUMNS(self):
1934
1957
# BZR_COLUMNS is set by the test framework
1935
self.assertEquals('80', os.environ['BZR_COLUMNS'])
1958
self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1936
1959
os.environ['BZR_COLUMNS'] = '12'
1937
self.assertEquals(12, osutils.terminal_width())
1960
self.assertEqual(12, osutils.terminal_width())
1962
def test_falls_back_to_COLUMNS(self):
1963
del os.environ['BZR_COLUMNS']
1964
self.assertNotEqual('42', os.environ['COLUMNS'])
1966
os.environ['COLUMNS'] = '42'
1967
self.assertEqual(42, osutils.terminal_width())
1939
1969
def test_tty_default_without_columns(self):
1940
1970
del os.environ['BZR_COLUMNS']
1941
1971
del os.environ['COLUMNS']
1942
orig_stdout = sys.stdout
1944
sys.stdout = orig_stdout
1945
self.addCleanup(restore)
1947
class I_am_a_tty(object):
1951
sys.stdout = I_am_a_tty()
1952
self.assertEquals(None, osutils.terminal_width())
1973
def terminal_size(w, h):
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
1983
def test_non_tty_default_without_columns(self):
1955
1984
del os.environ['BZR_COLUMNS']
1956
1985
del os.environ['COLUMNS']
1957
orig_stdout = sys.stdout
1959
sys.stdout = orig_stdout
1960
self.addCleanup(restore)
1962
self.assertEquals(None, osutils.terminal_width())
1986
self.replace_stdout(None)
1987
self.assertEqual(None, osutils.terminal_width())
1964
def test_TIOCGWINSZ(self):
1989
def test_no_TIOCGWINSZ(self):
1990
self.requireFeature(term_ios_feature)
1991
termios = term_ios_feature.module
1965
1992
# bug 63539 is about a termios without TIOCGWINSZ attribute
1968
1994
orig = termios.TIOCGWINSZ
1969
1995
except AttributeError:
1996
# We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1974
2000
termios.TIOCGWINSZ = orig
1975
self.addCleanup(restore)
1977
del termios.TIOCGWINSZ
2001
self.addCleanup(restore)
2002
del termios.TIOCGWINSZ
1978
2003
del os.environ['BZR_COLUMNS']
1979
2004
del os.environ['COLUMNS']
1980
self.assertEquals(None, osutils.terminal_width())
2005
# Whatever the result is, if we don't raise an exception, it's ok.
2006
osutils.terminal_width()