309
310
self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
310
311
self.assertEqual("@", osutils.kind_marker("symlink"))
311
312
self.assertEqual("+", osutils.kind_marker("tree-reference"))
312
self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
313
self.assertEqual("", osutils.kind_marker("fifo"))
314
self.assertEqual("", osutils.kind_marker("socket"))
315
self.assertEqual("", osutils.kind_marker("unknown"))
315
318
class TestUmask(tests.TestCaseInTempDir):
1135
1138
dirblock[:] = new_dirblock
1137
1140
def _save_platform_info(self):
1138
cur_winver = win32utils.winver
1139
cur_fs_enc = osutils._fs_enc
1140
cur_dir_reader = osutils._selected_dir_reader
1142
win32utils.winver = cur_winver
1143
osutils._fs_enc = cur_fs_enc
1144
osutils._selected_dir_reader = cur_dir_reader
1145
self.addCleanup(restore)
1141
self.overrideAttr(win32utils, 'winver')
1142
self.overrideAttr(osutils, '_fs_enc')
1143
self.overrideAttr(osutils, '_selected_dir_reader')
1147
1145
def assertDirReaderIs(self, expected):
1148
1146
"""Assert the right implementation for _walkdirs_utf8 is chosen."""
1699
1696
def setUp(self):
1700
1697
tests.TestCaseInTempDir.setUp(self)
1702
# Save platform specific info and reset it
1703
cur_dir_reader = osutils._selected_dir_reader
1706
osutils._selected_dir_reader = cur_dir_reader
1707
self.addCleanup(restore)
1709
osutils._selected_dir_reader = self._dir_reader_class()
1698
self.overrideAttr(osutils,
1699
'_selected_dir_reader', self._dir_reader_class())
1711
1701
def _get_ascii_tree(self):
1860
1850
def setUp(self):
1861
1851
super(TestConcurrency, self).setUp()
1862
orig = osutils._cached_local_concurrency
1864
osutils._cached_local_concurrency = orig
1865
self.addCleanup(restore)
1852
self.overrideAttr(osutils, '_cached_local_concurrency')
1867
1854
def test_local_concurrency(self):
1868
1855
concurrency = osutils.local_concurrency()
1896
1883
def setUp(self):
1897
1884
super(TestFailedToLoadExtension, self).setUp()
1898
self.saved_failures = osutils._extension_load_failures[:]
1899
del osutils._extension_load_failures[:]
1900
self.addCleanup(self.restore_failures)
1902
def restore_failures(self):
1903
osutils._extension_load_failures = self.saved_failures
1885
self.overrideAttr(osutils, '_extension_load_failures', [])
1905
1887
def test_failure_to_load(self):
1906
1888
self._try_loading()
1929
1911
class TestTerminalWidth(tests.TestCase):
1931
1913
def replace_stdout(self, new):
1932
orig_stdout = sys.stdout
1934
sys.stdout = orig_stdout
1935
self.addCleanup(restore)
1914
self.overrideAttr(sys, 'stdout', new)
1938
1916
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
1917
self.overrideAttr(osutils, '_terminal_size', new)
1945
1919
def set_fake_tty(self):
1996
1970
# We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
2000
termios.TIOCGWINSZ = orig
2001
self.addCleanup(restore)
1973
self.overrideAttr(termios, 'TIOCGWINSZ')
2002
1974
del termios.TIOCGWINSZ
2003
1975
del os.environ['BZR_COLUMNS']
2004
1976
del os.environ['COLUMNS']
2005
1977
# Whatever the result is, if we don't raise an exception, it's ok.
2006
1978
osutils.terminal_width()
1980
class TestCreationOps(tests.TestCaseInTempDir):
1981
_test_needs_features = [features.chown_feature]
1984
tests.TestCaseInTempDir.setUp(self)
1985
self.overrideAttr(os, 'chown', self._dummy_chown)
1987
# params set by call to _dummy_chown
1988
self.path = self.uid = self.gid = None
1990
def _dummy_chown(self, path, uid, gid):
1991
self.path, self.uid, self.gid = path, uid, gid
1993
def test_mkdir_with_ownership_chown(self):
1994
"""Ensure that osutils.mkdir_with_ownership chowns correctly with ownership_src.
1997
osutils.mkdir_with_ownership('foo', ownsrc)
2000
self.assertEquals(self.path, 'foo')
2001
self.assertEquals(self.uid, s.st_uid)
2002
self.assertEquals(self.gid, s.st_gid)
2004
def test_open_with_ownership_chown(self):
2005
"""Ensure that osutils.open_with_ownership chowns correctly with ownership_src.
2008
f = osutils.open_with_ownership('foo', 'w', ownership_src=ownsrc)
2010
# do a test write and close
2015
self.assertEquals(self.path, 'foo')
2016
self.assertEquals(self.uid, s.st_uid)
2017
self.assertEquals(self.gid, s.st_gid)