98
def load_tests(basic_tests, module, loader):
99
suite = loader.suiteClass()
100
dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
101
basic_tests, tests.condition_isinstance(TestDirReader))
102
tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
103
suite.addTest(remaining_tests)
100
load_tests = load_tests_apply_scenarios
107
103
class TestContainsWhitespace(tests.TestCase):
1083
1080
# Ensure the message contains the file name
1084
1081
self.assertContainsRe(str(e), "\./test-unreadable")
1084
def test_walkdirs_encoding_error(self):
1085
# <https://bugs.launchpad.net/bzr/+bug/488519>
1086
# walkdirs didn't raise a useful message when the filenames
1087
# are not using the filesystem's encoding
1089
# require a bytestring based filesystem
1090
self.requireFeature(tests.ByteStringNamedFilesystem)
1101
self.build_tree(tree)
1103
# rename the 1file to a latin-1 filename
1104
os.rename("./1file", "\xe8file")
1105
if "\xe8file" not in os.listdir("."):
1106
self.skip("Lack filesystem that preserves arbitrary bytes")
1108
self._save_platform_info()
1109
win32utils.winver = None # Avoid the win32 detection code
1110
osutils._fs_enc = 'UTF-8'
1112
# this should raise on error
1114
for dirdetail, dirblock in osutils.walkdirs('.'):
1117
self.assertRaises(errors.BadFilenameEncoding, attempt)
1086
1119
def test__walkdirs_utf8(self):
1672
1705
class TestReCompile(tests.TestCase):
1707
def _deprecated_re_compile_checked(self, *args, **kwargs):
1708
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1709
osutils.re_compile_checked, *args, **kwargs)
1674
1711
def test_re_compile_checked(self):
1675
r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
1712
r = self._deprecated_re_compile_checked(r'A*', re.IGNORECASE)
1676
1713
self.assertTrue(r.match('aaaa'))
1677
1714
self.assertTrue(r.match('aAaA'))
1679
1716
def test_re_compile_checked_error(self):
1680
1717
# like https://bugs.launchpad.net/bzr/+bug/251352
1719
# Due to possible test isolation error, re.compile is not lazy at
1720
# this point. We re-install lazy compile.
1721
lazy_regex.install_lazy_compile()
1681
1722
err = self.assertRaises(
1682
1723
errors.BzrCommandError,
1683
osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
1724
self._deprecated_re_compile_checked, '*', re.IGNORECASE, 'test case')
1684
1725
self.assertEqual(
1685
"Invalid regular expression in test case: '*': "
1686
"nothing to repeat",
1726
'Invalid regular expression in test case: '
1727
'"*" nothing to repeat',
1690
1731
class TestDirReader(tests.TestCaseInTempDir):
1733
scenarios = dir_reader_scenarios()
1692
1735
# Set by load_tests
1693
1736
_dir_reader_class = None
1694
1737
_native_to_unicode = None
1856
1899
self.assertIsInstance(concurrency, int)
1858
1901
def test_local_concurrency_environment_variable(self):
1859
os.environ['BZR_CONCURRENCY'] = '2'
1902
self.overrideEnv('BZR_CONCURRENCY', '2')
1860
1903
self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1861
os.environ['BZR_CONCURRENCY'] = '3'
1904
self.overrideEnv('BZR_CONCURRENCY', '3')
1862
1905
self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1863
os.environ['BZR_CONCURRENCY'] = 'foo'
1906
self.overrideEnv('BZR_CONCURRENCY', 'foo')
1864
1907
self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1866
1909
def test_option_concurrency(self):
1867
os.environ['BZR_CONCURRENCY'] = '1'
1910
self.overrideEnv('BZR_CONCURRENCY', '1')
1868
1911
self.run_bzr('rocks --concurrency 42')
1869
# Command line overrides envrionment variable
1912
# Command line overrides environment variable
1870
1913
self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1871
1914
self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1942
1985
def test_defaults_to_BZR_COLUMNS(self):
1943
1986
# BZR_COLUMNS is set by the test framework
1944
1987
self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1945
os.environ['BZR_COLUMNS'] = '12'
1988
self.overrideEnv('BZR_COLUMNS', '12')
1946
1989
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())
1948
1995
def test_falls_back_to_COLUMNS(self):
1949
del os.environ['BZR_COLUMNS']
1996
self.overrideEnv('BZR_COLUMNS', None)
1950
1997
self.assertNotEqual('42', os.environ['COLUMNS'])
1951
1998
self.set_fake_tty()
1952
os.environ['COLUMNS'] = '42'
1999
self.overrideEnv('COLUMNS', '42')
1953
2000
self.assertEqual(42, osutils.terminal_width())
1955
2002
def test_tty_default_without_columns(self):
1956
del os.environ['BZR_COLUMNS']
1957
del os.environ['COLUMNS']
2003
self.overrideEnv('BZR_COLUMNS', None)
2004
self.overrideEnv('COLUMNS', None)
1959
2006
def terminal_size(w, h):
1967
2014
self.assertEqual(42, osutils.terminal_width())
1969
2016
def test_non_tty_default_without_columns(self):
1970
del os.environ['BZR_COLUMNS']
1971
del os.environ['COLUMNS']
2017
self.overrideEnv('BZR_COLUMNS', None)
2018
self.overrideEnv('COLUMNS', None)
1972
2019
self.replace_stdout(None)
1973
2020
self.assertEqual(None, osutils.terminal_width())
1985
2032
self.overrideAttr(termios, 'TIOCGWINSZ')
1986
2033
del termios.TIOCGWINSZ
1987
del os.environ['BZR_COLUMNS']
1988
del os.environ['COLUMNS']
2034
self.overrideEnv('BZR_COLUMNS', None)
2035
self.overrideEnv('COLUMNS', None)
1989
2036
# Whatever the result is, if we don't raise an exception, it's ok.
1990
2037
osutils.terminal_width()
2027
2074
class TestGetuserUnicode(tests.TestCase):
2029
2076
def test_ascii_user(self):
2030
osutils.set_or_unset_env('LOGNAME', 'jrandom')
2077
self.overrideEnv('LOGNAME', 'jrandom')
2031
2078
self.assertEqual(u'jrandom', osutils.getuser_unicode())
2033
2080
def test_unicode_user(self):
2034
2081
ue = osutils.get_user_encoding()
2035
osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
2082
uni_val, env_val = tests.probe_unicode_in_user_encoding()
2084
raise tests.TestSkipped(
2085
'Cannot find a unicode character that works in encoding %s'
2086
% (osutils.get_user_encoding(),))
2087
uni_username = u'jrandom' + uni_val
2088
encoded_username = uni_username.encode(ue)
2089
self.overrideEnv('LOGNAME', encoded_username)
2090
self.assertEqual(uni_username, osutils.getuser_unicode())
2091
self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2036
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)