1918
1928
class TestTerminalWidth(tests.TestCase):
1920
def replace_stdout(self, new):
1921
self.overrideAttr(sys, 'stdout', new)
1923
def replace__terminal_size(self, new):
1924
self.overrideAttr(osutils, '_terminal_size', new)
1926
def set_fake_tty(self):
1928
class I_am_a_tty(object):
1932
self.replace_stdout(I_am_a_tty())
1934
1930
def test_default_values(self):
1935
self.assertEqual(80, osutils.default_terminal_width)
1931
self.assertEquals(80, osutils.default_terminal_width)
1937
1933
def test_defaults_to_BZR_COLUMNS(self):
1938
1934
# BZR_COLUMNS is set by the test framework
1939
self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1935
self.assertEquals('80', os.environ['BZR_COLUMNS'])
1940
1936
os.environ['BZR_COLUMNS'] = '12'
1941
self.assertEqual(12, osutils.terminal_width())
1943
def test_falls_back_to_COLUMNS(self):
1944
del os.environ['BZR_COLUMNS']
1945
self.assertNotEqual('42', os.environ['COLUMNS'])
1947
os.environ['COLUMNS'] = '42'
1948
self.assertEqual(42, osutils.terminal_width())
1937
self.assertEquals(12, osutils.terminal_width())
1950
1939
def test_tty_default_without_columns(self):
1951
1940
del os.environ['BZR_COLUMNS']
1952
1941
del os.environ['COLUMNS']
1954
def terminal_size(w, h):
1958
# We need to override the osutils definition as it depends on the
1959
# running environment that we can't control (PQM running without a
1960
# controlling terminal is one example).
1961
self.replace__terminal_size(terminal_size)
1962
self.assertEqual(42, osutils.terminal_width())
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())
1964
1954
def test_non_tty_default_without_columns(self):
1965
1955
del os.environ['BZR_COLUMNS']
1966
1956
del os.environ['COLUMNS']
1967
self.replace_stdout(None)
1968
self.assertEqual(None, osutils.terminal_width())
1957
orig_stdout = sys.stdout
1959
sys.stdout = orig_stdout
1960
self.addCleanup(restore)
1962
self.assertEquals(None, osutils.terminal_width())
1970
def test_no_TIOCGWINSZ(self):
1971
self.requireFeature(term_ios_feature)
1972
termios = term_ios_feature.module
1964
def test_TIOCGWINSZ(self):
1973
1965
# bug 63539 is about a termios without TIOCGWINSZ attribute
1975
1968
orig = termios.TIOCGWINSZ
1976
1969
except AttributeError:
1977
# We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1980
self.overrideAttr(termios, 'TIOCGWINSZ')
1981
del termios.TIOCGWINSZ
1974
termios.TIOCGWINSZ = orig
1975
self.addCleanup(restore)
1977
del termios.TIOCGWINSZ
1982
1978
del os.environ['BZR_COLUMNS']
1983
1979
del os.environ['COLUMNS']
1984
# Whatever the result is, if we don't raise an exception, it's ok.
1985
osutils.terminal_width()
1987
class TestCreationOps(tests.TestCaseInTempDir):
1988
_test_needs_features = [features.chown_feature]
1991
tests.TestCaseInTempDir.setUp(self)
1992
self.overrideAttr(os, 'chown', self._dummy_chown)
1994
# params set by call to _dummy_chown
1995
self.path = self.uid = self.gid = None
1997
def _dummy_chown(self, path, uid, gid):
1998
self.path, self.uid, self.gid = path, uid, gid
2000
def test_copy_ownership_from_path(self):
2001
"""copy_ownership_from_path test with specified src."""
2003
f = open('test_file', 'wt')
2004
osutils.copy_ownership_from_path('test_file', ownsrc)
2007
self.assertEquals(self.path, 'test_file')
2008
self.assertEquals(self.uid, s.st_uid)
2009
self.assertEquals(self.gid, s.st_gid)
2011
def test_copy_ownership_nonesrc(self):
2012
"""copy_ownership_from_path test with src=None."""
2013
f = open('test_file', 'wt')
2014
# should use parent dir for permissions
2015
osutils.copy_ownership_from_path('test_file')
2018
self.assertEquals(self.path, 'test_file')
2019
self.assertEquals(self.uid, s.st_uid)
2020
self.assertEquals(self.gid, s.st_gid)
1980
self.assertEquals(None, osutils.terminal_width())