100
load_tests = load_tests_apply_scenarios
99
def load_tests(basic_tests, module, loader):
100
suite = loader.suiteClass()
101
dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
102
basic_tests, tests.condition_isinstance(TestDirReader))
103
tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
104
suite.addTest(remaining_tests)
103
108
class TestContainsWhitespace(tests.TestCase):
1103
1108
# rename the 1file to a latin-1 filename
1104
1109
os.rename("./1file", "\xe8file")
1105
if "\xe8file" not in os.listdir("."):
1106
self.skip("Lack filesystem that preserves arbitrary bytes")
1108
1111
self._save_platform_info()
1109
1112
win32utils.winver = None # Avoid the win32 detection code
1899
1900
self.assertIsInstance(concurrency, int)
1901
1902
def test_local_concurrency_environment_variable(self):
1902
self.overrideEnv('BZR_CONCURRENCY', '2')
1903
os.environ['BZR_CONCURRENCY'] = '2'
1903
1904
self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1904
self.overrideEnv('BZR_CONCURRENCY', '3')
1905
os.environ['BZR_CONCURRENCY'] = '3'
1905
1906
self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1906
self.overrideEnv('BZR_CONCURRENCY', 'foo')
1907
os.environ['BZR_CONCURRENCY'] = 'foo'
1907
1908
self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1909
1910
def test_option_concurrency(self):
1910
self.overrideEnv('BZR_CONCURRENCY', '1')
1911
os.environ['BZR_CONCURRENCY'] = '1'
1911
1912
self.run_bzr('rocks --concurrency 42')
1912
# Command line overrides environment variable
1913
# Command line overrides envrionment variable
1913
1914
self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1914
1915
self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1985
1986
def test_defaults_to_BZR_COLUMNS(self):
1986
1987
# BZR_COLUMNS is set by the test framework
1987
1988
self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1988
self.overrideEnv('BZR_COLUMNS', '12')
1989
os.environ['BZR_COLUMNS'] = '12'
1989
1990
self.assertEqual(12, osutils.terminal_width())
1991
def test_BZR_COLUMNS_0_no_limit(self):
1992
self.overrideEnv('BZR_COLUMNS', '0')
1993
self.assertEqual(None, osutils.terminal_width())
1995
1992
def test_falls_back_to_COLUMNS(self):
1996
self.overrideEnv('BZR_COLUMNS', None)
1993
del os.environ['BZR_COLUMNS']
1997
1994
self.assertNotEqual('42', os.environ['COLUMNS'])
1998
1995
self.set_fake_tty()
1999
self.overrideEnv('COLUMNS', '42')
1996
os.environ['COLUMNS'] = '42'
2000
1997
self.assertEqual(42, osutils.terminal_width())
2002
1999
def test_tty_default_without_columns(self):
2003
self.overrideEnv('BZR_COLUMNS', None)
2004
self.overrideEnv('COLUMNS', None)
2000
del os.environ['BZR_COLUMNS']
2001
del os.environ['COLUMNS']
2006
2003
def terminal_size(w, h):
2014
2011
self.assertEqual(42, osutils.terminal_width())
2016
2013
def test_non_tty_default_without_columns(self):
2017
self.overrideEnv('BZR_COLUMNS', None)
2018
self.overrideEnv('COLUMNS', None)
2014
del os.environ['BZR_COLUMNS']
2015
del os.environ['COLUMNS']
2019
2016
self.replace_stdout(None)
2020
2017
self.assertEqual(None, osutils.terminal_width())
2032
2029
self.overrideAttr(termios, 'TIOCGWINSZ')
2033
2030
del termios.TIOCGWINSZ
2034
self.overrideEnv('BZR_COLUMNS', None)
2035
self.overrideEnv('COLUMNS', None)
2031
del os.environ['BZR_COLUMNS']
2032
del os.environ['COLUMNS']
2036
2033
# Whatever the result is, if we don't raise an exception, it's ok.
2037
2034
osutils.terminal_width()
2074
2071
class TestGetuserUnicode(tests.TestCase):
2076
2073
def test_ascii_user(self):
2077
self.overrideEnv('LOGNAME', 'jrandom')
2074
osutils.set_or_unset_env('LOGNAME', 'jrandom')
2078
2075
self.assertEqual(u'jrandom', osutils.getuser_unicode())
2080
2077
def test_unicode_user(self):
2086
2083
% (osutils.get_user_encoding(),))
2087
2084
uni_username = u'jrandom' + uni_val
2088
2085
encoded_username = uni_username.encode(ue)
2089
self.overrideEnv('LOGNAME', encoded_username)
2086
osutils.set_or_unset_env('LOGNAME', encoded_username)
2090
2087
self.assertEqual(uni_username, osutils.getuser_unicode())
2091
self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2092
self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2094
class TestBackupNames(tests.TestCase):
2097
super(TestBackupNames, self).setUp()
2100
def backup_exists(self, name):
2101
return name in self.backups
2103
def available_backup_name(self, name):
2104
backup_name = osutils.available_backup_name(name, self.backup_exists)
2105
self.backups.append(backup_name)
2108
def assertBackupName(self, expected, name):
2109
self.assertEqual(expected, self.available_backup_name(name))
2111
def test_empty(self):
2112
self.assertBackupName('file.~1~', 'file')
2114
def test_existing(self):
2115
self.available_backup_name('file')
2116
self.available_backup_name('file')
2117
self.assertBackupName('file.~3~', 'file')
2118
# Empty slots are found, this is not a strict requirement and may be
2119
# revisited if we test against all implementations.
2120
self.backups.remove('file.~2~')
2121
self.assertBackupName('file.~2~', 'file')
2124
class TestFindExecutableInPath(tests.TestCase):
2126
def test_windows(self):
2127
if sys.platform != 'win32':
2128
raise tests.TestSkipped('test requires win32')
2129
self.assertTrue(osutils.find_executable_on_path('explorer') is not None)
2131
osutils.find_executable_on_path('explorer.exe') is not None)
2133
osutils.find_executable_on_path('EXPLORER.EXE') is not None)
2135
osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2136
self.assertTrue(osutils.find_executable_on_path('file.txt') is None)
2138
def test_other(self):
2139
if sys.platform == 'win32':
2140
raise tests.TestSkipped('test requires non-win32')
2141
self.assertTrue(osutils.find_executable_on_path('sh') is not None)
2143
osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)