533
533
def report_test_start(self, test):
535
535
name = self._shortened_test_description(test)
536
# width needs space for 6 char status, plus 1 for slash, plus an
537
# 11-char time string, plus a trailing blank
538
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
539
self.stream.write(self._ellipsize_to_right(name,
540
osutils.terminal_width()-18))
536
width = osutils.terminal_width()
537
if width is not None:
538
# width needs space for 6 char status, plus 1 for slash, plus an
539
# 11-char time string, plus a trailing blank
540
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on
542
self.stream.write(self._ellipsize_to_right(name, width-18))
544
self.stream.write(name)
541
545
self.stream.flush()
543
547
def _error_summary(self, err):
1115
1119
:raises AssertionError: If the expected and actual stat values differ
1116
1120
other than by atime.
1118
self.assertEqual(expected.st_size, actual.st_size)
1119
self.assertEqual(expected.st_mtime, actual.st_mtime)
1120
self.assertEqual(expected.st_ctime, actual.st_ctime)
1121
self.assertEqual(expected.st_dev, actual.st_dev)
1122
self.assertEqual(expected.st_ino, actual.st_ino)
1123
self.assertEqual(expected.st_mode, actual.st_mode)
1122
self.assertEqual(expected.st_size, actual.st_size,
1123
'st_size did not match')
1124
self.assertEqual(expected.st_mtime, actual.st_mtime,
1125
'st_mtime did not match')
1126
self.assertEqual(expected.st_ctime, actual.st_ctime,
1127
'st_ctime did not match')
1128
if sys.platform != 'win32':
1129
# On Win32 both 'dev' and 'ino' cannot be trusted. In python2.4 it
1130
# is 'dev' that varies, in python 2.5 (6?) it is st_ino that is
1131
# odd. Regardless we shouldn't actually try to assert anything
1132
# about their values
1133
self.assertEqual(expected.st_dev, actual.st_dev,
1134
'st_dev did not match')
1135
self.assertEqual(expected.st_ino, actual.st_ino,
1136
'st_ino did not match')
1137
self.assertEqual(expected.st_mode, actual.st_mode,
1138
'st_mode did not match')
1125
1140
def assertLength(self, length, obj_with_len):
1126
1141
"""Assert that obj_with_len is of length length."""
1513
1528
'BZR_PROGRESS_BAR': None,
1514
1529
'BZR_LOG': None,
1515
1530
'BZR_PLUGIN_PATH': None,
1531
'BZR_CONCURRENCY': None,
1516
1532
# Make sure that any text ui tests are consistent regardless of
1517
1533
# the environment the test case is run in; you may want tests that
1518
1534
# test other combinations. 'dumb' is a reasonable guess for tests
1825
1842
os.chdir(working_dir)
1828
result = self.apply_redirected(ui.ui_factory.stdin,
1830
bzrlib.commands.run_bzr_catch_user_errors,
1846
result = self.apply_redirected(ui.ui_factory.stdin,
1848
bzrlib.commands.run_bzr_catch_user_errors,
1850
except KeyboardInterrupt:
1851
# Reraise KeyboardInterrupt with contents of redirected stdout
1852
# and stderr as arguments, for tests which are interested in
1853
# stdout and stderr and are expecting the exception.
1854
out = stdout.getvalue()
1855
err = stderr.getvalue()
1857
self.log('output:\n%r', out)
1859
self.log('errors:\n%r', err)
1860
raise KeyboardInterrupt(out, err)
1833
1862
logger.removeHandler(handler)
1834
1863
ui.ui_factory = old_ui_factory
2382
2411
# recreate a new one or all the followng tests will fail.
2383
2412
# If you need to inspect its content uncomment the following line
2384
2413
# import pdb; pdb.set_trace()
2385
_rmtree_temp_dir(root + '/.bzr')
2414
_rmtree_temp_dir(root + '/.bzr', test_id=self.id())
2386
2415
self._create_safety_net()
2387
2416
raise AssertionError('%s/.bzr should not be modified' % root)
2464
2493
return branchbuilder.BranchBuilder(branch=branch)
2466
2495
def overrideEnvironmentForTesting(self):
2467
os.environ['HOME'] = self.test_home_dir
2468
os.environ['BZR_HOME'] = self.test_home_dir
2496
test_home_dir = self.test_home_dir
2497
if isinstance(test_home_dir, unicode):
2498
test_home_dir = test_home_dir.encode(sys.getfilesystemencoding())
2499
os.environ['HOME'] = test_home_dir
2500
os.environ['BZR_HOME'] = test_home_dir
2470
2502
def setUp(self):
2471
2503
super(TestCaseWithMemoryTransport, self).setUp()
2578
2610
def deleteTestDir(self):
2579
2611
os.chdir(TestCaseWithMemoryTransport.TEST_ROOT)
2580
_rmtree_temp_dir(self.test_base_dir)
2612
_rmtree_temp_dir(self.test_base_dir, test_id=self.id())
2582
2614
def build_tree(self, shape, line_endings='binary', transport=None):
2583
2615
"""Build a test tree according to a pattern.
3321
3353
if not os.path.isfile(bzr_path):
3322
3354
# We are probably installed. Assume sys.argv is the right file
3323
3355
bzr_path = sys.argv[0]
3356
bzr_path = [bzr_path]
3357
if sys.platform == "win32":
3358
# if we're on windows, we can't execute the bzr script directly
3359
bzr_path = [sys.executable] + bzr_path
3324
3360
fd, test_list_file_name = tempfile.mkstemp()
3325
3361
test_list_file = os.fdopen(fd, 'wb', 1)
3326
3362
for test in process_tests:
3327
3363
test_list_file.write(test.id() + '\n')
3328
3364
test_list_file.close()
3330
argv = [bzr_path, 'selftest', '--load-list', test_list_file_name,
3366
argv = bzr_path + ['selftest', '--load-list', test_list_file_name,
3332
3368
if '--no-plugins' in sys.argv:
3333
3369
argv.append('--no-plugins')
4101
4137
return new_test
4104
def _rmtree_temp_dir(dirname):
4140
def _rmtree_temp_dir(dirname, test_id=None):
4105
4141
# If LANG=C we probably have created some bogus paths
4106
4142
# which rmtree(unicode) will fail to delete
4107
4143
# so make sure we are using rmtree(str) to delete everything
4119
4155
# We don't want to fail here because some useful display will be lost
4120
4156
# otherwise. Polluting the tmp dir is bad, but not giving all the
4121
4157
# possible info to the test runner is even worse.
4159
ui.ui_factory.clear_term()
4160
sys.stderr.write('\nWhile running: %s\n' % (test_id,))
4122
4161
sys.stderr.write('Unable to remove testing dir %s\n%s'
4123
4162
% (os.path.basename(dirname), e))
4208
4247
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4250
class ModuleAvailableFeature(Feature):
4251
"""This is a feature than describes a module we want to be available.
4253
Declare the name of the module in __init__(), and then after probing, the
4254
module will be available as 'self.module'.
4256
:ivar module: The module if it is available, else None.
4259
def __init__(self, module_name):
4260
super(ModuleAvailableFeature, self).__init__()
4261
self.module_name = module_name
4265
self._module = __import__(self.module_name, {}, {}, [''])
4272
if self.available(): # Make sure the probe has been done
4276
def feature_name(self):
4277
return self.module_name
4211
4281
def probe_unicode_in_user_encoding():
4212
4282
"""Try to encode several unicode strings to use in unicode-aware tests.
4213
4283
Return first successfull match.