100
def load_tests(basic_tests, module, loader):
101
suite = loader.suiteClass()
102
dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
103
basic_tests, tests.condition_isinstance(TestDirReader))
104
tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
105
suite.addTest(remaining_tests)
100
load_tests = load_tests_apply_scenarios
109
103
class TestContainsWhitespace(tests.TestCase):
1072
1066
if sys.platform == 'win32':
1073
1067
raise tests.TestNotApplicable(
1074
1068
"readdir IOError not tested on win32")
1069
self.requireFeature(features.not_running_as_root)
1075
1070
os.mkdir("test-unreadable")
1076
1071
os.chmod("test-unreadable", 0000)
1077
1072
# must chmod it back so that it can be removed
1108
1103
# rename the 1file to a latin-1 filename
1109
1104
os.rename("./1file", "\xe8file")
1105
if "\xe8file" not in os.listdir("."):
1106
self.skip("Lack filesystem that preserves arbitrary bytes")
1111
1108
self._save_platform_info()
1112
1109
win32utils.winver = None # Avoid the win32 detection code
1900
1899
self.assertIsInstance(concurrency, int)
1902
1901
def test_local_concurrency_environment_variable(self):
1903
os.environ['BZR_CONCURRENCY'] = '2'
1902
self.overrideEnv('BZR_CONCURRENCY', '2')
1904
1903
self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1905
os.environ['BZR_CONCURRENCY'] = '3'
1904
self.overrideEnv('BZR_CONCURRENCY', '3')
1906
1905
self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1907
os.environ['BZR_CONCURRENCY'] = 'foo'
1906
self.overrideEnv('BZR_CONCURRENCY', 'foo')
1908
1907
self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1910
1909
def test_option_concurrency(self):
1911
os.environ['BZR_CONCURRENCY'] = '1'
1910
self.overrideEnv('BZR_CONCURRENCY', '1')
1912
1911
self.run_bzr('rocks --concurrency 42')
1913
# Command line overrides envrionment variable
1912
# Command line overrides environment variable
1914
1913
self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1915
1914
self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1986
1985
def test_defaults_to_BZR_COLUMNS(self):
1987
1986
# BZR_COLUMNS is set by the test framework
1988
1987
self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1989
os.environ['BZR_COLUMNS'] = '12'
1988
self.overrideEnv('BZR_COLUMNS', '12')
1990
1989
self.assertEqual(12, osutils.terminal_width())
1992
1991
def test_falls_back_to_COLUMNS(self):
1993
del os.environ['BZR_COLUMNS']
1992
self.overrideEnv('BZR_COLUMNS', None)
1994
1993
self.assertNotEqual('42', os.environ['COLUMNS'])
1995
1994
self.set_fake_tty()
1996
os.environ['COLUMNS'] = '42'
1995
self.overrideEnv('COLUMNS', '42')
1997
1996
self.assertEqual(42, osutils.terminal_width())
1999
1998
def test_tty_default_without_columns(self):
2000
del os.environ['BZR_COLUMNS']
2001
del os.environ['COLUMNS']
1999
self.overrideEnv('BZR_COLUMNS', None)
2000
self.overrideEnv('COLUMNS', None)
2003
2002
def terminal_size(w, h):
2011
2010
self.assertEqual(42, osutils.terminal_width())
2013
2012
def test_non_tty_default_without_columns(self):
2014
del os.environ['BZR_COLUMNS']
2015
del os.environ['COLUMNS']
2013
self.overrideEnv('BZR_COLUMNS', None)
2014
self.overrideEnv('COLUMNS', None)
2016
2015
self.replace_stdout(None)
2017
2016
self.assertEqual(None, osutils.terminal_width())
2029
2028
self.overrideAttr(termios, 'TIOCGWINSZ')
2030
2029
del termios.TIOCGWINSZ
2031
del os.environ['BZR_COLUMNS']
2032
del os.environ['COLUMNS']
2030
self.overrideEnv('BZR_COLUMNS', None)
2031
self.overrideEnv('COLUMNS', None)
2033
2032
# Whatever the result is, if we don't raise an exception, it's ok.
2034
2033
osutils.terminal_width()
2071
2070
class TestGetuserUnicode(tests.TestCase):
2073
2072
def test_ascii_user(self):
2074
osutils.set_or_unset_env('LOGNAME', 'jrandom')
2073
self.overrideEnv('LOGNAME', 'jrandom')
2075
2074
self.assertEqual(u'jrandom', osutils.getuser_unicode())
2077
2076
def test_unicode_user(self):
2078
2077
ue = osutils.get_user_encoding()
2079
osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
2078
uni_val, env_val = tests.probe_unicode_in_user_encoding()
2080
raise tests.TestSkipped(
2081
'Cannot find a unicode character that works in encoding %s'
2082
% (osutils.get_user_encoding(),))
2083
uni_username = u'jrandom' + uni_val
2084
encoded_username = uni_username.encode(ue)
2085
self.overrideEnv('LOGNAME', encoded_username)
2086
self.assertEqual(uni_username, osutils.getuser_unicode())
2087
self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2080
2088
self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2090
class TestBackupNames(tests.TestCase):
2093
super(TestBackupNames, self).setUp()
2096
def backup_exists(self, name):
2097
return name in self.backups
2099
def available_backup_name(self, name):
2100
backup_name = osutils.available_backup_name(name, self.backup_exists)
2101
self.backups.append(backup_name)
2104
def assertBackupName(self, expected, name):
2105
self.assertEqual(expected, self.available_backup_name(name))
2107
def test_empty(self):
2108
self.assertBackupName('file.~1~', 'file')
2110
def test_existing(self):
2111
self.available_backup_name('file')
2112
self.available_backup_name('file')
2113
self.assertBackupName('file.~3~', 'file')
2114
# Empty slots are found, this is not a strict requirement and may be
2115
# revisited if we test against all implementations.
2116
self.backups.remove('file.~2~')
2117
self.assertBackupName('file.~2~', 'file')