1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
184
183
shape = sorted(os.listdir('.'))
185
184
self.assertEquals(['A', 'B'], shape)
187
def test_rename_error(self):
188
# We wrap os.rename to make it give an error including the filenames
189
# https://bugs.launchpad.net/bzr/+bug/491763
190
err = self.assertRaises(OSError, osutils.rename,
191
'nonexistent', 'target')
192
self.assertContainsString(str(err), 'nonexistent')
195
187
class TestRandChars(tests.TestCase):
317
309
self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
318
310
self.assertEqual("@", osutils.kind_marker("symlink"))
319
311
self.assertEqual("+", osutils.kind_marker("tree-reference"))
320
self.assertEqual("", osutils.kind_marker("fifo"))
321
self.assertEqual("", osutils.kind_marker("socket"))
322
self.assertEqual("", osutils.kind_marker("unknown"))
312
self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
325
315
class TestUmask(tests.TestCaseInTempDir):
1145
1135
dirblock[:] = new_dirblock
1147
1137
def _save_platform_info(self):
1148
self.overrideAttr(win32utils, 'winver')
1149
self.overrideAttr(osutils, '_fs_enc')
1150
self.overrideAttr(osutils, '_selected_dir_reader')
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)
1152
1147
def assertDirReaderIs(self, expected):
1153
1148
"""Assert the right implementation for _walkdirs_utf8 is chosen."""
1703
1699
def setUp(self):
1704
1700
tests.TestCaseInTempDir.setUp(self)
1705
self.overrideAttr(osutils,
1706
'_selected_dir_reader', self._dir_reader_class())
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()
1708
1711
def _get_ascii_tree(self):
1857
1860
def setUp(self):
1858
1861
super(TestConcurrency, self).setUp()
1859
self.overrideAttr(osutils, '_cached_local_concurrency')
1862
orig = osutils._cached_local_concurrency
1864
osutils._cached_local_concurrency = orig
1865
self.addCleanup(restore)
1861
1867
def test_local_concurrency(self):
1862
1868
concurrency = osutils.local_concurrency()
1890
1896
def setUp(self):
1891
1897
super(TestFailedToLoadExtension, self).setUp()
1892
self.overrideAttr(osutils, '_extension_load_failures', [])
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
1894
1905
def test_failure_to_load(self):
1895
1906
self._try_loading()
1918
1929
class TestTerminalWidth(tests.TestCase):
1920
1931
def replace_stdout(self, new):
1921
self.overrideAttr(sys, 'stdout', new)
1932
orig_stdout = sys.stdout
1934
sys.stdout = orig_stdout
1935
self.addCleanup(restore)
1923
1938
def replace__terminal_size(self, new):
1924
self.overrideAttr(osutils, '_terminal_size', new)
1939
orig__terminal_size = osutils._terminal_size
1941
osutils._terminal_size = orig__terminal_size
1942
self.addCleanup(restore)
1943
osutils._terminal_size = new
1926
1945
def set_fake_tty(self):
1977
1996
# We won't remove TIOCGWINSZ, because it doesn't exist anyway :)
1980
self.overrideAttr(termios, 'TIOCGWINSZ')
2000
termios.TIOCGWINSZ = orig
2001
self.addCleanup(restore)
1981
2002
del termios.TIOCGWINSZ
1982
2003
del os.environ['BZR_COLUMNS']
1983
2004
del os.environ['COLUMNS']
1984
2005
# Whatever the result is, if we don't raise an exception, it's ok.
1985
2006
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)